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
105
106
107
108
109
110
111
112
113
114
115
116
use report::Mode;
use yansi::Paint;

/// Data structures
pub mod data;

/// Render
pub mod report;

#[derive(Debug)]
pub struct Chars {
    pub vbar: char,
    pub hbar: char,
    pub dbar: char,
    pub trline: char,
    pub bxline: char,
    pub brline: char,
    pub ylline: char,
    pub bullet: char,
}

impl Chars {
    pub fn unicode() -> &'static Chars {
        &Chars {
            vbar: '│',
            hbar: '─',
            dbar: '┆',
            trline: '└',
            bxline: '┬',
            brline: '┌',
            ylline: '├',
            bullet: '•',
        }
    }

    pub fn ascii() -> &'static Chars {
        &Chars {
            vbar: '|',
            hbar: '-',
            dbar: ':',
            trline: '\\',
            bxline: 'v',
            brline: '/',
            ylline: '-',
            bullet: '*',
        }
    }
}

#[derive(Debug)]
pub struct RenderConfig<'a> {
    pub chars: &'a Chars,
    pub indent: usize,
    pub hide_vals: bool,
    pub mode: Mode,
    pub not_align: bool,
    pub only_main: bool,
    pub show_immediate_deps: bool,
}

impl<'a> RenderConfig<'a> {
    pub fn unicode(indent: usize, hide_vals: bool, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
        RenderConfig {
            chars: Chars::unicode(),
            indent,
            hide_vals,
            mode: Mode::Classic,
            not_align: false,
            only_main,
            show_immediate_deps
        }
    }

    pub fn ascii(indent: usize, hide_vals: bool, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
        RenderConfig {
            chars: Chars::ascii(),
            indent,
            hide_vals,
            mode: Mode::Classic,
            not_align: false,
            only_main,
            show_immediate_deps
        }
    }

    pub fn compact(indent: usize, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
        RenderConfig {
            chars: Chars::ascii(),
            indent,
            hide_vals: true,
            mode: Mode::Compact,
            not_align: true,
            only_main,
            show_immediate_deps
        }
    }
}

pub fn check_if_colors_are_supported(disable: bool) {
    if disable || (cfg!(windows) && !Paint::enable_windows_ascii()) {
        Paint::disable();
    }
}

pub fn check_if_utf8_is_supported<'a>(disable: bool, indent: usize, hide_vals: bool, mode: Mode, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
    match mode {
        Mode::Classic => {
            if disable || (cfg!(windows) && !Paint::enable_windows_ascii()) {
                RenderConfig::ascii(indent, hide_vals, only_main, show_immediate_deps)
            } else {
                RenderConfig::unicode(indent, hide_vals, only_main, show_immediate_deps)
            }
        },
        Mode::Compact => RenderConfig::compact(0, only_main, show_immediate_deps),
    }
}