Skip to main content

fancy_tree/tree/
charset.rs

1//! Module for collections of `char`s.
2
3/// Provides text used for generating a tree. Could be considered the "branches" of the
4/// tree.
5///
6/// When implementing this, ideally `depth`, `breadth`, and `indent` should all be the
7/// same visual length.
8#[non_exhaustive]
9pub struct Charset<'a> {
10    /// The text to print when traveling deeper into the directory structure.
11    ///
12    /// Typically should resemble a horizontal line.
13    pub depth: &'a str,
14    /// The text to print when traversing the breadth of a directory.
15    ///
16    /// Typically a vertical line. Also helps control padding between branches.
17    pub breadth: &'a str,
18    /// The text to use to indent tree branches with each level.
19    pub indent: &'a str,
20}
21
22const EMPTY_TEXT: &str = "    ";
23
24impl<'a> Charset<'a> {
25    /// The standard charset. Pretty characters, but not too fancy.
26    pub const STANDARD: Self = Self {
27        depth: "├── ",
28        // NOTE U+00A0 is a non-breaking space
29        breadth: "│\u{00A0}\u{00A0} ",
30        indent: "    ",
31    };
32
33    /// Empty charset. The tree is invisible.
34    pub const EMPTY: Self = Self {
35        depth: EMPTY_TEXT,
36        breadth: EMPTY_TEXT,
37        indent: EMPTY_TEXT,
38    };
39}
40
41impl<'a> Default for Charset<'a> {
42    #[inline]
43    fn default() -> Self {
44        Charset::STANDARD
45    }
46}