Closed
Description
Bug report
Bug description:
A read1 of 'stdin' in cbreak mode returns 0x0D (instead of 0x0A) when <enter> is entered.
That is for Python version 3.12.1, version 3.11.6 returns 0x0A.
The following code demonstrates this. When run enter <enter>.
"""
cbreak <enter> test
"""
import sys
import tty
import select
import termios
from time import sleep
# save stdin attributes
prevStdinAttributes = termios.tcgetattr(sys.stdin)
# set cbreak mode:
# "Enter cbreak mode. In cbreak mode (sometimes called “rare” mode) normal tty line buffering
# is turned off and characters are available to be read one by one. However, unlike raw mode,
# special characters (interrupt, quit, suspend, and flow control) retain their effects on the
# tty driver and calling program. Calling first raw() then cbreak() leaves the terminal in cbreak mode."
tty.setcbreak(sys.stdin, when = termios.TCSANOW)
c = b''
# wait for a byte
while True:
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
c = sys.stdin.buffer.read1(1)
break
sleep(.1)
# restore stdin attributes
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, prevStdinAttributes)
# print result byte in hex
print(f"bytes: '\\x{c.hex().upper()}'")
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux, macOS