pub struct Style { /* private fields */ }
Expand description
A terminal text style
Style
stores two sets of Attribute
s: those attributes that the style
enables, plus those that the style explicitly disables/turns off. The
latter are relevant if you’re applying a style in the middle of text with a
different style; e.g., if a text styled with "red bold"
contains a
substring styled with "blue not bold"
, you’d want to know that the bold
effect should be disabled for that substring.
Implementations§
Source§impl Style
impl Style
Sourcepub const fn foreground(self, fg: Option<Color>) -> Style
pub const fn foreground(self, fg: Option<Color>) -> Style
Set or clear the foreground color.
Note that setting the foreground to None
is different from setting it
to Color::Default
: if the style is applied in the middle of text
with a foreground color set, None
will leave the foreground color
as-is while Color::Default
will reset it.
Sourcepub const fn background(self, bg: Option<Color>) -> Style
pub const fn background(self, bg: Option<Color>) -> Style
Set or clear the background color
Note that setting the background to None
is different from setting it
to Color::Default
: if the style is applied in the middle of text
with a background color set, None
will leave the background color
as-is while Color::Default
will reset it.
Sourcepub fn enabled_attributes<A: Into<AttributeSet>>(self, attrs: A) -> Style
pub fn enabled_attributes<A: Into<AttributeSet>>(self, attrs: A) -> Style
Set the enabled attributes
Sourcepub fn disabled_attributes<A: Into<AttributeSet>>(self, attrs: A) -> Style
pub fn disabled_attributes<A: Into<AttributeSet>>(self, attrs: A) -> Style
Set the disabled attributes
Sourcepub fn is_enabled(self, attr: Attribute) -> bool
pub fn is_enabled(self, attr: Attribute) -> bool
true
if attr
is enabled
Sourcepub fn is_disabled(self, attr: Attribute) -> bool
pub fn is_disabled(self, attr: Attribute) -> bool
true
if attr
is explicitly disabled
Sourcepub const fn get_foreground(self) -> Option<Color>
pub const fn get_foreground(self) -> Option<Color>
Return the foreground color
Sourcepub const fn get_background(self) -> Option<Color>
pub const fn get_background(self) -> Option<Color>
Return the background color
Sourcepub const fn get_enabled_attributes(self) -> AttributeSet
pub const fn get_enabled_attributes(self) -> AttributeSet
Return the enabled attributes
Sourcepub const fn get_disabled_attributes(self) -> AttributeSet
pub const fn get_disabled_attributes(self) -> AttributeSet
Return the disabled attributes
Sourcepub fn patch(self, other: Style) -> Style
pub fn patch(self, other: Style) -> Style
Combine two styles, applying the effects of other
after self
Sourcepub fn enable<A: Into<AttributeSet>>(self, attrs: A) -> Style
pub fn enable<A: Into<AttributeSet>>(self, attrs: A) -> Style
Enable the given attribute(s)
Sourcepub fn disable<A: Into<AttributeSet>>(self, attrs: A) -> Style
pub fn disable<A: Into<AttributeSet>>(self, attrs: A) -> Style
Disable the given attribute(s)
Sourcepub fn underline2(self) -> Style
pub fn underline2(self) -> Style
Enable double-underlining
Sourcepub fn not_italic(self) -> Style
pub fn not_italic(self) -> Style
Disable italic text
Sourcepub fn not_underline(self) -> Style
pub fn not_underline(self) -> Style
Disable underlining
Sourcepub fn not_blink2(self) -> Style
pub fn not_blink2(self) -> Style
Disable fast blinking
Sourcepub fn not_reverse(self) -> Style
pub fn not_reverse(self) -> Style
Disable reverse video
Sourcepub fn not_conceal(self) -> Style
pub fn not_conceal(self) -> Style
Disable concealed/hidden text
Sourcepub fn not_strike(self) -> Style
pub fn not_strike(self) -> Style
Disable strikethrough
Sourcepub fn not_underline2(self) -> Style
pub fn not_underline2(self) -> Style
Disable double-underlining
Sourcepub fn not_encircle(self) -> Style
pub fn not_encircle(self) -> Style
Disable encircled text
Sourcepub fn not_overline(self) -> Style
pub fn not_overline(self) -> Style
Disable overlining
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Style
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Style
serde
only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl From<AttributeSet> for Style
impl From<AttributeSet> for Style
Source§fn from(value: AttributeSet) -> Style
fn from(value: AttributeSet) -> Style
Construct a new Style
that enables the given attributes
Source§impl From<Attributes> for Style
Available on crate feature crossterm
only.
impl From<Attributes> for Style
crossterm
only.Source§fn from(value: Attributes) -> Style
fn from(value: Attributes) -> Style
Convert a crossterm::style::Attributes
to a Style
§Data Loss
The following attributes are discarded during conversion:
Source§impl From<ContentStyle> for Style
Available on crate feature crossterm
only.
impl From<ContentStyle> for Style
crossterm
only.Source§fn from(value: ContentStyle) -> Style
fn from(value: ContentStyle) -> Style
Convert a crossterm::style::ContentStyle
to a Style
§Data Loss
Underline color is discarded during conversion.
The following attributes are discarded during conversion:
Source§impl From<Style> for ContentStyle
Available on crate feature crossterm
only.
impl From<Style> for ContentStyle
crossterm
only.Source§fn from(value: Style) -> ContentStyle
fn from(value: Style) -> ContentStyle
Convert a Style
to a crossterm::style::ContentStyle
§Data Loss
Certain pairs of parse-style
attributes are disabled by a single
shared crossterm
attribute. Thus, when one element of a pair occurs
in the disabled attributes, the resulting ContentStyle
will disable
both elements of the pair.
The pairs are as follows:
-
Attribute::Bold
andAttribute::Dim
— both disabled bycrossterm::style::Attribute::NormalIntensity
-
Attribute::Blink
andAttribute::Blink2
— both disabled bycrossterm::style::Attribute::NoBlink
-
Attribute::Underline
andAttribute::Underline2
— both disabled bycrossterm::style::Attribute::NoUnderline
-
Attribute::Frame
andAttribute::Encircle
— both disabled bycrossterm::style::Attribute::NotFramedOrEncircled
Source§impl From<Style> for Style
Available on crate feature anstyle
only.
impl From<Style> for Style
anstyle
only.Source§fn from(value: Style) -> Style
fn from(value: Style) -> Style
Convert a Style
to an anstyle::Style
§Data Loss
If the Style
’s foreground or background color is Color::Default
,
it will be converted to None
.
The following attributes will be discarded during conversion:
- Attribute::Blink2
- Attribute::Frame
- Attribute::Encircle
- Attribute::Overline
Disabled attributes are discarded during conversion.
Source§impl From<Style> for Style
Available on crate feature anstyle
only.
impl From<Style> for Style
anstyle
only.Source§impl From<Style> for Style
Available on crate feature ratatui
only.
impl From<Style> for Style
ratatui
only.impl Copy for Style
impl Eq for Style
impl StructuralPartialEq for Style
Auto Trait Implementations§
impl Freeze for Style
impl RefUnwindSafe for Style
impl Send for Style
impl Sync for Style
impl Unpin for Style
impl UnwindSafe for Style
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()
Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString
. Read more