diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2019-08-15 21:19:38 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2019-08-15 21:19:38 +0200 |
commit | e1cde9174a5ba42de8daccd7b74ea10093029220 (patch) | |
tree | 011046e4a766c7a5a13471788c7a5e6ebb03fbee /TermIO/in | |
parent | d2379f3b162b598ec6fb0a0a2b995aa7dbf1f10c (diff) | |
download | TermIO-python-package-e1cde9174a5ba42de8daccd7b74ea10093029220.tar.gz TermIO-python-package-e1cde9174a5ba42de8daccd7b74ea10093029220.zip |
:truck: Move package into folder
Diffstat (limited to 'TermIO/in')
-rw-r--r-- | TermIO/in/__init__.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/TermIO/in/__init__.py b/TermIO/in/__init__.py new file mode 100644 index 0000000..b886141 --- /dev/null +++ b/TermIO/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() |