miniterm: add a cancel() function to console wrapper object and a win32 implementation
- see also #107
diff --git a/serial/tools/miniterm.py b/serial/tools/miniterm.py
index ebb7f6e..2110688 100644
--- a/serial/tools/miniterm.py
+++ b/serial/tools/miniterm.py
@@ -68,6 +68,9 @@
self.output.write(text)
self.output.flush()
+ def cancel(self):
+ """Cancel getkey operation"""
+
# - - - - - - - - - - - - - - - - - - - - - - - -
# context manager:
# switch terminal temporary to normal mode (e.g. to get user input)
@@ -123,6 +126,10 @@
else:
return z
+ def cancel(self):
+ hwnd = ctypes.windll.kernel32.GetConsoleWindow()
+ ctypes.windll.user32.PostMessageA(hwnd, 0x100, 0x0d, 0)
+
elif os.name == 'posix':
import atexit
import termios
@@ -434,9 +441,8 @@
self.console.write(text)
except serial.SerialException:
self.alive = False
- # XXX would be nice if the writer could be interrupted at this
- # point... to exit completely
- raise
+ self.console.cancel()
+ raise # XXX handle instead of re-raise?
def writer(self):
"""\
@@ -451,6 +457,8 @@
c = self.console.getkey()
except KeyboardInterrupt:
c = '\x03'
+ if not self.alive:
+ break
if menu_active:
self.handle_menu_key(c)
menu_active = False