encre_css/plugins/interactivity/caret_color/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias = "interactivity")]
3use crate::prelude::build_plugin::*;
4
5#[derive(Debug)]
6pub(crate) struct PluginDefinition;
7
8impl Plugin for PluginDefinition {
9    fn can_handle(&self, context: ContextCanHandle) -> bool {
10        match context.modifier {
11            Modifier::Builtin { value, .. } => {
12                color::is_matching_builtin_color(context.config, value)
13            }
14            Modifier::Arbitrary { hint, value, .. } => {
15                *hint == "color" || (hint.is_empty() && is_matching_color(value))
16            }
17        }
18    }
19
20    fn handle(&self, context: &mut ContextHandle) {
21        match context.modifier {
22            Modifier::Builtin { value, .. } => context.buffer.line(format_args!(
23                "caret-color: {};",
24                color::get(context.config, value).unwrap()
25            )),
26            Modifier::Arbitrary { value, .. } => {
27                context.buffer.line(format_args!("caret-color: {value};"));
28            }
29        }
30    }
31}