disp_str(buffer:string) -> (string, [int]) Return the string that should be the printed representation of |buffer| and a list detailing where the characters of |buffer| get used up. E.g.: >>> disp_str(chr(3)) ('^C', [1, 0])
(buffer: str)
| 40 | |
| 41 | |
| 42 | def disp_str(buffer: str) -> tuple[str, list[int]]: |
| 43 | """disp_str(buffer:string) -> (string, [int]) |
| 44 | |
| 45 | Return the string that should be the printed representation of |
| 46 | |buffer| and a list detailing where the characters of |buffer| |
| 47 | get used up. E.g.: |
| 48 | |
| 49 | >>> disp_str(chr(3)) |
| 50 | ('^C', [1, 0]) |
| 51 | |
| 52 | """ |
| 53 | b: list[int] = [] |
| 54 | s: list[str] = [] |
| 55 | for c in buffer: |
| 56 | if c == '\x1a': |
| 57 | s.append(c) |
| 58 | b.append(2) |
| 59 | elif ord(c) < 128: |
| 60 | s.append(c) |
| 61 | b.append(1) |
| 62 | elif unicodedata.category(c).startswith("C"): |
| 63 | c = r"\u%04x" % ord(c) |
| 64 | s.append(c) |
| 65 | b.extend([0] * (len(c) - 1)) |
| 66 | else: |
| 67 | s.append(c) |
| 68 | b.append(str_width(c)) |
| 69 | return "".join(s), b |
| 70 | |
| 71 | |
| 72 | # syntax classes: |
no test coverage detected