Skip to content

Fix ENTER on macos #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
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
6 changes: 1 addition & 5 deletions readchar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
from sys import platform


if (
platform.startswith("linux")
or platform == "darwin"
or platform.startswith("freebsd")
):
if platform.startswith(("linux", "darwin", "freebsd")):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats a cool idea. very nice.

from ._posix_read import readchar, readkey
from . import _posix_key as key
elif platform in ("win32", "cygwin"):
Expand Down
4 changes: 4 additions & 0 deletions readchar/_macos_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# common

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please import exsiting definitions from other files here

Suggested change
from ._posix_key import *

CR = "\x0d"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is alread defined. no need to redefine it

ENTER = CR
5 changes: 4 additions & 1 deletion readchar/_posix_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def readchar() -> str:
term[3] &= ~(termios.ICANON | termios.ECHO | termios.IGNBRK | termios.BRKINT)
termios.tcsetattr(fd, termios.TCSAFLUSH, term)

ch = sys.stdin.read(1)
if sys.platform == "darwin":
ch = sys.stdin.readline(1)
else:
ch = sys.stdin.read(1)
Comment on lines +22 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is defnetly to complex for me to just sign of on. Please remove #70 from this PR. I will decide if it makes sense to include it once I finde the time to get around to it.

finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
Expand Down
9 changes: 4 additions & 5 deletions readchar/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

from . import platform

if (
platform.startswith("linux")
or platform == "darwin"
or platform.startswith("freebsd")
):
if platform.startswith(("linux", "freebsd")):
from ._posix_key import *
elif platform.startswith("darwin"):
from ._posix_key import *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like I said above, this should be part of the _mac_key.py file

Suggested change
from ._posix_key import *

from ._macos_key import *
elif platform in ("win32", "cygwin"):
from ._win_key import *
else:
Expand Down