st
FG ¶
Bases: ColorANSI
Foreground Color
BG ¶
Bases: ColorANSI
Background Color
ST ¶
Bases: ColorANSI
Style
sf ¶
A collection of functions that can be used to filter strings.
filename
classmethod
¶
Removes or replaces characters that are not allowed to be in a filename.
filepath
classmethod
¶
Removes or replaces characters that are not allowed to be in a filepath.
Source code in stdl/st.py
ascii
classmethod
¶
colored ¶
colored(text: str, color: ForegroundColor | None = None, background: BackgroundColor | None = None, style: Style | None = None)
Returns the text with ansi color, background color and text style codes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text |
str
|
The text that should be colorized. |
required |
color |
str
|
The color to use for the text. |
None
|
background |
str
|
The color to use for the background. |
None
|
style |
str
|
The style to use for the text. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The colorized text. |
Source code in stdl/st.py
terminal_link ¶
terminal_link(uri: str, label: str | None = None, color: ForegroundColor = 'white', background: BackgroundColor | None = None, style: Style | None = None)
Returns a hyperlink that can be used in terminals.
NOTE
Hyperlinks are not supported in all terminals. For more information visit https://github.com/Alhadis/OSC8-Adoption/ and https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri |
str
|
The URI of the link. |
required |
label |
str
|
The label of the link. Defaults to the URI. |
None
|
color |
str
|
The color of the link. Defaults to white. |
'white'
|
background |
str
|
The background color of the link. |
None
|
style |
str
|
The style of the link. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The link as a string. |
Source code in stdl/st.py
remove ¶
Remove or replace characters in a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s |
str
|
Input string. |
required |
chars |
str | set
|
Characters to remove |
required |
replace_with |
str
|
If provided, replace the characters with this value. |
''
|
Source code in stdl/st.py
keep ¶
Keep provided characters in a string. Remove or replace others.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s |
str
|
Input string |
required |
chars |
str | set
|
Characters to keep |
required |
replace_with |
str
|
If provided, replace other characters with this value. |
''
|
Source code in stdl/st.py
snake_case ¶
camel_case ¶
kebab_case ¶
Converts a given string to kebab-case.
Source code in stdl/st.py
wrapped ¶
Wraps the given text to a specified width and separates lines with the given newline character.
len_without_ansi ¶
Returns the length of the string without the ANSI codes.
ansi_ljust ¶
ljust function that takes into account the length of the ANSI codes in the string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s |
str
|
The string to be left justified. |
required |
width |
int
|
The width of the string. |
required |
fillchar |
str
|
The character to fill the string with. Defaults to " ". |
' '
|
Source code in stdl/st.py
ansi_rjust ¶
rjust function that takes into account the length of the ANSI codes in the string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s |
str
|
The string to be right justified. |
required |
width |
int
|
The width of the string. |
required |
fillchar |
str
|
The character to fill the string with. Defaults to " ". |
' '
|