pub struct Style { /* private fields */ }Expand description
A style consisting of foreground and background color.
No text modifiers (bold, italic, underline, etc.) by design – retroglyph is a spiritual
remake of BearLibTerminal, which doesn’t support them either. A pixel/bitmap-font renderer
can’t fake most of them (no bold font variant, no underline stroke) without real per-style
assets, so rather than have them work in a real terminal and silently do nothing in the
software backend, they’re not part of the API at all. Color and glyph choice are the only two
knobs, in every backend.
Implementations§
Source§impl Style
impl Style
Sourcepub const fn foreground(&self) -> Color
pub const fn foreground(&self) -> Color
Returns the foreground color.
Sourcepub const fn background(&self) -> Color
pub const fn background(&self) -> Color
Returns the background color.
Sourcepub fn patch(self, other: Self) -> Self
pub fn patch(self, other: Self) -> Self
Overlays another style onto this one, only if fields in other are non-default.
Color::Default in other means “unset”, not “reset to default”: a field left at
Color::Default is skipped, and self’s existing value for that field is kept. This
mirrors ratatui’s Style::patch convention, so Style::new().fg(Color::Default) is a
no-op when patched onto anything, and there is no way to use patch to explicitly clear a
field back to Color::Default – use Style::reset_fg or Style::reset_bg for that.
use retroglyph_core::{Color, Style};
let base = Style::new().fg(Color::RED).bg(Color::BLUE);
// Patching with a default `fg` leaves `base`'s red foreground untouched.
let patched = base.patch(Style::new().bg(Color::GREEN));
assert_eq!(patched.foreground(), Color::RED);
assert_eq!(patched.background(), Color::GREEN);Sourcepub const fn reset_fg(self) -> Self
pub const fn reset_fg(self) -> Self
Resets the foreground color to Color::Default.
Unlike Style::patch, which treats Color::Default as “leave unset”, this explicitly
clears the field. Use this when a caller needs to undo a previously patched-in foreground
color rather than merge in a new one.
Sourcepub const fn reset_bg(self) -> Self
pub const fn reset_bg(self) -> Self
Resets the background color to Color::Default.
Unlike Style::patch, which treats Color::Default as “leave unset”, this explicitly
clears the field. Use this when a caller needs to undo a previously patched-in background
color rather than merge in a new one.