diff --git a/ptrlib/binary/encoding/ansi.py b/ptrlib/binary/encoding/ansi.py index da8b8fa..28cfaef 100644 --- a/ptrlib/binary/encoding/ansi.py +++ b/ptrlib/binary/encoding/ansi.py @@ -14,12 +14,12 @@ def _escape_codes(): codes['CSI_CURSOR_MOVE'] = re.compile(b'^\x1b\[([1-9]\d*);([1-9]\d*)[Hf]') codes['CSI_CURSOR_ROW'] = re.compile(b'^\x1b\[([1-9]\d*)d') codes['CSI_CURSOR_COLUMN'] = re.compile(b'^\x1b\[([1-9]\d*)[`G]') - codes['CSI_CURSOR_UP'] = re.compile(b'^\x1b\[(\d+)A') - codes['CSI_CURSOR_DOWN'] = re.compile(b'^\x1b\[(\d+)B') - codes['CSI_CURSOR_RIGHT'] = re.compile(b'^\x1b\[(\d+)C') - codes['CSI_CURSOR_LEFT'] = re.compile(b'^\x1b\[(\d+)D') - codes['CSI_CURSOR_UP_HEAD'] = re.compile(b'^\x1b\[(\d+)F') - codes['CSI_CURSOR_DOWN_HEAD'] = re.compile(b'^\x1b\[(\d+)E') + codes['CSI_CURSOR_UP'] = re.compile(b'^\x1b\[(\d*)A') + codes['CSI_CURSOR_DOWN'] = re.compile(b'^\x1b\[(\d*)B') + codes['CSI_CURSOR_RIGHT'] = re.compile(b'^\x1b\[(\d*)C') + codes['CSI_CURSOR_LEFT'] = re.compile(b'^\x1b\[(\d*)D') + codes['CSI_CURSOR_UP_HEAD'] = re.compile(b'^\x1b\[(\d*)F') + codes['CSI_CURSOR_DOWN_HEAD'] = re.compile(b'^\x1b\[(\d*)E') codes['CSI_CURSOR_SAVE'] = re.compile(b'^\x1b\[s') codes['CSI_CURSOR_RESTORE'] = re.compile(b'^\x1b\[u') codes['CSI_CURSOR_REQUEST'] = re.compile(b'^\x1b\[6n') @@ -87,17 +87,17 @@ def draw_ansi(buf: bytes): elif m := E['CSI_CURSOR_COLUMN'].match(buf): x = int(m.group(1)) - 1 elif m := E['CSI_CURSOR_UP'].match(buf): - y = max(0, y - int(m.group(1))) + y = max(0, y - int(m.group(1))) if m.group(1) else max(0, y-1) elif m := E['CSI_CURSOR_DOWN'].match(buf): - y += int(m.group(1)) + y += int(m.group(1)) if m.group(1) else 1 elif m := E['CSI_CURSOR_LEFT'].match(buf): - x = max(0, x - int(m.group(1))) + x = max(0, x - int(m.group(1))) if m.group(1) else max(0, x-1) elif m := E['CSI_CURSOR_RIGHT'].match(buf): - x += int(m.group(1)) + x += int(m.group(1)) if m.group(1) else 1 elif m := E['CSI_CURSOR_UP_HEAD'].match(buf): - x, y = 0, max(0, y - int(m.group(1))) + x, y = 0, max(0, y - int(m.group(1))) if m.group(1) else max(0, y-1) elif m := E['CSI_CURSOR_DOWN_HEAD'].match(buf): - x, y = 0, y + int(m.group(1)) + x, y = 0, y + int(m.group(1)) if m.group(1) else y+1 elif m := E['CSI_CURSOR_SAVE'].match(buf): saved_sco = (x, y) elif m := E['CSI_CURSOR_RESTORE'].match(buf):