Text with color / style.
text (str, optional) – Default unstyled text. Defaults to “”.
style (Union[str, Style], optional) – Base style for text. Defaults to “”.
justify (str, optional) – Justify method: “left”, “center”, “full”, “right”. Defaults to None.
overflow (str, optional) – Overflow method: “crop”, “fold”, “ellipsis”. Defaults to None.
no_wrap (bool, optional) – Disable text wrapping, or None for default. Defaults to None.
end (str, optional) – Character to end text with. Defaults to “\n”.
tab_size (int) – Number of spaces per tab, or None
to use console.tab_size
. Defaults to None.
spans (List[Span], optional)
Align text to a given width.
Add text with an optional style.
Append another Text instance. This method is more performant that Text.append, but only works for Text.
Append iterable of str and style. Style may be a Style instance or a str style definition.
Apply metadata to the text, or a portion of the text.
Construct a text instance by combining a sequence of strings with optional styles. The positional arguments should be either strings, or a tuple of string + style.
style (Union[str, Style], optional) – Base style for text. Defaults to “”.
justify (str, optional) – Justify method: “left”, “center”, “full”, “right”. Defaults to None.
overflow (str, optional) – Overflow method: “crop”, “fold”, “ellipsis”. Defaults to None.
no_wrap (bool, optional) – Disable text wrapping, or None for default. Defaults to None.
end (str, optional) – Character to end text with. Defaults to “\n”.
tab_size (int) – Number of spaces per tab, or None
to use console.tab_size
. Defaults to None.
meta (Dict[str, Any], optional)
A new text instance.
Return a new Text instance with copied metadata (but not the string or spans).
Get the number of cells required to render this text.
Return a copy of this instance.
Copy styles from another Text instance.
text (Text) – A Text instance to copy styles from, must be the same length.
None
Auto-detect indentation of code.
Number of spaces used to indent code.
Divide text in to a number of lines at given offsets.
offsets (Iterable[int]) – Offsets used to divide text.
New RichText instances between offsets.
Lines
Converts tabs to spaces.
tab_size (int, optional) – Size of tabs. Defaults to 8.
None
Extend the Text given number of spaces where the spaces have the same style as the last character.
spaces (int) – Number of spaces to add to the Text.
None
Fit the text in to given width by chopping in to lines.
width (int) – Maximum characters in a line.
Lines container.
Lines
Create a Text object from a string containing ANSI escape codes.
text (str) – A string containing escape codes.
style (Union[str, Style], optional) – Base style for text. Defaults to “”.
justify (str, optional) – Justify method: “left”, “center”, “full”, “right”. Defaults to None.
overflow (str, optional) – Overflow method: “crop”, “fold”, “ellipsis”. Defaults to None.
no_wrap (bool, optional) – Disable text wrapping, or None for default. Defaults to None.
end (str, optional) – Character to end text with. Defaults to “\n”.
tab_size (int) – Number of spaces per tab, or None
to use console.tab_size
. Defaults to None.
Create Text instance from markup.
text (str) – A string containing console markup.
style (Union[str, Style], optional) – Base style for text. Defaults to “”.
emoji (bool, optional) – Also render emoji code. Defaults to True.
emoji_variant (str, optional) – Optional emoji variant, either “text” or “emoji”. Defaults to None.
justify (str, optional) – Justify method: “left”, “center”, “full”, “right”. Defaults to None.
overflow (str, optional) – Overflow method: “crop”, “fold”, “ellipsis”. Defaults to None.
end (str, optional) – Character to end text with. Defaults to “\n”.
A Text instance with markup rendered.
Get the style of a character at give offset.
Highlight text with a regular expression, where group names are translated to styles.
re_highlight (Union[re.Pattern, str]) – A regular expression object or string.
style (Union[GetStyleCallable, StyleType]) – Optional style to apply to whole match, or a callable which accepts the matched text and returns a style. Defaults to None.
style_prefix (str, optional) – Optional prefix to add to style group names.
Number of regex matches
Highlight words with a style.
Join text together with this instance as the separator.
Get console markup to render this Text.
A string potentially creating markup tags.
Apply event handlers (used by Textual project).
Example
>>> from rich.text import Text >>> text = Text("hello world") >>> text.on(click="view.toggle('world')")
Pad left and right with a given number of characters.
Pad the left with a given character.
Pad the right with a given character.
Get the text as a single string.
Remove a suffix if it exists.
suffix (str) – Suffix to remove.
None
Render the text as Segments.
Remove a number of characters from the end of the text.
amount (int)
None
Strip whitespace from end of text.
None
Remove whitespace beyond a certain width at the end of the text.
size (int) – The desired size of the text.
None
Set new length of the text, clipping or padding is required.
new_length (int)
None
Get a reference to the internal list of spans.
Split rich text in to lines, preserving styles.
A list of rich text, one per line of the original.
List[RichText]
Construct a Text instance with a pre-applied styled. A style applied in this way won’t be used to pad the text when it is justified.
text (str) – A string containing console markup.
style (Union[str, Style]) – Style to apply to the text. Defaults to “”.
justify (str, optional) – Justify method: “left”, “center”, “full”, “right”. Defaults to None.
overflow (str, optional) – Overflow method: “crop”, “fold”, “ellipsis”. Defaults to None.
A text instance with a style applied to the entire string.
Apply a style to the text, or a portion of the text.
Apply a style to the text, or a portion of the text. Styles will be applied before other styles already present.
Truncate text if it is longer that a given width.
Adds indent guide lines to text.
New text with indentation guides.
Word wrap the text.
console (Console) – Console instance.
width (int) – Number of cells available per line.
justify (str, optional) – Justify method: “default”, “left”, “center”, “full”, “right”. Defaults to “default”.
overflow (str, optional) – Overflow method: “crop”, “fold”, or “ellipsis”. Defaults to None.
tab_size (int, optional) – Default tab size. Defaults to 8.
no_wrap (bool, optional) – Disable wrapping, Defaults to False.
Number of lines.
Lines
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4