Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/wcwidth/control_codes.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

6 statements  

1""" 

2Control character sets for terminal handling. 

3 

4This module provides the control character sets used by the width() function to handle terminal 

5control 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, ACK 

13 list(range(0x10, 0x1b)) + # DLE through SUB (^Z) 

14 list(range(0x1c, 0x20)) + # FS, GS, RS, US 

15 [0x7f] + # DEL 

16 list(range(0x80, 0xa0)) # C1 control characters 

17 ) 

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 1 

32 '\x09', # HT (horizontal tab) - advance to next tab stop 

33 '\x0d', # CR (carriage return) - cursor to column 0 

34}) 

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', # NUL 

40 '\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'}