From 41fd5a5b2a6b50a238f9e7f8caa560fa60db4d95 Mon Sep 17 00:00:00 2001 From: Pierre Peltier Date: Thu, 24 Oct 2019 17:55:05 +0200 Subject: Use the term_grid package for the output of tree --- src/display.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/display.rs b/src/display.rs index 9cd90ee..db232fa 100644 --- a/src/display.rs +++ b/src/display.rs @@ -129,9 +129,23 @@ fn inner_display_tree( let mut grid = Grid::new(GridOptions { filling: Filling::Spaces(2), - direction: Direction::TopToBottom, + direction: Direction::LeftToRight, }); + for meta in metas.into_iter() { + for block in get_output(&meta, &colors, &icons, &flags, &padding_rules) { + let block_str = block.to_string(); + + grid.add(Cell { + width: get_visible_width(&block_str), + contents: block_str, + }); + } + } + + let content = grid.fit_into_columns(flags.blocks.len()).to_string(); + let mut lines = content.lines(); + for (idx, meta) in metas.into_iter().enumerate() { let is_last_folder_elem = idx + 1 != last_idx; @@ -146,14 +160,8 @@ fn inner_display_tree( output += " "; } - for block in get_output(&meta, &colors, &icons, &flags, &padding_rules) { - let block_str = block.to_string(); - - grid.add(Cell { - width: get_visible_width(&block_str), - contents: block_str, - }); - } + output += lines.next().unwrap().clone(); + output += "\n"; if meta.content.is_some() { let mut new_prefix = String::from(prefix); -- cgit v1.2.3