clap_utils/
traits.rs

1use crate::prelude::*;
2use std::io::Write;
3
4macro_rules! highlight_ext {
5    ($($name:ident), *) => {
6        $crate::paste! {
7            $(
8                #[doc=concat!("write highlighted ", stringify!($name), " to writer")]
9                fn [<highlight_ $name>](&mut self, text: &str) -> Result<(), Error> {
10                    self.highlight(text, stringify!($name), None)
11                }
12            )*
13        }
14    };
15}
16pub trait Highlight: Write {
17    /// write highlighted text to writer
18    fn highlight(&mut self, text: &str, extension: &str, theme: Option<&str>) -> Result<(), Error>;
19
20    fn highlight_ext(&mut self, text: &str, extension: &str) -> Result<(), Error> {
21        self.highlight(text, extension, None)
22    }
23
24    highlight_ext!(json, yaml, toml, xml, html, css, js, rs, py, rb, sh, md, txt);
25}