i3status_rs/formatting/formatter/
pango.rs

1use super::*;
2
3#[derive(Debug)]
4pub struct PangoStrFormatter;
5
6impl PangoStrFormatter {
7    pub(super) fn from_args(args: &[Arg]) -> Result<Self> {
8        if let Some(arg) = args.first() {
9            return Err(Error::new(format!(
10                "Unknown argument for 'pango-str': '{}'",
11                arg.key
12            )));
13        }
14        Ok(Self)
15    }
16}
17
18impl Formatter for PangoStrFormatter {
19    fn format(&self, val: &Value, config: &SharedConfig) -> Result<String, FormatError> {
20        match val {
21            Value::Text(x) => Ok(x.clone()), // No escaping
22            Value::Icon(icon, value) => config.get_icon(icon, *value).map_err(Into::into),
23            other => Err(FormatError::IncompatibleFormatter {
24                ty: other.type_name(),
25                fmt: "pango-str",
26            }),
27        }
28    }
29}