ColorTerm
Module: terminaltexteffects.utils.colorterm
New in 0.16.0
reset_fg() and reset_bg() are available on development main and are not in the published 0.15.0 package.
Use reset_fg() to restore the terminal's default foreground color, or reset_bg() to restore its default background
color. Each emits a selective SGR reset and leaves the other color and text attributes in effect. Use
ansitools.reset_all() to clear all formatting.
Convert XTerm 256 color codes and RGB hex colors into ANSI escape sequences.
Functions:
| Name | Description |
|---|---|
`fg` |
Set the foreground color using an XTerm code or RGB hex string. |
`bg` |
Set the background color using an XTerm code or RGB hex string. |
`reset_fg` |
Restore the default foreground color without clearing other formatting. |
`reset_bg` |
Restore the default background color without clearing other formatting. |
bg(color_code)
Set the background color of the terminal text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color_code
|
str | int
|
The background color as an XTerm 256 color code
or an RGB hex string, with or without a leading |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The ANSI escape sequence to set the background color. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Source code in terminaltexteffects/utils/colorterm.py
fg(color_code)
Set the foreground color of the terminal text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color_code
|
str | int
|
The foreground color as an XTerm 256 color code
or an RGB hex string, with or without a leading |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The ANSI escape sequence to set the foreground color. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |