MCPcopy Create free account
hub / github.com/facebook/PathPicker / parse_formatting

Method parse_formatting

src/pathpicker/formatted_text.py:42–59  ·  view source on GitHub ↗

Parse ANSI formatting; the formatting passed in should be stripped of the control characters and ending character

(cls, formatting: str)

Source from the content-addressed store, hash-verified

40
41 @classmethod
42 def parse_formatting(cls, formatting: str) -> Tuple[int, int, int]:
43 """Parse ANSI formatting; the formatting passed in should be
44 stripped of the control characters and ending character"""
45 fg_color = -1 # -1 default means "use default", not "use white/black"
46 bg_color = -1
47 other = 0
48 int_values = [int(value) for value in formatting.split(";") if value]
49 for code in int_values:
50 if cls.FOREGROUND_RANGE.bottom <= code <= cls.FOREGROUND_RANGE.top:
51 fg_color = code - cls.FOREGROUND_RANGE.bottom
52 elif cls.BACKGROUND_RANGE.bottom <= code <= cls.BACKGROUND_RANGE.top:
53 bg_color = code - cls.BACKGROUND_RANGE.bottom
54 elif code == cls.BOLD_ATTRIBUTE:
55 other = other | curses.A_BOLD
56 elif code == cls.UNDERLINE_ATTRIBUTE:
57 other = other | curses.A_UNDERLINE
58
59 return fg_color, bg_color, other
60
61 @classmethod
62 def get_sequence_for_attributes(

Callers 1

print_textMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected