pub struct Text {
pub plain: String,
pub spans: Vec<Span>,
pub style: Style,
pub justify: JustifyMethod,
pub end: String,
pub overflow: OverflowMethod,
pub no_wrap: bool,
}Expand description
A renderable piece of text with optional style spans.
Fields§
§plain: StringThe plain text content.
spans: Vec<Span>Style spans applied over the text.
style: StyleDefault style for the entire text.
justify: JustifyMethodJustification method.
end: StringEnd string (appended during rendering).
overflow: OverflowMethodOverflow method.
no_wrap: boolIf true, don’t wrap.
Implementations§
Source§impl Text
impl Text
Sourcepub fn justify(self, justify: JustifyMethod) -> Self
pub fn justify(self, justify: JustifyMethod) -> Self
Builder: set the justification.
Sourcepub fn overflow(self, overflow: OverflowMethod) -> Self
pub fn overflow(self, overflow: OverflowMethod) -> Self
Builder: set overflow method.
Sourcepub fn append(&mut self, text: impl Into<Text>, style: Option<Style>)
pub fn append(&mut self, text: impl Into<Text>, style: Option<Style>)
Append another Text or string to this one, with an optional style.
Sourcepub fn append_styled(&mut self, text: impl Into<String>, style: Style)
pub fn append_styled(&mut self, text: impl Into<String>, style: Style)
Append a plain string with a style.
Sourcepub fn style_at(&self, position: usize) -> Style
pub fn style_at(&self, position: usize) -> Style
Get the style at a given position, combining spans.
Sourcepub fn truncate(&mut self, max_width: usize, overflow: OverflowMethod)
pub fn truncate(&mut self, max_width: usize, overflow: OverflowMethod)
Truncate the text to the given maximum width.
Sourcepub fn expand_tabs(&mut self)
pub fn expand_tabs(&mut self)
Expand tab characters to spaces.
Sourcepub fn split_lines(&self) -> Vec<Text>
pub fn split_lines(&self) -> Vec<Text>
Split the text into lines.
Sourcepub fn pad(&mut self, count: usize, character: char)
pub fn pad(&mut self, count: usize, character: char)
Pad the text on both sides with count copies of character.
Sourcepub fn align(&mut self, method: AlignMethod, width: usize)
pub fn align(&mut self, method: AlignMethod, width: usize)
Align the text within a given width using the specified method.
Sourcepub fn stylize(&mut self, style: Style, start: usize, end: Option<usize>)
pub fn stylize(&mut self, style: Style, start: usize, end: Option<usize>)
Apply a style to a range of text.
Equivalent to Python’s Text.stylize().
Sourcepub fn highlight_regex(&mut self, pattern: &str, style: Style) -> usize
pub fn highlight_regex(&mut self, pattern: &str, style: Style) -> usize
Highlight all regex matches with the given style. Returns count of
matches. Equivalent to Python’s Text.highlight_regex().
Trait Implementations§
Source§impl Renderable for Text
Allows a Text object to be used as a renderable.
impl Renderable for Text
Allows a Text object to be used as a renderable.
Source§fn render(&self, _options: &ConsoleOptions) -> RenderResult
fn render(&self, _options: &ConsoleOptions) -> RenderResult
RenderResult using the provided options. Read moreSource§fn measure(&self, _options: &ConsoleOptions) -> Option<Measurement>
fn measure(&self, _options: &ConsoleOptions) -> Option<Measurement>
__rich_measure__).
Override to provide min/max width constraints for layout.