TermAttributes

Struct TermAttributes 

Source
pub struct TermAttributes {
    pub init_strategy: ColorInitStrategy,
    pub how_initialized: HowInitialized,
    pub color_support: ColorSupport,
    pub term_bg_hex: Option<String>,
    pub term_bg_rgb: Option<[u8; 3]>,
    pub term_bg_luma: TermBgLuma,
    pub theme: Theme,
}
Expand description

Manages terminal color attributes and styling based on terminal capabilities and theme The complete styling attributes for terminal output

Fields§

§init_strategy: ColorInitStrategy

The initialization strategy used

§how_initialized: HowInitialized

Indicates how the terminal attributes were initialized (configured, defaulted, or detected)

§color_support: ColorSupport

The level of color support available in the terminal

§term_bg_hex: Option<String>

The terminal background color as a hex string (e.g., “#1e1e1e”)

§term_bg_rgb: Option<[u8; 3]>

The terminal background color as RGB values (red, green, blue)

§term_bg_luma: TermBgLuma

The luminance (light/dark) of the terminal background

§theme: Theme

The theme used for styling text and interface elements

Implementations§

Source§

impl TermAttributes

Source

pub fn is_initialized() -> bool

Checks if TermAttributes has been initialized

Source

pub fn try_get() -> Option<&'static Self>

Attempts to get the TermAttributes instance, returning None if not initialized

Source

pub fn get_or_init() -> &'static Self

Gets the TermAttributes instance, initializing with auto-determined strategy if necessary.

This method uses ColorInitStrategy::determine() to automatically choose the best initialization strategy based on available features and environment.

If not already initialized:

  • With color_detect feature: performs auto-detection
  • Without color_detect: uses safe defaults
§Returns

Reference to the TermAttributes instance

§Panics

Panics if theme initialization fails

Source

pub fn with_context<F, R>(&self, f: F) -> R
where F: FnOnce() -> R,

Execute a closure with a temporary TermAttributes context This allows testing and temporary overrides without affecting the global state

Source

pub fn current() -> Self

Gets the current context, falling back to the global instance if no context is set

Source

pub fn try_initialize_with_strategy( strategy: &ColorInitStrategy, ) -> Result<&'static Self, String>

Initialize with a specific strategy, for testing and special cases

Returns Ok if successfully initialized or if already initialized with a compatible strategy. Returns Err if already initialized with an incompatible strategy.

§Arguments
  • strategy - The specific ColorInitStrategy to use
§Returns
  • Ok(&'static Self) - Reference to the TermAttributes instance
  • Err(String) - Error message if incompatible strategy already used
§Errors

This function will return an error if the instance is already initialized with an incompatible strategy..

Source

pub fn get_or_init_with_strategy(strategy: &ColorInitStrategy) -> &'static Self

Gets or initializes TermAttributes with the specified strategy

This method initializes TermAttributes with the given strategy if not already initialized, or returns the existing instance if already initialized (regardless of the original strategy).

This is the recommended method when you need a specific initialization strategy.

§Arguments
  • strategy - The ColorInitStrategy to use for initialization
§Returns

Reference to the TermAttributes instance

§Panics

Panics if theme initialization fails

Source

pub fn for_testing( color_support: ColorSupport, term_bg_rgb: Option<[u8; 3]>, term_bg_luma: TermBgLuma, theme: Theme, ) -> Self

Creates a new TermAttributes instance for testing purposes

Source

pub fn with_theme( self, theme_name: &str, support: ColorSupport, ) -> StylingResult<Self>

Updates the current theme to the specified built-in theme.

§Arguments
  • theme_name - Name of the built-in theme to use
§Returns

The updated TermAttributes instance

§Errors

Returns a ThemeError if:

  • The specified theme name is not recognized
  • The theme file is corrupted or invalid
  • The theme is incompatible with current terminal capabilities
  • Theme validation fails
Source

pub const fn with_color_support(self, support: ColorSupport) -> Self

Creates a new instance with the specified color support level

§Arguments
  • support - The color support level to set
§Returns

A new TermAttributes instance with the updated color support

Trait Implementations§

Source§

impl Clone for TermAttributes

Source§

fn clone(&self) -> TermAttributes

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TermAttributes

Source§

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

Formats the value using the given formatter. Read more

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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.