regex
This modules contains all of the regex-related names and utilites.
escape_markup(text)
Escapes any potential markup to avoid double-parsing.
Use this when treating already parsed markup.
Source code in pytermgui/regex.py
77 78 79 80 81 82 83 84 85 86 87 88 |
|
has_open_sequence(text)
cached
Figures out if the given text has any unclosed ANSI sequences.
It supports standard SGR (\x1b[1mHello
), OSC (\x1b[30;2ST\x1b\\
) and Kitty APC codes
(_Garguments;hex_data\x1b\\
). It also recognizes incorrect syntax; it only considers
a tag closed when it is using the right closing sequence, e.g. m
or H
for SGR, \x1b\\
for OSC and APC types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The text to test. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if there is at least one tag that hasn't been closed, False otherwise. |
Source code in pytermgui/regex.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
real_length(text)
cached
Gets the display-length of text.
This length means no ANSI sequences are counted. This method is a convenience wrapper
for len(strip_ansi(text))
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The text to calculate the length of. |
required |
Returns:
Type | Description |
---|---|
int
|
The display-length of text. |
Source code in pytermgui/regex.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
strip_ansi(text)
cached
Removes ANSI sequences from text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
A string or bytes object containing 0 or more ANSI sequences. |
required |
Returns:
Type | Description |
---|---|
str
|
The text without any ANSI sequences. |
Source code in pytermgui/regex.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
strip_markup(text)
cached
Removes markup tags from text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
A string or bytes object containing 0 or more markup tags. |
required |
Returns:
Type | Description |
---|---|
str
|
The text without any markup tags. |
Source code in pytermgui/regex.py
46 47 48 49 50 51 52 53 54 55 56 57 |
|