Macro syntastica::theme

macro_rules! theme {
    ($($tt:tt)*) => { ... };
}
Expand description

Convenience macro for constructing new Themes.

Currently, the macro is very strict about the input’s structure. See the example below to learn more. Also note that for extended values, either color or link must be set, or any call to resolve_links will fail.

See the documentation for Theme and ResolvedTheme for more information on themes.

Example

use std::collections::BTreeMap;
use syntastica_core::{
    theme,
    theme::{Theme, ThemeValue},
};

let theme = theme! {
    // specify colors using hex literals
    "purple": "#c678dd",
    "blue": "#61afef",
    "green": "#98c379",

    // link to other keys using a `$` sign
    "keyword": "$purple",
    "function": "$blue",

    // specify more styling options in curly braces
    // (note that currently this order required by the macro)
    "string": {
        color: None, // either `None` or `"#<color>"`
        bg: None, // either `None` or `"#<color>"`
        underline: false,
        strikethrough: false,
        italic: true,
        bold: false,
        link: "green", // either `None` or `"<key>"`
    },
};

assert_eq!(theme, Theme::new(BTreeMap::from([
    ("purple".to_owned(), ThemeValue::Simple("#c678dd".to_owned())),
    ("blue".to_owned(), ThemeValue::Simple("#61afef".to_owned())),
    ("green".to_owned(), ThemeValue::Simple("#98c379".to_owned())),
    ("keyword".to_owned(), ThemeValue::Simple("$purple".to_owned())),
    ("function".to_owned(), ThemeValue::Simple("$blue".to_owned())),
    ("string".to_owned(), ThemeValue::Extended {
        color: None,
        bg: None,
        underline: false,
        strikethrough: false,
        italic: true,
        bold: false,
        link: Some("green".to_owned()),
    }),
])));