pub struct Spans<'a>(pub Vec<Span<'a>>);
👎Deprecated: Use
ratatui::text::Line
insteadExpand description
A string composed of clusters of graphemes, each with their own style.
Spans
has been deprecated in favor of Line
, and will be removed in the
future. All methods that accept Spans have been replaced with methods that
accept Into<Line<’a>> (which is implemented on Spans
) to allow users of
this crate to gradually transition to Line.
Tuple Fields§
§0: Vec<Span<'a>>
👎Deprecated: Use
ratatui::text::Line
insteadImplementations§
source§impl<'a> Spans<'a>
impl<'a> Spans<'a>
sourcepub fn width(&self) -> usize
pub fn width(&self) -> usize
Returns the width of the underlying string.
Examples
let spans = Spans::from(vec![
Span::styled("My", Style::default().fg(Color::Yellow)),
Span::raw(" text"),
]);
assert_eq!(7, spans.width());
sourcepub fn patch_style(&mut self, style: Style)
pub fn patch_style(&mut self, style: Style)
Patches the style of each Span in an existing Spans, adding modifiers from the given style.
Examples
let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
let mut raw_spans = Spans::from(vec![
Span::raw("My"),
Span::raw(" text"),
]);
let mut styled_spans = Spans::from(vec![
Span::styled("My", style),
Span::styled(" text", style),
]);
assert_ne!(raw_spans, styled_spans);
raw_spans.patch_style(style);
assert_eq!(raw_spans, styled_spans);
sourcepub fn reset_style(&mut self)
pub fn reset_style(&mut self)
Resets the style of each Span in the Spans.
Equivalent to calling patch_style(Style::reset())
.
Examples
let mut spans = Spans::from(vec![
Span::styled("My", Style::default().fg(Color::Yellow)),
Span::styled(" text", Style::default().add_modifier(Modifier::BOLD)),
]);
spans.reset_style();
assert_eq!(Style::reset(), spans.0[0].style);
assert_eq!(Style::reset(), spans.0[1].style);
Trait Implementations§
source§impl<'a> PartialEq<Spans<'a>> for Spans<'a>
impl<'a> PartialEq<Spans<'a>> for Spans<'a>
impl<'a> Eq for Spans<'a>
impl<'a> StructuralEq for Spans<'a>
impl<'a> StructuralPartialEq for Spans<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Spans<'a>
impl<'a> Send for Spans<'a>
impl<'a> Sync for Spans<'a>
impl<'a> Unpin for Spans<'a>
impl<'a> UnwindSafe for Spans<'a>
Blanket Implementations§
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
Mutably borrows from an owned value. Read more