windows: Make WindowsConsole actually work
There were some definitions missing, and sys.stdin.read doesn't quite work right
on Windows consoles.
Change-Id: I857483ac20a7dafbcd221cce18119b95722931bd
diff --git a/mdt/console.py b/mdt/console.py
index 8bf7452..362f025 100644
--- a/mdt/console.py
+++ b/mdt/console.py
@@ -28,6 +28,7 @@
TYPE_TERMINAL_OUTPUT = 1
TYPE_REMOTE_CLOSED = 2
TYPE_SOCKET_TIMEOUT = 3
+TYPE_EXIT_CODE = 4
KEEP_ALIVE_SECONDS = 10
@@ -40,6 +41,10 @@
pass
+class UnknownEventTypeError(Exception):
+ pass
+
+
def GetTtyWindowSize(fd):
import fcntl
import struct
@@ -182,9 +187,11 @@
self.queue = queue
def run(self):
+ import msvcrt
+
while True:
- ch = sys.stdin.read(1)
- self.queue.put((KEYBOARD_INPUT_DATA, ch))
+ ch = msvcrt.getch()
+ self.queue.put((TYPE_KEYBOARD_INPUT, ch))
class TerminalOutputThread(threading.Thread):
@@ -228,7 +235,7 @@
escape_level = 0
while True:
- dataType, data = self.queue.get()
+ dataType, data = self.dataQueue.get()
if dataType == TYPE_KEYBOARD_INPUT:
if escape_level == 0 and data == b'\r':
@@ -241,14 +248,16 @@
else:
escape_level = 0
- channel.send(data)
- if dataType == TYPE_TERMINAL_OUTPUT:
+ self.channel.send(data.decode("utf-8", errors="ignore"))
+ elif dataType == TYPE_TERMINAL_OUTPUT:
sys.stdout.write(data)
sys.stdout.flush()
- if dataType == TYPE_REMOTE_CLOSED:
+ elif dataType == TYPE_REMOTE_CLOSED:
raise ConnectionClosedError(exit_code=data)
- if dataType == TYPE_SOCKET_TIMEOUT:
+ elif dataType == TYPE_SOCKET_TIMEOUT:
raise SocketTimeoutError()
+ else:
+ raise UnknownEventTypeError()
class Console: