Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ venv/
coverage.xml
.eggs
*.egg
.idea/
6 changes: 4 additions & 2 deletions readchar/readchar_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import tty


def readchar():
def readchar(enter_code="\r"):
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno())
ch = sys.stdin.read(1)
if ch in ('\r', '\n'):
ch = enter_code
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
2 changes: 1 addition & 1 deletion readchar/readchar_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def readchar(blocking=False):
msvcrt.getch()
ch = msvcrt.getch()

return ch if sys.version_info.major > 2 else ch.decode(encoding=win_encoding)
return ch.decode() if sys.version_info.major > 2 else ch.decode(encoding=win_encoding)