Browse Source

fix(tree-view): Ensure nested tree parts align under item name

Before:
```
foo/
├── nested/
│  ├── bar
│  └── other-bar
└── baz
```
Notice how the nested tree is aligned on the blank before the dir name

After:
```
foo/
├── nested/
│   ├── bar
│   └── other-bar
└── baz
```
Now the nested tree is aligned on the dir name, making it much nicer to
look at and more logical.
Benoit de Chezelles 1 year ago
parent
commit
688308824d
4 changed files with 44 additions and 60 deletions
  1. 0 12
      src/output/details.rs
  2. 13 17
      src/output/tree.rs
  3. 17 17
      tests/cmd/follow-symlinks_unix.stdout
  4. 14 14
      tests/cmd/tree_unix.stdout

+ 0 - 12
src/output/details.rs

@@ -505,12 +505,6 @@ impl<'a> Iterator for TableIter<'a> {
                 cell.push(self.tree_style.paint(tree_part.ascii_art()), 4);
             }
 
-            // If any tree characters have been printed, then add an extra
-            // space, which makes the output look much better.
-            if !row.tree.is_at_root() {
-                cell.add_spaces(1);
-            }
-
             cell.append(row.name);
             cell
         })
@@ -534,12 +528,6 @@ impl Iterator for Iter {
                 cell.push(self.tree_style.paint(tree_part.ascii_art()), 4);
             }
 
-            // If any tree characters have been printed, then add an extra
-            // space, which makes the output look much better.
-            if !row.tree.is_at_root() {
-                cell.add_spaces(1);
-            }
-
             cell.append(row.name);
             cell
         })

+ 13 - 17
src/output/tree.rs

@@ -26,14 +26,14 @@
 //!     │     1 │ false │ ├── this_file.txt     │
 //!     │     1 │ false │ ├── that_file.txt     │
 //!     │     1 │ false │ ├── features          │
-//!     │     2 │ false │ │  ├── feature_1.rs 
-//!     │     2 │ false │ │  ├── feature_2.rs 
-//!     │     2 │ true  │ │  └── feature_3.rs 
+//!     │     2 │ false │ │   ├── feature_1.rs  │
+//!     │     2 │ false │ │   ├── feature_2.rs  │
+//!     │     2 │ true  │ │   └── feature_3.rs  │
 //!     │     1 │ true  │ └── pictures          │
-//!     │     2 │ false │    ├── garden.jpg 
-//!     │     2 │ false │    ├── flowers.jpg 
-//!     │     2 │ false │    ├── library.png 
-//!     │     2 │ true  │    └── space.tiff 
+//!     │     2 │ false │     ├── garden.jpg    │
+//!     │     2 │ false │     ├── flowers.jpg   │
+//!     │     2 │ false │     ├── library.png   │
+//!     │     2 │ true  │     └── space.tiff    │
 //!     └───────┴───────┴───────────────────────┘
 //! ```
 //!
@@ -65,10 +65,10 @@ impl TreePart {
     pub fn ascii_art(self) -> &'static str {
         #[rustfmt::skip]
         return match self {
-            Self::Edge    => "├──",
-            Self::Line    => "│  ",
-            Self::Corner  => "└──",
-            Self::Blank   => "   ",
+            Self::Edge    => "├── ",
+            Self::Line    => "│   ",
+            Self::Corner  => "└── ",
+            Self::Blank   => "    ",
         };
     }
 }
@@ -137,9 +137,9 @@ impl TreeTrunk {
         //     with [0..]        with [1..]
         //     ==========        ==========
         //      ├── folder        folder
-        //      │  └── file       └── file
+        //      │   └── file       └── file
         //      └── folder        folder
-        //         └── file       └──file
+        //          └── file       └──file
         //
         &self.stack[1..]
     }
@@ -149,10 +149,6 @@ impl TreeParams {
     pub fn new(depth: TreeDepth, last: bool) -> Self {
         Self { depth, last }
     }
-
-    pub fn is_at_root(&self) -> bool {
-        self.depth.0 == 0
-    }
 }
 
 impl TreeDepth {

+ 17 - 17
tests/cmd/follow-symlinks_unix.stdout

@@ -4,14 +4,14 @@ tests/itest
 ├── c
 ├── d
 ├── dir-symlink -> vagrant/debug
-│  ├── a
-│  ├── symlink -> a
-│  └── symlink-broken -> ./b
+│   ├── a
+│   ├── symlink -> a
+│   └── symlink-broken -> ./b
 ├── e
 ├── exa
-│  ├── file.c -> djihisudjuhfius
-│  └── sssssssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
-│     └── Makefile
+│   ├── file.c -> djihisudjuhfius
+│   └── sssssssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
+│       └── Makefile
 ├── f
 ├── g
 ├── h
@@ -27,14 +27,14 @@ tests/itest
 ├── p
 ├── q
 └── vagrant
-   ├── debug
-   │  ├── a
-   │  ├── symlink -> a
-   │  └── symlink-broken -> ./b
-   ├── dev
-   │  └── main.bf
-   └── log
-      ├── file.png
-      └── run
-         ├── run.log.text
-         └── sps.log.text
+    ├── debug
+       ├── a
+       ├── symlink -> a
+       └── symlink-broken -> ./b
+    ├── dev
+       └── main.bf
+    └── log
+        ├── file.png
+        └── run
+            ├── run.log.text
+            └── sps.log.text

+ 14 - 14
tests/cmd/tree_unix.stdout

@@ -6,9 +6,9 @@ tests/itest
 ├── dir-symlink -> vagrant/debug
 ├── e
 ├── exa
-│  ├── file.c -> djihisudjuhfius
-│  └── sssssssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
-│     └── Makefile
+│   ├── file.c -> djihisudjuhfius
+│   └── sssssssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
+│       └── Makefile
 ├── f
 ├── g
 ├── h
@@ -24,14 +24,14 @@ tests/itest
 ├── p
 ├── q
 └── vagrant
-   ├── debug
-   │  ├── a
-   │  ├── symlink -> a
-   │  └── symlink-broken -> ./b
-   ├── dev
-   │  └── main.bf
-   └── log
-      ├── file.png
-      └── run
-         ├── run.log.text
-         └── sps.log.text
+    ├── debug
+       ├── a
+       ├── symlink -> a
+       └── symlink-broken -> ./b
+    ├── dev
+       └── main.bf
+    └── log
+        ├── file.png
+        └── run
+            ├── run.log.text
+            └── sps.log.text