aboutsummaryrefslogtreecommitdiffstats
path: root/src/render.rs
blob: 71f538a72a50650409737a28509432df16fa32df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::{collections::BTreeMap, sync::Arc};

use ansi_term::Style;

use crate::{config::FormattedPart, widgets::widget::Widget, ZellijState};

pub fn formatting(part: FormattedPart, text: String) -> String {
    let mut style = match part.fg {
        Some(color) => Style::new().fg(color),
        None => Style::new(),
    };

    style.background = part.bg;
    style.is_italic = part.italic;
    style.is_bold = part.bold;

    let style = style.paint(text);

    format!("{}", style)
}

pub fn widgets_and_formatting(
    part: FormattedPart,
    widgets: BTreeMap<String, Arc<dyn Widget>>,
    state: ZellijState,
) -> String {
    let mut output = part.content.clone();

    if output.contains("{mode}") {
        let result = match widgets.get("mode") {
            Some(widget) => widget.process(state.clone()),
            None => "Use of uninitialized widget".to_string(),
        };

        output = output.replace("{mode}", &result);
    }

    if output.contains("{tabs}") {
        let result = match widgets.get("tabs") {
            Some(widget) => widget.process(state),
            None => "Use of uninitialized widget".to_string(),
        };

        output = output.replace("{tabs}", &result);
    }

    formatting(part, output)
}