Skip to content

Commit

Permalink
tree indent
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Nov 20, 2023
1 parent 74fdb7a commit 429ed05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions examples/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use promkit::{error::Result, preset::Tree, tree::Node};

fn main() -> Result {
let mut p = Tree::new(Node::new("/").add_children([
Node::new("a").add_children([Node::new("aa"), Node::new("ab")]),
Node::new("b"),
Node::new("c"),
Node::new("foo").add_children([Node::new("test1.txt"), Node::new("test2.txt")]),
Node::new("bar"),
Node::new("baz"),
]))
.title("What number do you like?")
.title("Select a directory or file")
.lines(10)
.prompt()?;
println!("result: {:?}", p.run()?);
Expand Down
5 changes: 3 additions & 2 deletions src/components/tree_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ impl TreeViewer {
.map(|(i, item)| {
if i == self.tree.position {
Graphemes::new_with_style(
format!("{}{}", self.cursor, item.data),
format!("{}{}{}", self.cursor, " ".repeat(item.depth), item.data),
self.cursor_style,
)
} else {
Graphemes::new_with_style(
format!(
"{}{}",
"{}{}{}",
" ".repeat(Graphemes::new(self.cursor.clone()).widths()),
" ".repeat(item.depth),
item.data
),
self.style,
Expand Down

0 comments on commit 429ed05

Please sign in to comment.