pub struct TextStyle { /* private fields */ }Expand description
A reusable set of text styling rules.
A TextStyle carries no geometry. A position that renders inline text cannot
honor padding, a border, or a dimension, so those properties live on
BlockStyle instead and the illegal combination is
unrepresentable rather than merely discouraged.
A TextStyle is an immutable value: builder methods consume and return it, so
styles can be stored, cloned, and extended without affecting each other.
use urushi::{Color, TextStyle};
let base = TextStyle::new().foreground(Color::CYAN);
let emphasized = base.clone().bold();
let text = urushi::StyledText::new("hello", emphasized);
let _ = text;Geometry is not merely discouraged here, it is unrepresentable:
use urushi::{Border, TextStyle};
let _ = TextStyle::new().border(Border::ROUNDED);Implementations§
Source§impl TextStyle
impl TextStyle
pub fn new() -> Self
Sourcepub fn foreground(self, color: impl Into<Color>) -> Self
pub fn foreground(self, color: impl Into<Color>) -> Self
Sets the text foreground color.
Sourcepub fn reset_foreground(self) -> Self
pub fn reset_foreground(self) -> Self
Returns the text foreground color to the terminal default.
Sourcepub fn background(self, color: impl Into<Color>) -> Self
pub fn background(self, color: impl Into<Color>) -> Self
Sets the text background color.
Sourcepub fn reset_background(self) -> Self
pub fn reset_background(self) -> Self
Returns the text background color to the terminal default.
Sourcepub fn add_attribute(self, attribute: TextAttribute) -> Self
pub fn add_attribute(self, attribute: TextAttribute) -> Self
Adds one active text attribute.
Sourcepub fn add_attributes(self, attributes: TextAttributes) -> Self
pub fn add_attributes(self, attributes: TextAttributes) -> Self
Adds a set of active text attributes.
Sourcepub fn remove_attribute(self, attribute: TextAttribute) -> Self
pub fn remove_attribute(self, attribute: TextAttribute) -> Self
Removes one active text attribute.
Sourcepub fn remove_attributes(self, attributes: TextAttributes) -> Self
pub fn remove_attributes(self, attributes: TextAttributes) -> Self
Removes a set of active text attributes.
Sourcepub fn reset_attributes(self) -> Self
pub fn reset_attributes(self) -> Self
Removes every active text attribute.
pub fn bold(self) -> Self
pub fn dim(self) -> Self
pub fn italic(self) -> Self
Sourcepub fn underlined(self) -> Self
pub fn underlined(self) -> Self
Underlines the text with a single line in the foreground color.
This sets the complete default underline value; the other two builders below refine an underline that may already be set.
Sourcepub fn underline_style(self, style: UnderlineStyle) -> Self
pub fn underline_style(self, style: UnderlineStyle) -> Self
Sets the shape the underline is drawn with, adding an underline in the foreground color when the style has none.
Sourcepub fn underline_color(self, color: impl Into<Color>) -> Self
pub fn underline_color(self, color: impl Into<Color>) -> Self
Sets the color the underline is drawn in, adding a single underline when the style has none.
A color is only reachable through an underline, so a style cannot carry an underline color that nothing draws.
Sourcepub fn reset_underline(self) -> Self
pub fn reset_underline(self) -> Self
Removes the underline, including its color.
Sourcepub fn hyperlink(self, hyperlink: impl Into<Hyperlink>) -> Self
pub fn hyperlink(self, hyperlink: impl Into<Hyperlink>) -> Self
Attaches an OSC 8 hyperlink to this text.
A URI converts directly for the ordinary case. Use Hyperlink when
the link needs parameters such as id.
Sourcepub fn reset_hyperlink(self) -> Self
pub fn reset_hyperlink(self) -> Self
Removes the OSC 8 hyperlink from this text.
pub fn blink(self) -> Self
pub fn reverse(self) -> Self
pub fn hide(self) -> Self
pub fn strikethrough(self) -> Self
Sourcepub const fn get_foreground(&self) -> Option<Color>
pub const fn get_foreground(&self) -> Option<Color>
Returns the foreground color instruction, if this style sets one.
Sourcepub const fn get_background(&self) -> Option<Color>
pub const fn get_background(&self) -> Option<Color>
Returns the background color instruction, if this style sets one.
Sourcepub const fn get_underline(&self) -> Option<Underline>
pub const fn get_underline(&self) -> Option<Underline>
Returns the underline instruction, if this style sets one.
Sourcepub fn get_hyperlink(&self) -> Option<&Hyperlink>
pub fn get_hyperlink(&self) -> Option<&Hyperlink>
Returns the hyperlink attached to this text, if any.
Sourcepub const fn get_attributes(&self) -> TextAttributes
pub const fn get_attributes(&self) -> TextAttributes
Returns the active text attributes.