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: ColorInitStrategyThe initialization strategy used
how_initialized: HowInitializedIndicates how the terminal attributes were initialized (configured, defaulted, or detected)
color_support: ColorSupportThe 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: TermBgLumaThe luminance (light/dark) of the terminal background
theme: ThemeThe theme used for styling text and interface elements
Implementations§
Source§impl TermAttributes
impl TermAttributes
Sourcepub fn is_initialized() -> bool
pub fn is_initialized() -> bool
Checks if TermAttributes has been initialized
Sourcepub fn try_get() -> Option<&'static Self>
pub fn try_get() -> Option<&'static Self>
Attempts to get the TermAttributes instance, returning None if not initialized
Sourcepub fn get_or_init() -> &'static Self
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_detectfeature: performs auto-detection - Without
color_detect: uses safe defaults
§Returns
Reference to the TermAttributes instance
§Panics
Panics if theme initialization fails
Sourcepub fn with_context<F, R>(&self, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn with_context<F, R>(&self, f: F) -> Rwhere
F: FnOnce() -> R,
Execute a closure with a temporary TermAttributes context
This allows testing and temporary overrides without affecting the global state
Sourcepub fn current() -> Self
pub fn current() -> Self
Gets the current context, falling back to the global instance if no context is set
Sourcepub fn try_initialize_with_strategy(
strategy: &ColorInitStrategy,
) -> Result<&'static Self, String>
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 specificColorInitStrategyto use
§Returns
Ok(&'static Self)- Reference to theTermAttributesinstanceErr(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..
Sourcepub fn get_or_init_with_strategy(strategy: &ColorInitStrategy) -> &'static Self
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- TheColorInitStrategyto use for initialization
§Returns
Reference to the TermAttributes instance
§Panics
Panics if theme initialization fails
Sourcepub fn for_testing(
color_support: ColorSupport,
term_bg_rgb: Option<[u8; 3]>,
term_bg_luma: TermBgLuma,
theme: Theme,
) -> Self
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
Sourcepub fn with_theme(
self,
theme_name: &str,
support: ColorSupport,
) -> StylingResult<Self>
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
Sourcepub const fn with_color_support(self, support: ColorSupport) -> Self
pub const fn with_color_support(self, support: ColorSupport) -> Self
Trait Implementations§
Source§impl Clone for TermAttributes
impl Clone for TermAttributes
Source§fn clone(&self) -> TermAttributes
fn clone(&self) -> TermAttributes
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TermAttributes
impl RefUnwindSafe for TermAttributes
impl Send for TermAttributes
impl Sync for TermAttributes
impl Unpin for TermAttributes
impl UnwindSafe for TermAttributes
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<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