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,
pub tab_size: usize,
pub indent_guides: 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.
tab_size: usizeTab width for expand_tabs (default 8).
indent_guides: boolWhether to show indent guide lines.
Implementations§
Source§impl Text
impl Text
Sourcepub fn from_ansi(text: &str) -> Self
pub fn from_ansi(text: &str) -> Self
Parse an ANSI-escaped string into a styled Text.
Extracts SGR (Select Graphic Rendition) codes as style spans and strips all other ANSI escape sequences.
Sourcepub fn from_markup(markup: &str) -> Self
pub fn from_markup(markup: &str) -> Self
Parse a BBCode-like markup string into a styled Text.
Delegates to crate::markup::render().
Sourcepub fn get_style_mut(&mut self) -> &mut Style
pub fn get_style_mut(&mut self) -> &mut Style
Get a mutable reference to the default style.
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 with_indent_guides(self, show: bool) -> Self
pub fn with_indent_guides(self, show: bool) -> Self
Builder: show indent guides.
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_tokens(&mut self, tokens: Vec<(String, Style)>)
pub fn append_tokens(&mut self, tokens: Vec<(String, Style)>)
Append a sequence of (text, style) tokens.
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 get_style_at_offset(&self, offset: usize) -> Style
pub fn get_style_at_offset(&self, offset: usize) -> Style
Get the combined style at a specific byte offset. Iterates through spans that cover the offset and combines them.
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 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 stylize_before(&mut self, style: Style, start: usize, end: Option<usize>)
pub fn stylize_before(&mut self, style: Style, start: usize, end: Option<usize>)
Like [stylize] but inserts the span at the beginning of the spans
list, giving it lower priority than existing spans.
Sourcepub fn apply_meta(&mut self, meta: Vec<u8>, spans: &[Span])
pub fn apply_meta(&mut self, meta: Vec<u8>, spans: &[Span])
Apply metadata to the text at the given spans. Sets the style.meta field on overlapping spans.
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().
Sourcepub fn blank_copy(&self) -> Self
pub fn blank_copy(&self) -> Self
Return a new Text with the same style settings but empty content.
Sourcepub fn copy_styles(&self) -> Self
pub fn copy_styles(&self) -> Self
Return a copy with only the plain text (no spans, default style).
Sourcepub fn detect_indentation(&self) -> (String, usize)
pub fn detect_indentation(&self) -> (String, usize)
Detect the leading whitespace indentation. Returns (indent_string, indent_count) where indent_count is the number of occurrences of the first indent character.
Sourcepub fn divide(&self, offsets: &[usize]) -> Vec<Text>
pub fn divide(&self, offsets: &[usize]) -> Vec<Text>
Split the text at the given byte offsets into multiple pieces, preserving style spans.
Sourcepub fn extend_style(&mut self, style: Style)
pub fn extend_style(&mut self, style: Style)
Apply a style to the entire text by adding a full-length span.
Sourcepub fn fit(&self, width: usize) -> Text
pub fn fit(&self, width: usize) -> Text
Truncate or pad to exactly fit width cells.
Uses existing truncate + align methods.
Sourcepub fn set_length(&mut self, length: usize)
pub fn set_length(&mut self, length: usize)
Pad with spaces or truncate to exact length cells.
Sourcepub fn remove_suffix(&mut self, suffix: &str) -> bool
pub fn remove_suffix(&mut self, suffix: &str) -> bool
Remove a suffix from the text, returning true if it was present.
Sourcepub fn rstrip_end(&mut self, end: &str) -> bool
pub fn rstrip_end(&mut self, end: &str) -> bool
Remove a trailing end string, returning true if it was present.
Sourcepub fn right_crop(&mut self, offset: usize) -> Text
pub fn right_crop(&mut self, offset: usize) -> Text
Crop all text beyond offset. Returns the cropped (removed) portion.
Sourcepub fn split(&self) -> Vec<Text>
pub fn split(&self) -> Vec<Text>
Split at every character boundary, producing per-character Text pieces.
Sourcepub fn wrap(&self, width: usize) -> Vec<Text>
pub fn wrap(&self, width: usize) -> Vec<Text>
Simple word-wrap: split text into lines, each not exceeding width
cells. Returns a Vec<Text>, one per wrapped line.
Equivalent to Python’s Text.wrap().
Sourcepub fn markup(&self) -> String
pub fn markup(&self) -> String
Serialize the text to a BBCode-like markup string.
Each span is wrapped in [style]...[/] tags.
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.
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.Auto Trait Implementations§
impl Freeze for Text
impl RefUnwindSafe for Text
impl Send for Text
impl Sync for Text
impl Unpin for Text
impl UnsafeUnpin for Text
impl UnwindSafe for Text
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more