Fix: Bug: names may be shortened unnecessarily

The code calculating the width of a row to use vs the width of the
terminal wasn't quite right.

If we had 2 long filepaths one at the top of the dir tree and one at the
bottom the old code would shorten both equally. This doesn't make sense
as the one at the shallowest part of the tree would have used less
screen real estate and so should show a longer part of the filepath.
This commit is contained in:
andy.boot
2022-01-02 23:16:27 +00:00
parent 2d58609d54
commit 469e6d0a69
3 changed files with 29 additions and 20 deletions
+2 -2
View File
@@ -141,7 +141,7 @@ pub fn test_substring_of_names_and_long_names() {
fn no_substring_of_names_output() -> Vec<String> {
let ubuntu = "
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_goe..
4.0K ├── dir_name_clash
4.0K │ ┌── hello
8.0K ├─┴ dir
@@ -153,7 +153,7 @@ fn no_substring_of_names_output() -> Vec<String> {
.into();
let mac_and_some_linux = "
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_goe..
4.0K │ ┌── hello
4.0K ├─┴ dir
4.0K ├── dir_name_clash
+1 -1
View File
@@ -24,7 +24,7 @@ fn get_width_of_terminal() -> u16 {
// Mac test runners create tmp files with very long names, hence it may be shortened in the output
fn get_file_name(name: String) -> String {
let terminal_plus_buffer = (get_width_of_terminal() - 14) as usize;
let terminal_plus_buffer = (get_width_of_terminal() - 12) as usize;
if UnicodeWidthStr::width(&*name) > terminal_plus_buffer {
let trimmed_name = name
.chars()