kind_report/
lib.rs

1use report::Mode;
2use yansi::Paint;
3
4/// Data structures
5pub mod data;
6
7/// Render
8pub mod report;
9
10#[derive(Debug)]
11pub struct Chars {
12    pub vbar: char,
13    pub hbar: char,
14    pub dbar: char,
15    pub trline: char,
16    pub bxline: char,
17    pub brline: char,
18    pub ylline: char,
19    pub bullet: char,
20}
21
22impl Chars {
23    pub fn unicode() -> &'static Chars {
24        &Chars {
25            vbar: '│',
26            hbar: '─',
27            dbar: '┆',
28            trline: '└',
29            bxline: '┬',
30            brline: '┌',
31            ylline: '├',
32            bullet: '•',
33        }
34    }
35
36    pub fn ascii() -> &'static Chars {
37        &Chars {
38            vbar: '|',
39            hbar: '-',
40            dbar: ':',
41            trline: '\\',
42            bxline: 'v',
43            brline: '/',
44            ylline: '-',
45            bullet: '*',
46        }
47    }
48}
49
50#[derive(Debug)]
51pub struct RenderConfig<'a> {
52    pub chars: &'a Chars,
53    pub indent: usize,
54    pub hide_vals: bool,
55    pub mode: Mode,
56    pub not_align: bool,
57    pub only_main: bool,
58    pub show_immediate_deps: bool,
59}
60
61impl<'a> RenderConfig<'a> {
62    pub fn unicode(indent: usize, hide_vals: bool, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
63        RenderConfig {
64            chars: Chars::unicode(),
65            indent,
66            hide_vals,
67            mode: Mode::Classic,
68            not_align: false,
69            only_main,
70            show_immediate_deps
71        }
72    }
73
74    pub fn ascii(indent: usize, hide_vals: bool, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
75        RenderConfig {
76            chars: Chars::ascii(),
77            indent,
78            hide_vals,
79            mode: Mode::Classic,
80            not_align: false,
81            only_main,
82            show_immediate_deps
83        }
84    }
85
86    pub fn compact(indent: usize, only_main: bool, show_immediate_deps: bool) -> RenderConfig<'a> {
87        RenderConfig {
88            chars: Chars::ascii(),
89            indent,
90            hide_vals: true,
91            mode: Mode::Compact,
92            not_align: true,
93            only_main,
94            show_immediate_deps
95        }
96    }
97}
98
99pub fn check_if_colors_are_supported(disable: bool) {
100    if disable || (cfg!(windows) && !Paint::enable_windows_ascii()) {
101        Paint::disable();
102    }
103}
104
105pub 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> {
106    match mode {
107        Mode::Classic => {
108            if disable || (cfg!(windows) && !Paint::enable_windows_ascii()) {
109                RenderConfig::ascii(indent, hide_vals, only_main, show_immediate_deps)
110            } else {
111                RenderConfig::unicode(indent, hide_vals, only_main, show_immediate_deps)
112            }
113        },
114        Mode::Compact => RenderConfig::compact(0, only_main, show_immediate_deps),
115    }
116}