diff options
| author | Jan Tuomi <jan-sebastian.tuomi@aalto.fi> | 2016-03-17 20:55:11 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan-sebastian.tuomi@aalto.fi> | 2016-03-17 23:02:34 +0200 |
| commit | b6dc3ba88e5ef0a7e4509c88665372cb04a36f06 (patch) | |
| tree | 11649dec1e48377571a98edea0a9fdf0b2fcb377 /src/python-sshmgr/sshmgr/utils | |
| parent | ddbf8a86cf4ef071f289aceda1035818948d2292 (diff) | |
Arch packaging
Diffstat (limited to 'src/python-sshmgr/sshmgr/utils')
| -rw-r--r-- | src/python-sshmgr/sshmgr/utils/__init__.py | 0 | ||||
| -rw-r--r-- | src/python-sshmgr/sshmgr/utils/getch.py | 40 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/python-sshmgr/sshmgr/utils/__init__.py b/src/python-sshmgr/sshmgr/utils/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/python-sshmgr/sshmgr/utils/__init__.py diff --git a/src/python-sshmgr/sshmgr/utils/getch.py b/src/python-sshmgr/sshmgr/utils/getch.py new file mode 100644 index 0000000..3ee4b25 --- /dev/null +++ b/src/python-sshmgr/sshmgr/utils/getch.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +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() + + +getch = _Getch() |
