pub struct ColorMapping {
pub dark: Option<String>,
pub light: Option<String>,
}Available on crate feature
markdown-preview only.Expand description
Color mapping for light/dark modes.
This struct holds color names (not actual colors) that map to entries
in a ColorPalette. When resolving the actual color, the appropriate
variant (dark or light) is selected based on the current color scheme.
§Fields
dark- Color name to use in dark modelight- Color name to use in light mode
§Example
ⓘ
use ratatui_toolkit::markdown_widget::extensions::theme::{ColorMapping, ColorPalette, palettes};
// ColorMapping references color names, not actual RGB values
let mapping = ColorMapping {
dark: Some("blue".to_string()),
light: Some("oceanBlue".to_string()),
};
let palette = palettes::dark_default();
let color = mapping.get_color(&palette, true); // true = dark modeFields§
§dark: Option<String>Color name to use in dark mode.
light: Option<String>Color name to use in light mode.
Implementations§
Source§impl ColorMapping
impl ColorMapping
Sourcepub fn get_color(&self, palette: &ColorPalette, is_dark: bool) -> Color
pub fn get_color(&self, palette: &ColorPalette, is_dark: bool) -> Color
Get color for the specified color scheme.
Resolves the appropriate color name (dark or light) based on the
is_dark parameter, then looks up that color in the provided palette.
If the preferred variant (dark/light) is not set, falls back to the other variant.
If neither variant is set, returns Color::White.
§Arguments
palette- TheColorPaletteto look up color names inis_dark- Whether to use dark mode colors (true) or light mode colors (false)
§Returns
The resolved Color for the current color scheme.
§Example
ⓘ
use ratatui_toolkit::markdown_widget::extensions::theme::{ColorMapping, palettes};
let mapping = ColorMapping {
dark: Some("blue".to_string()),
light: Some("oceanBlue".to_string()),
};
let palette = palettes::dark_default();
// Get dark mode color
let dark_color = mapping.get_color(&palette, true);
// Get light mode color
let light_color = mapping.get_color(&palette, false);Trait Implementations§
Source§impl Clone for ColorMapping
impl Clone for ColorMapping
Source§fn clone(&self) -> ColorMapping
fn clone(&self) -> ColorMapping
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ColorMapping
impl Debug for ColorMapping
Source§impl<'de> Deserialize<'de> for ColorMapping
impl<'de> Deserialize<'de> for ColorMapping
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ColorMapping, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ColorMapping, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ColorMapping
impl RefUnwindSafe for ColorMapping
impl Send for ColorMapping
impl Sync for ColorMapping
impl Unpin for ColorMapping
impl UnsafeUnpin for ColorMapping
impl UnwindSafe for ColorMapping
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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 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>
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