diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2019-08-15 15:07:24 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2019-08-15 15:07:24 +0200 |
commit | 4a6e117c9425b4b7ec0875b654c20ea92d3d7ce0 (patch) | |
tree | 078f52f42b70649c73e4d8b1a9ed2a54708be103 /in/__init__.py | |
download | TermIO-python-package-4a6e117c9425b4b7ec0875b654c20ea92d3d7ce0.tar.gz TermIO-python-package-4a6e117c9425b4b7ec0875b654c20ea92d3d7ce0.zip |
:sparkles: Initial commit
Diffstat (limited to 'in/__init__.py')
-rw-r--r-- | in/__init__.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/in/__init__.py b/in/__init__.py new file mode 100644 index 0000000..b886141 --- /dev/null +++ b/in/__init__.py @@ -0,0 +1,35 @@ +class _Getch: + """Gets a single character from standard input. Does not echo to the +screen.""" + def __init__(self): + try: + self.impl = _GetchWindows() + except ImportError: + self.impl = _GetchUnix() + + def __call__(self): return self.impl() + + +class _GetchUnix: + def __init__(self): + import tty, sys + + def __call__(self): + import sys, tty, termios + fd = sys.stdin.fileno() + old_settings = termios.tcgetattr(fd) + try: + tty.setraw(sys.stdin.fileno()) + ch = sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + return ch + + +class _GetchWindows: + def __init__(self): + import msvcrt + + def __call__(self): + import msvcrt + return msvcrt.getch() |