|
43 | 43 | |
44 | 44 | __copyright__ = "Copyright © 2021 Forschungszentrum Jülich GmbH. All rights reserved." |
45 | 45 | __license__ = "MIT" |
46 | | -__version_info__ = (1, 6, 4) |
| 46 | +__version_info__ = (1, 6, 5) |
47 | 47 | __version__ = ".".join(map(str, __version_info__)) |
48 | 48 |
|
49 | 49 |
|
@@ -904,9 +904,11 @@ def _init_terminal_codes(cls) -> None: |
904 | 904 | return |
905 | 905 | supported_colors = int(cls._query_terminfo_database("colors")) |
906 | 906 | cls._codename_to_terminal_code = { |
907 | | - codename: cls._query_terminfo_database(codename) |
908 | | - if not (codename.startswith("bg_") or codename.startswith("fg_")) or supported_colors >= 8 |
909 | | - else "" |
| 907 | + codename: ( |
| 908 | + cls._query_terminfo_database(codename) |
| 909 | + if not (codename.startswith("bg_") or codename.startswith("fg_")) or supported_colors >= 8 |
| 910 | + else "" |
| 911 | + ) |
910 | 912 | for codename in cls._codenames |
911 | 913 | } |
912 | 914 | cls._codename_to_terminal_code.update(cls._name_to_control_character) |
@@ -964,10 +966,14 @@ def _init_term(self) -> None: |
964 | 966 | self._tty_out = open("/dev/tty", "w", encoding=self._user_locale, errors="replace") |
965 | 967 | self._old_term = termios.tcgetattr(self._tty_in.fileno()) |
966 | 968 | self._new_term = termios.tcgetattr(self._tty_in.fileno()) |
967 | | - # set the terminal to: unbuffered, no echo and no <CR> to <NL> translation (so <enter> sends <CR> instead of |
968 | | - # <NL, this is necessary to distinguish between <enter> and <Ctrl-j> since <Ctrl-j> generates <NL>) |
| 969 | + # set the terminal to: no line-buffering, no echo and no <CR> to <NL> translation (so <enter> sends <CR> instead |
| 970 | + # of <NL, this is necessary to distinguish between <enter> and <Ctrl-j> since <Ctrl-j> generates <NL>) |
969 | 971 | self._new_term[3] = cast(int, self._new_term[3]) & ~termios.ICANON & ~termios.ECHO & ~termios.ICRNL |
970 | 972 | self._new_term[0] = cast(int, self._new_term[0]) & ~termios.ICRNL |
| 973 | + # Set the timings for an unbuffered read: Return immediately after at least one character has arrived and don't |
| 974 | + # wait for further characters |
| 975 | + cast(list[bytes], self._new_term[6])[termios.VMIN] = b"\x01" |
| 976 | + cast(list[bytes], self._new_term[6])[termios.VTIME] = b"\x00" |
971 | 977 | termios.tcsetattr( |
972 | 978 | self._tty_in.fileno(), termios.TCSAFLUSH, cast(List[Union[int, List[Union[bytes, int]]]], self._new_term) |
973 | 979 | ) |
@@ -1220,9 +1226,11 @@ def get_preview_string() -> Optional[str]: |
1220 | 1226 | ) |
1221 | 1227 | def strip_ansi_codes_except_styling(string: str) -> str: |
1222 | 1228 | stripped_string = strip_ansi_codes_except_styling.ansi_escape_regex.sub( # type: ignore |
1223 | | - lambda match_obj: match_obj.group(0) |
1224 | | - if strip_ansi_codes_except_styling.ansi_sgr_regex.match(match_obj.group(0)) # type: ignore |
1225 | | - else "", |
| 1229 | + lambda match_obj: ( |
| 1230 | + match_obj.group(0) |
| 1231 | + if strip_ansi_codes_except_styling.ansi_sgr_regex.match(match_obj.group(0)) # type: ignore |
| 1232 | + else "" |
| 1233 | + ), |
1226 | 1234 | string, |
1227 | 1235 | ) |
1228 | 1236 | return cast(str, stripped_string) |
|
0 commit comments