From 730c2197db095486aee42860b359d3f4cd971a61 Mon Sep 17 00:00:00 2001 From: fleytman Date: Thu, 28 Jul 2022 01:43:51 +0300 Subject: [PATCH 1/2] fix macos enter add macos pycharm fix https://github.com/magmax/python-readchar/pull/70 --- readchar/__init__.py | 6 +----- readchar/_macos_key.py | 4 ++++ readchar/_posix_read.py | 5 ++++- readchar/key.py | 9 ++++----- 4 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 readchar/_macos_key.py diff --git a/readchar/__init__.py b/readchar/__init__.py index 64817a1..a5adad3 100644 --- a/readchar/__init__.py +++ b/readchar/__init__.py @@ -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")): from ._posix_read import readchar, readkey elif platform in ("win32", "cygwin"): from ._win_read import readchar, readkey diff --git a/readchar/_macos_key.py b/readchar/_macos_key.py new file mode 100644 index 0000000..800eb44 --- /dev/null +++ b/readchar/_macos_key.py @@ -0,0 +1,4 @@ +# common + +CR = "\x0d" +ENTER = CR \ No newline at end of file diff --git a/readchar/_posix_read.py b/readchar/_posix_read.py index c34a797..560f679 100644 --- a/readchar/_posix_read.py +++ b/readchar/_posix_read.py @@ -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) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch diff --git a/readchar/key.py b/readchar/key.py index a73163a..4fdef6c 100644 --- a/readchar/key.py +++ b/readchar/key.py @@ -2,12 +2,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 * + from ._macos_key import * elif platform in ("win32", "cygwin"): from ._win_key import * else: From 0655497a98e9056871005ac55c56a23f3677aa18 Mon Sep 17 00:00:00 2001 From: fleytman Date: Sun, 31 Jul 2022 18:23:35 +0300 Subject: [PATCH 2/2] add newline to end file --- readchar/_macos_key.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readchar/_macos_key.py b/readchar/_macos_key.py index 800eb44..5e27eb8 100644 --- a/readchar/_macos_key.py +++ b/readchar/_macos_key.py @@ -1,4 +1,4 @@ # common CR = "\x0d" -ENTER = CR \ No newline at end of file +ENTER = CR