from __future__ import annotations
+import sys
+
from contextlib import contextmanager
from dataclasses import dataclass, field, fields
import unicodedata
b: list[int] = []
s: list[str] = []
for c in buffer:
- if ord(c) < 128:
+ if c == '\x1a':
+ s.append(c)
+ b.append(2)
+ elif ord(c) < 128:
s.append(c)
b.append(1)
elif unicodedata.category(c).startswith("C"):
(r"\C-w", "unix-word-rubout"),
(r"\C-x\C-u", "upcase-region"),
(r"\C-y", "yank"),
- (r"\C-z", "suspend"),
+ *(() if sys.platform == "win32" else ((r"\C-z", "suspend"), )),
(r"\M-b", "backward-word"),
(r"\M-c", "capitalize-word"),
(r"\M-d", "kill-word"),
"copyright": _sitebuiltins._Printer('copyright', sys.copyright),
"help": "help",
"clear": _clear_screen,
+ "\x1a": _sitebuiltins.Quitter('\x1a', ''),
}
length = sum(str_width(i) for i in s)
# remove lengths of any escape sequences
sequence = ANSI_ESCAPE_SEQUENCE.findall(s)
- return length - sum(len(i) for i in sequence)
+ ctrl_z_cnt = s.count('\x1a')
+ return length - sum(len(i) for i in sequence) + ctrl_z_cnt
else:
self.__posxy = wlen(newline), y
- if "\x1b" in newline or y != self.__posxy[1]:
+ if "\x1b" in newline or y != self.__posxy[1] or '\x1a' in newline:
# ANSI escape characters are present, so we can't assume
# anything about the position of the cursor. Moving the cursor
# to the left margin should work to get to a known position.
self.__write("\x1b[?12l")
def __write(self, text: str) -> None:
+ if "\x1a" in text:
+ text = ''.join(["^Z" if x == '\x1a' else x for x in text])
+
if self.out is not None:
self.out.write(text.encode(self.encoding, "replace"))
self.out.flush()