sequence¶
Module contains definitions for working with ANSI escape sequences as classes and instances.
Each preset defined below is a valid argument for autocomplete()
and
build()
methods.
- class pytermor.sequence.SequenceSGR(*params: int)¶
Class representing SGR-type escape sequence with varying amount of parameters.
SequenceSGR with zero params was specifically implemented to translate into empty string and not into
\e[m
, which would have made sense, but also would be very entangling, as this sequence is equivalent of\e[0m
– hard reset sequence. The empty-string-sequence is predefined asNOOP
.It’s possible to add of one SGR sequence to another:
SequenceSGR(31) + SequenceSGR(1)
which is equivalent to:
SequenceSGR(31, 1)
- print() str ¶
Build up actual byte sequence and return as an ASCII-encoded string.
- pytermor.sequence.build(*args: str | int | SequenceSGR) SequenceSGR ¶
Create new SequenceSGR with specified args as params.
Resulting sequence param order is same as an argument order.
- pytermor.sequence.color_indexed(color: int, bg: bool = False) SequenceSGR ¶
Wrapper for creation of SequenceSGR that sets foreground (or background) to one of 256-color pallete value.
- Parameters
color – Index of the color in the pallete, 0 – 255.
bg – Set to true to change the background color (default is foreground).
- Returns
SequenceSGR with required params.
- pytermor.sequence.color_rgb(r: int, g: int, b: int, bg: bool = False) SequenceSGR ¶
Wrapper for creation of SequenceSGR operating in True Color mode (16M). Valid values for r, g and b are in range [0; 255]. This range linearly translates into [0x00; 0xFF] for each channel. The result value is composed as
#RRGGBB
. For example, sequence with color of #FF3300 can be created with:color_rgb(255, 51, 0)
- Parameters
r – Red channel value, 0 – 255.
g – Blue channel value, 0 – 255.
b – Green channel value, 0 – 255.
bg – Set to true to change the background color (default is foreground).
- Returns
SequenceSGR with required params.
- pytermor.sequence.NOOP = SGR[]¶
Special sequence in case where you have to provide one or another SGR, but do not want anything to be actually printed.
NOOP.print()
returns empty string.NOOP.params()
returns empty list.
New in version 1.8.
- pytermor.sequence.RESET = SGR[0]¶
Reset all attributes and colors.
- pytermor.sequence.BOLD = SGR[1]¶
- pytermor.sequence.DIM = SGR[2]¶
- pytermor.sequence.ITALIC = SGR[3]¶
- pytermor.sequence.UNDERLINED = SGR[4]¶
- pytermor.sequence.BLINK_SLOW = SGR[5]¶
- pytermor.sequence.BLINK_FAST = SGR[6]¶
- pytermor.sequence.INVERSED = SGR[7]¶
- pytermor.sequence.HIDDEN = SGR[8]¶
- pytermor.sequence.CROSSLINED = SGR[9]¶
- pytermor.sequence.DOUBLE_UNDERLINED = SGR[21]¶
- pytermor.sequence.OVERLINED = SGR[53]¶
- pytermor.sequence.NO_BOLD_DIM = SGR[22]¶
- pytermor.sequence.ITALIC_OFF = SGR[23]¶
- pytermor.sequence.UNDERLINED_OFF = SGR[24]¶
- pytermor.sequence.BLINK_OFF = SGR[25]¶
- pytermor.sequence.INVERSED_OFF = SGR[27]¶
- pytermor.sequence.HIDDEN_OFF = SGR[28]¶
- pytermor.sequence.CROSSLINED_OFF = SGR[29]¶
- pytermor.sequence.OVERLINED_OFF = SGR[55]¶
- pytermor.sequence.BLACK = SGR[30]¶
- pytermor.sequence.RED = SGR[31]¶
- pytermor.sequence.GREEN = SGR[32]¶
- pytermor.sequence.YELLOW = SGR[33]¶
- pytermor.sequence.BLUE = SGR[34]¶
- pytermor.sequence.MAGENTA = SGR[35]¶
- pytermor.sequence.CYAN = SGR[36]¶
- pytermor.sequence.WHITE = SGR[37]¶
- pytermor.sequence.COLOR_OFF = SGR[39]¶
- pytermor.sequence.BG_BLACK = SGR[40]¶
- pytermor.sequence.BG_RED = SGR[41]¶
- pytermor.sequence.BG_GREEN = SGR[42]¶
- pytermor.sequence.BG_YELLOW = SGR[43]¶
- pytermor.sequence.BG_BLUE = SGR[44]¶
- pytermor.sequence.BG_MAGENTA = SGR[45]¶
- pytermor.sequence.BG_CYAN = SGR[46]¶
- pytermor.sequence.BG_WHITE = SGR[47]¶
- pytermor.sequence.BG_COLOR_OFF = SGR[49]¶
- pytermor.sequence.GRAY = SGR[90]¶
- pytermor.sequence.HI_RED = SGR[91]¶
- pytermor.sequence.HI_GREEN = SGR[92]¶
- pytermor.sequence.HI_YELLOW = SGR[93]¶
- pytermor.sequence.HI_BLUE = SGR[94]¶
- pytermor.sequence.HI_MAGENTA = SGR[95]¶
- pytermor.sequence.HI_CYAN = SGR[96]¶
- pytermor.sequence.HI_WHITE = SGR[97]¶
- pytermor.sequence.BG_GRAY = SGR[100]¶
- pytermor.sequence.BG_HI_RED = SGR[101]¶
- pytermor.sequence.BG_HI_GREEN = SGR[102]¶
- pytermor.sequence.BG_HI_YELLOW = SGR[103]¶
- pytermor.sequence.BG_HI_BLUE = SGR[104]¶
- pytermor.sequence.BG_HI_MAGENTA = SGR[105]¶
- pytermor.sequence.BG_HI_CYAN = SGR[106]¶
- pytermor.sequence.BG_HI_WHITE = SGR[107]¶