pub struct Theme {
pub name: String,
pub is_dark: bool,
pub source_url: Option<String>,
pub background: Option<Color>,
pub foreground: Option<Color>,
pub styles: [Style; 73],
}Expand description
A complete syntax highlighting theme.
Fields§
§name: StringTheme name for display.
is_dark: boolWhether this is a dark or light theme.
source_url: Option<String>URL to the original theme source (for attribution).
background: Option<Color>Background color for the code block.
foreground: Option<Color>Foreground (default text) color.
styles: [Style; 73]Styles for each highlight category, indexed by HIGHLIGHT_NAMES.
Implementations§
Source§impl Theme
impl Theme
Sourcepub const ANSI_RESET: &'static str = "\x1b[0m"
pub const ANSI_RESET: &'static str = "\x1b[0m"
ANSI reset sequence.
Sourcepub fn to_css(&self, selector_prefix: &str) -> String
pub fn to_css(&self, selector_prefix: &str) -> String
Generate CSS for this theme.
Uses CSS nesting for compact output. The selector_prefix is prepended
to scope the rules (e.g., [data-theme="mocha"]).
Sourcepub fn ansi_style(&self, index: usize) -> String
pub fn ansi_style(&self, index: usize) -> String
Generate ANSI escape sequence for a style.
Sourcepub fn ansi_style_with_base_bg(&self, index: usize) -> String
pub fn ansi_style_with_base_bg(&self, index: usize) -> String
Generate ANSI escape sequence for a style, inheriting base foreground/background if not set.
When rendering with a base background color, we want individual styles to inherit that background unless they explicitly override it. Similarly, if a style doesn’t define a foreground, use the base foreground. This avoids the background disappearing when switching between styled and unstyled text, and ensures colors are complete.
Sourcepub fn ansi_base_style(&self) -> String
pub fn ansi_base_style(&self) -> String
Generate ANSI escape sequence for the theme’s base foreground/background.
This uses background and foreground and does not include any
per-highlight styling or text modifiers.
Sourcepub fn ansi_border_style(&self) -> String
pub fn ansi_border_style(&self) -> String
Generate ANSI escape sequence for border characters (half-blocks).
Returns fg color only (no bg), slightly darker/lighter than theme background. The transparent half of the half-block char shows the terminal background.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Theme
impl RefUnwindSafe for Theme
impl Send for Theme
impl Sync for Theme
impl Unpin for Theme
impl UnwindSafe for Theme
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)