Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
control_codes.py47 linesDownload Raw Back to wcwidth
1"""2Control character sets for terminal handling.3 4This module provides the control character sets used by the width() function to handle terminal5control characters.6"""7 8# Illegal C0/C1 control characters.9# These raise ValueError in 'strict' mode.10ILLEGAL_CTRL = frozenset(11    chr(c) for c in (12        list(range(0x01, 0x07)) +    # SOH, STX, ETX (^C), EOT (^D), ENQ, ACK13        list(range(0x10, 0x1b)) +    # DLE through SUB (^Z)14        list(range(0x1c, 0x20)) +    # FS, GS, RS, US15        [0x7f] +                      # DEL16        list(range(0x80, 0xa0))       # C1 control characters17    )18)19 20# Vertical movement control characters.21# These raise ValueError in 'strict' mode (indeterminate horizontal position).22VERTICAL_CTRL = frozenset({23    '\x0a',  # LF (line feed)24    '\x0b',  # VT (vertical tab)25    '\x0c',  # FF (form feed)26})27 28# Horizontal movement control characters.29# These affect cursor position and are tracked in 'strict' and 'parse' modes.30HORIZONTAL_CTRL = frozenset({31    '\x08',  # BS (backspace) - cursor left 132    '\x09',  # HT (horizontal tab) - advance to next tab stop33    '\x0d',  # CR (carriage return) - cursor to column 034})35 36# Terminal-valid zero-width control characters.37# These are allowed in all modes (zero-width, no movement).38ZERO_WIDTH_CTRL = frozenset({39    '\x00',  # NUL40    '\x07',  # BEL (bell)41    '\x0e',  # SO (shift out)42    '\x0f',  # SI (shift in)43})44 45# All control characters that need special handling (not regular printable).46ALL_CTRL = ILLEGAL_CTRL | VERTICAL_CTRL | HORIZONTAL_CTRL | ZERO_WIDTH_CTRL | {'\x1b'}47