diagnostic/characters/mod.rs
1/// Possible character sets to use when rendering diagnostics.
2#[derive(Copy, Clone, Debug, PartialEq, Eq)]
3pub enum BuiltinDrawer {
4 /// Unicode characters (an attempt is made to use only commonly-supported characters).
5 Unicode,
6 /// ASCII-only characters.
7 Ascii,
8}
9
10/// A trait for types that can be used to draw diagnostics.
11pub trait Draw {
12 /// Get the character set to use when rendering diagnostics.
13 fn get_elements(&self) -> DrawElements;
14}
15
16impl Draw for BuiltinDrawer {
17 fn get_elements(&self) -> DrawElements {
18 match self {
19 BuiltinDrawer::Unicode => DrawElements {
20 hbar: '─',
21 vbar: '│',
22 xbar: '┼',
23 vbar_break: '┆',
24 vbar_gap: '┆',
25 uarrow: '🭯',
26 rarrow: '▶',
27 ltop: '╭',
28 mtop: '┬',
29 rtop: '╮',
30 lbot: '╰',
31 mbot: '┴',
32 rbot: '╯',
33 lbox: '[',
34 rbox: ']',
35 lcross: '├',
36 rcross: '┤',
37 underbar: '┬',
38 underline: '─',
39 },
40 BuiltinDrawer::Ascii => DrawElements {
41 hbar: '-',
42 vbar: '|',
43 xbar: '+',
44 vbar_break: '*',
45 vbar_gap: ':',
46 uarrow: '^',
47 rarrow: '>',
48 ltop: ',',
49 mtop: 'v',
50 rtop: '.',
51 lbot: '`',
52 mbot: '^',
53 rbot: '\'',
54 lbox: '[',
55 rbox: ']',
56 lcross: '|',
57 rcross: '|',
58 underbar: '|',
59 underline: '^',
60 },
61 }
62 }
63}
64
65/// The character set used by formatter
66#[allow(missing_docs)]
67#[derive(Copy, Clone, Debug, PartialEq, Eq)]
68pub struct DrawElements {
69 /// Horizontal bar, eg: `─, -`
70 pub hbar: char,
71 /// Vertical bar, eg: `│, |`
72 pub vbar: char,
73 /// Cross bar, eg: `┼, +`
74 pub xbar: char,
75 /// Vertical bar break, eg: `┆, *`
76 pub vbar_break: char,
77 /// Vertical bar gap, eg: `┆, :`
78 pub vbar_gap: char,
79 /// Up arrow, eg: `🭯, ^`
80 pub uarrow: char,
81 /// Right arrow, eg: `▶, >`
82 pub rarrow: char,
83 /// Left top corner, eg: `╭, ,`
84 pub ltop: char,
85 /// Middle top, eg: `┬, v`
86 pub mtop: char,
87 /// Right top corner, eg: `╮, .`
88 pub rtop: char,
89 /// Left bottom corner, eg: `╰, ``
90 pub lbot: char,
91 /// Middle bottom, eg: `┴, ^`
92 pub rbot: char,
93 /// Right bottom corner, eg: `╯, '`
94 pub mbot: char,
95 /// Left box, eg: `[`
96 pub lbox: char,
97 /// Right box, eg: `]`
98 pub rbox: char,
99 /// Left cross, eg: `├, |`
100 pub lcross: char,
101 /// Right cross, eg: `┤, |`
102 pub rcross: char,
103 /// Under bar, eg: `┬, |`
104 pub underbar: char,
105 /// Underline, eg: `─, ^`
106 pub underline: char,
107}