tree-mumu 0.1.0-rc.2

Creates Linux `tree`-style renderings of MuMu values
Documentation
// src/share/glyphs.rs
//
// Branch glyphs and indentation helpers for Linux `tree`-style rendering.

#[derive(Clone, Copy, Debug)]
pub struct GlyphSet {
    /// Middle-child connector, e.g. "├── "
    pub tee: &'static str,
    /// Last-child connector, e.g. "└── "
    pub last: &'static str,
    /// Vertical guide for parent levels, e.g. "│   "
    pub pipe: &'static str,
    /// Empty spacing where a parent ended, e.g. "    "
    pub space: &'static str,
}

pub const UTF: GlyphSet = GlyphSet {
    tee: "├── ",
    last: "└── ",
    pipe: "",
    space: "    ",
};

pub const ASCII: GlyphSet = GlyphSet {
    tee: "+-- ",
    last: "\\-- ",
    pipe: "|   ",
    space: "    ",
};

/// Build the indentation prefix for all ancestor levels.
/// `ancestors_more` has one entry per ancestor depth: true means there are
/// siblings *after* that ancestor (draw `pipe`), false means it was the last
/// child (draw `space`).
pub fn indent_prefix(ancestors_more: &[bool], g: &GlyphSet) -> String {
    let mut s = String::new();
    for &more in ancestors_more {
        if more {
            s.push_str(g.pipe);
        } else {
            s.push_str(g.space);
        }
    }
    s
}

/// Return the connector for the current entry depending on whether it is the last child.
pub fn head(is_last: bool, g: &GlyphSet) -> &'static str {
    if is_last { g.last } else { g.tee }
}