Enum Attribute
#[non_exhaustive]pub enum Attribute {
Show 28 variants
Reset,
Bold,
Dim,
Italic,
Underlined,
DoubleUnderlined,
Undercurled,
Underdotted,
Underdashed,
SlowBlink,
RapidBlink,
Reverse,
Hidden,
CrossedOut,
Fraktur,
NoBold,
NormalIntensity,
NoItalic,
NoUnderline,
NoBlink,
NoReverse,
NoHidden,
NotCrossedOut,
Framed,
Encircled,
OverLined,
NotFramedOrEncircled,
NotOverLined,
}
dep_crossterm
and std
only.Expand description
Represents an attribute.
§Platform-specific Notes
- Only UNIX and Windows 10 terminals do support text attributes.
- Keep in mind that not all terminals support all attributes.
- Crossterm implements almost all attributes listed in the SGR parameters.
Attribute | Windows | UNIX | Notes |
---|---|---|---|
Reset | ✓ | ✓ | |
Bold | ✓ | ✓ | |
Dim | ✓ | ✓ | |
Italic | ? | ? | Not widely supported, sometimes treated as inverse. |
Underlined | ✓ | ✓ | |
SlowBlink | ? | ? | Not widely supported, sometimes treated as inverse. |
RapidBlink | ? | ? | Not widely supported. MS-DOS ANSI.SYS; 150+ per minute. |
Reverse | ✓ | ✓ | |
Hidden | ✓ | ✓ | Also known as Conceal. |
Fraktur | ✗ | ✓ | Legible characters, but marked for deletion. |
DefaultForegroundColor | ? | ? | Implementation specific (according to standard). |
DefaultBackgroundColor | ? | ? | Implementation specific (according to standard). |
Framed | ? | ? | Not widely supported. |
Encircled | ? | ? | This should turn on the encircled attribute. |
OverLined | ? | ? | This should draw a line at the top of the text. |
§Examples
Basic usage:
use crossterm::style::Attribute;
println!(
"{} Underlined {} No Underline",
Attribute::Underlined,
Attribute::NoUnderline
);
Style existing text:
use crossterm::style::Stylize;
println!("{}", "Bold text".bold());
println!("{}", "Underlined text".underlined());
println!("{}", "Negative text".negative());
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Reset
Resets all the attributes.
Bold
Increases the text intensity.
Dim
Decreases the text intensity.
Italic
Emphasises the text.
Underlined
Underlines the text.
DoubleUnderlined
Double underlines the text.
Undercurled
Undercurls the text.
Underdotted
Underdots the text.
Underdashed
Underdashes the text.
SlowBlink
Makes the text blinking (< 150 per minute).
RapidBlink
Makes the text blinking (>= 150 per minute).
Reverse
Swaps foreground and background colors.
Hidden
Hides the text (also known as Conceal).
CrossedOut
Crosses the text.
Fraktur
Sets the Fraktur typeface.
Mostly used for mathematical alphanumeric symbols.
NoBold
Turns off the Bold
attribute. - Inconsistent - Prefer to use NormalIntensity
NormalIntensity
Switches the text back to normal intensity (no bold, italic).
NoItalic
Turns off the Italic
attribute.
NoUnderline
Turns off the Underlined
attribute.
NoBlink
Turns off the text blinking (SlowBlink
or RapidBlink
).
NoReverse
Turns off the Reverse
attribute.
NoHidden
Turns off the Hidden
attribute.
NotCrossedOut
Turns off the CrossedOut
attribute.
Framed
Makes the text framed.
Encircled
Makes the text encircled.
OverLined
Draws a line at the top of the text.
NotFramedOrEncircled
Turns off the Frame
and Encircled
attributes.
NotOverLined
Turns off the OverLined
attribute.
Implementations§
§impl Attribute
impl Attribute
pub const fn bytes(self) -> u32 ⓘ
pub const fn bytes(self) -> u32 ⓘ
Returns a u32 with one bit set, which is the signature of this attribute in the Attributes bitset.
The +1 enables storing Reset (whose index is 0) in the bitset Attributes.
pub fn sgr(self) -> String ⓘ
pub fn sgr(self) -> String ⓘ
Returns the SGR attribute value.
See https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
Trait Implementations§
§impl BitAnd<Attribute> for Attributes
impl BitAnd<Attribute> for Attributes
§type Output = Attributes
type Output = Attributes
&
operator.§fn bitand(self, rhs: Attribute) -> Attributes
fn bitand(self, rhs: Attribute) -> Attributes
&
operation. Read more§impl BitOr<Attribute> for Attributes
impl BitOr<Attribute> for Attributes
§type Output = Attributes
type Output = Attributes
|
operator.§fn bitor(self, rhs: Attribute) -> Attributes
fn bitor(self, rhs: Attribute) -> Attributes
|
operation. Read more§impl BitXor<Attribute> for Attributes
impl BitXor<Attribute> for Attributes
§type Output = Attributes
type Output = Attributes
^
operator.§fn bitxor(self, rhs: Attribute) -> Attributes
fn bitxor(self, rhs: Attribute) -> Attributes
^
operation. Read more§impl From<Attribute> for Attributes
impl From<Attribute> for Attributes
§fn from(attribute: Attribute) -> Attributes
fn from(attribute: Attribute) -> Attributes
§impl Ord for Attribute
impl Ord for Attribute
§impl PartialOrd for Attribute
impl PartialOrd for Attribute
impl Copy for Attribute
impl Eq for Attribute
impl StructuralPartialEq for Attribute
Auto Trait Implementations§
impl Freeze for Attribute
impl RefUnwindSafe for Attribute
impl Send for Attribute
impl Sync for Attribute
impl Unpin for Attribute
impl UnwindSafe for Attribute
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.