Function default_indenter

Source
pub fn default_indenter(children: &dyn Children, index: usize) -> String
Expand description

Default tree indenter for nested content and multiline text.

This indenter creates the visual connection lines for nested tree content. It uses a vertical line (│) with spaces for continuing branches and plain spaces for content under the last child. The spacing is carefully calculated to align with the default enumerator characters.

§Arguments

  • children - The children collection being indented
  • index - The zero-based index of the current child

§Returns

“│ “ (vertical line + 3 spaces) for continuing branches, “ “ (4 spaces) for content under the last child

§Output Example

├── Foo
├── Bar
│   ├── Qux
│   ├── Quux
│   │   ├── Foo
│   │   └── Bar
│   └── Quuux
└── Baz

§Examples

use lipgloss_tree::{default_indenter, new_string_data};

let children = new_string_data(&["Foo", "Bar", "Baz"]);
assert_eq!(default_indenter(&children, 0), "│   ");   // Continuing branch
assert_eq!(default_indenter(&children, 1), "│   ");   // Continuing branch
assert_eq!(default_indenter(&children, 2), "    ");   // Last child (spaces only)

§Design Notes

The spacing is designed to align with standard enumerator widths:

  • “├── “ is 4 characters wide
  • “└── “ is 4 characters wide
  • “│ “ provides continuing vertical line + 3 spaces = 4 total
  • “ “ provides 4 spaces for clean termination