summaryrefslogtreecommitdiffstats
path: root/src/mad_skin.rs
blob: 52dc8e06bb995b64bac3753718efa0746ccb48cb (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/// This module builds Termimad `MadSkin` from Broot `Skin`

use {
    crate::{
        skin::Skin,
    },
    crossterm::{
        style::Color,
    },
    termimad::{
        Alignment,
        CompoundStyle,
        LineStyle,
        gray,
        MadSkin,
    },
};

/// the mad skin applying to the status depending whether it's an
/// error or not
pub struct StatusMadSkinSet {
    pub normal: MadSkin,
    pub error: MadSkin,
}

/// build a MadSkin which will be used to display the status
/// when there's no error
fn make_normal_status_mad_skin(skin: &Skin) -> MadSkin {
    let mut mad_skin = MadSkin::default();
    mad_skin.paragraph = LineStyle {
        compound_style: skin.status_normal.clone(),
        align: Alignment::Left,
    };
    mad_skin.italic = skin.status_italic.clone();
    mad_skin.bold = skin.status_bold.clone();
    mad_skin.inline_code = skin.status_code.clone();
    mad_skin.ellipsis = skin.status_ellipsis.clone();
    mad_skin
}

/// build a MadSkin which will be used to display the status
/// when there's a error
fn make_error_status_mad_skin(skin: &Skin) -> MadSkin {
    let mut mad_skin = MadSkin::default();
    mad_skin.paragraph = LineStyle {
        compound_style: skin.status_error.clone(),
        align: Alignment::Left,
    };
    mad_skin.ellipsis = skin.status_ellipsis.clone();
    mad_skin
}

impl StatusMadSkinSet {
    pub fn from_skin(skin: &Skin) -> Self {
        Self {
            normal: make_normal_status_mad_skin(skin),
            error: make_error_status_mad_skin(skin),
        }
    }
}

/// build a MadSkin, which will be used for markdown formatting
/// for the help screen by applying the `help_*` entries
/// of the skin.
pub fn make_help_mad_skin(skin: &Skin) -> MadSkin {
    let mut ms = MadSkin::default();
    ms.paragraph.compound_style = CompoundStyle::from(skin.help_paragraph.clone());
    ms.inline_code = CompoundStyle::from(skin.help_code.clone());
    ms.code_block.compound_style = ms.inline_code.clone();
    ms.bold = CompoundStyle::from(skin.help_bold.clone());
    ms.italic = CompoundStyle::from(skin.help_italic.clone());
    ms.table = LineStyle {
        compound_style: CompoundStyle::from(skin.help_table_border.clone()),
        align: Alignment::Center,
    };
    if let Some(c) = skin.help_headers.get_fg() {
        ms.set_headers_fg(c);
    }
    if let Some(c) = skin.help_headers.get_bg() {
        ms.set_headers_bg(c);
    }
    ms.bullet.set_compound_style(ms.paragraph.compound_style.clone());
    ms.scrollbar
        .track
        .set_compound_style(CompoundStyle::from(skin.scrollbar_track.clone()));
    ms.scrollbar
        .thumb
        .set_compound_style(CompoundStyle::from(skin.scrollbar_thumb.clone()));
    ms
}

/// build a termimad skin for cli output (mostly
/// for the install process)
pub fn make_cli_mad_skin() -> MadSkin {
    let mut skin = MadSkin::default();
    skin.set_headers_fg(Color::AnsiValue(178));
    skin.bold.set_fg(gray(12));
    skin.inline_code.set_bg(gray(2));
    skin.inline_code.set_fg(gray(18));
    skin.code_block.set_bg(gray(2));
    skin.code_block.set_fg(gray(18));
    skin.italic.set_fg(Color::Magenta);
    skin
}