diff options
author | Chris Liechti <cliechti@gmx.net> | 2016-12-07 01:27:41 +0100 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2016-12-07 01:27:41 +0100 |
commit | cab3dabc81ecbf010d81ff38433db99c1f6d667c (patch) | |
tree | 33dd30e5281064de229c624dc33b84b448a69246 | |
parent | 0c7077a519092b2f3422b5ea0f3996ee87a5a6f0 (diff) | |
download | pyserial-git-cab3dabc81ecbf010d81ff38433db99c1f6d667c.tar.gz |
miniterm: change cancel impl. for console, fixes #174
the way select was used, was incompatible with the text io
wrapper used by python3 for sys.stdin
-rw-r--r-- | serial/tools/miniterm.py | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/serial/tools/miniterm.py b/serial/tools/miniterm.py index 7c68e9d..14182f0 100644 --- a/serial/tools/miniterm.py +++ b/serial/tools/miniterm.py @@ -135,15 +135,12 @@ if os.name == 'nt': # noqa elif os.name == 'posix': import atexit import termios - import select + import fcntl class Console(ConsoleBase): def __init__(self): super(Console, self).__init__() self.fd = sys.stdin.fileno() - # an additional pipe is used in getkey, so that the cancel method - # can abort the waiting getkey method - self.pipe_r, self.pipe_w = os.pipe() self.old = termios.tcgetattr(self.fd) atexit.register(self.cleanup) if sys.version_info < (3, 0): @@ -159,17 +156,13 @@ elif os.name == 'posix': termios.tcsetattr(self.fd, termios.TCSANOW, new) def getkey(self): - ready, _, _ = select.select([self.enc_stdin, self.pipe_r], [], [], None) - if self.pipe_r in ready: - os.read(self.pipe_r, 1) - return c = self.enc_stdin.read(1) if c == unichr(0x7f): c = unichr(8) # map the BS key (which yields DEL) to backspace return c def cancel(self): - os.write(self.pipe_w, b"x") + fcntl.ioctl(self.fd, termios.TIOCSTI, b'\0') def cleanup(self): termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old) |