mirror of
https://github.com/google/mozc-devices.git
synced 2025-11-09 01:03:26 +03:00
Read ANSI escape codes by KeyboardRecorderFromConsole
This commit is contained in:
@@ -54,4 +54,7 @@ class Bluetooth():
|
||||
if cmd not in self.UART_CODES:
|
||||
print('Unknown Command: {}'.format(cmd))
|
||||
return
|
||||
if self._dummy:
|
||||
print('bluetooth: command({})'.format(cmd))
|
||||
return
|
||||
self.send(struct.pack('b', self.UART_CODES[cmd]))
|
||||
|
||||
@@ -73,6 +73,24 @@ class KeyboardRecorderFromConsole(KeyboardRecorder):
|
||||
KeyboardRecorder.__init__(self, verbose)
|
||||
self.log('Input from console')
|
||||
|
||||
def _read_ansi_escape(self):
|
||||
seq = sys.stdin.read(1)
|
||||
if seq == '[':
|
||||
code = sys.stdin.read(1)
|
||||
self.log('CSI code: {}'.format(code))
|
||||
if code == 'A':
|
||||
return (None, 'KEY_UP')
|
||||
if code == 'B':
|
||||
return (None, 'KEY_DOWN')
|
||||
if code == 'C':
|
||||
return (None, 'KEY_RIGHT')
|
||||
if code == 'D':
|
||||
return (None, 'KEY_LEFT')
|
||||
self.log('it was unknown code...')
|
||||
else:
|
||||
self.log('unknown seq: {}'.format(seq))
|
||||
return (None, None)
|
||||
|
||||
def record(self):
|
||||
"""
|
||||
Returns a tuple of |data| and |command|.
|
||||
@@ -93,8 +111,12 @@ class KeyboardRecorderFromConsole(KeyboardRecorder):
|
||||
key = None
|
||||
finally:
|
||||
now = datetime.datetime.now()
|
||||
if key == '\n':
|
||||
return (None, None)
|
||||
if key == '\x1b':
|
||||
return self._read_ansi_escape();
|
||||
elif key == '\n':
|
||||
return (None, 'KEY_ENTER')
|
||||
elif key == '\b' or key == '\x7f':
|
||||
return (None, 'KEY_BACKSPACE')
|
||||
elif key:
|
||||
if not recording:
|
||||
recording = True
|
||||
|
||||
Reference in New Issue
Block a user