Skip to main content

TextStyle

Struct TextStyle 

Source
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

Source

pub fn new() -> Self

Source

pub fn foreground(self, color: impl Into<Color>) -> Self

Sets the text foreground color.

Source

pub fn reset_foreground(self) -> Self

Returns the text foreground color to the terminal default.

Source

pub fn background(self, color: impl Into<Color>) -> Self

Sets the text background color.

Source

pub fn reset_background(self) -> Self

Returns the text background color to the terminal default.

Source

pub fn add_attribute(self, attribute: TextAttribute) -> Self

Adds one active text attribute.

Source

pub fn add_attributes(self, attributes: TextAttributes) -> Self

Adds a set of active text attributes.

Source

pub fn remove_attribute(self, attribute: TextAttribute) -> Self

Removes one active text attribute.

Source

pub fn remove_attributes(self, attributes: TextAttributes) -> Self

Removes a set of active text attributes.

Source

pub fn reset_attributes(self) -> Self

Removes every active text attribute.

Source

pub fn bold(self) -> Self

Source

pub fn dim(self) -> Self

Source

pub fn italic(self) -> Self

Source

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.

Source

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.

Source

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.

Source

pub fn underline(self, underline: Underline) -> Self

Replaces the complete underline value.

Source

pub fn reset_underline(self) -> Self

Removes the underline, including its color.

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.

Removes the OSC 8 hyperlink from this text.

Source

pub fn reverse(self) -> Self

Source

pub fn hide(self) -> Self

Source

pub fn strikethrough(self) -> Self

Source

pub const fn get_foreground(&self) -> Option<Color>

Returns the foreground color instruction, if this style sets one.

Source

pub const fn get_background(&self) -> Option<Color>

Returns the background color instruction, if this style sets one.

Source

pub const fn get_underline(&self) -> Option<Underline>

Returns the underline instruction, if this style sets one.

Returns the hyperlink attached to this text, if any.

Source

pub const fn get_attributes(&self) -> TextAttributes

Returns the active text attributes.

Trait Implementations§

Source§

impl Clone for TextStyle

Source§

fn clone(&self) -> TextStyle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextStyle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextStyle

Source§

fn default() -> TextStyle

Returns the “default value” for a type. Read more
Source§

impl<'a> From<&'a TextStyle> for TerminalTextStyle<'a>

Source§

fn from(value: &'a TextStyle) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for TextStyle

Source§

fn eq(&self, other: &TextStyle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TextStyle

Source§

impl StructuralPartialEq for TextStyle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.