mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Use full width of terminal (extra 2 characters)
Make output 2 characters wider to use the full width of terminal
This commit is contained in:
+1
-1
@@ -148,7 +148,7 @@ pub fn draw_it(
|
|||||||
if !permissions {
|
if !permissions {
|
||||||
eprintln!("Did not have permissions for all directories");
|
eprintln!("Did not have permissions for all directories");
|
||||||
}
|
}
|
||||||
let terminal_width = (get_width_of_terminal() - 16) as usize;
|
let terminal_width = (get_width_of_terminal() - 14) as usize;
|
||||||
let num_indent_chars = 3;
|
let num_indent_chars = 3;
|
||||||
let longest_string_length = root_node
|
let longest_string_length = root_node
|
||||||
.children
|
.children
|
||||||
|
|||||||
+34
-32
@@ -95,10 +95,10 @@ pub fn test_main_multi_arg() {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn main_output() -> String {
|
fn main_output() -> String {
|
||||||
r#"
|
r#"
|
||||||
0B ┌── a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
4.0K ├── hello_file│██████████████████████████████████████████████ │ 100%
|
4.0K ├── hello_file│████████████████████████████████████████████████ │ 100%
|
||||||
4.0K ┌─┴ many │██████████████████████████████████████████████ │ 100%
|
4.0K ┌─┴ many │████████████████████████████████████████████████ │ 100%
|
||||||
4.0K ┌─┴ test_dir │██████████████████████████████████████████████ │ 100%
|
4.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string()
|
.to_string()
|
||||||
@@ -107,10 +107,10 @@ fn main_output() -> String {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn main_output() -> String {
|
fn main_output() -> String {
|
||||||
r#"
|
r#"
|
||||||
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
4.0K ├── hello_file│ ░░░░░░░░░░░░░░░████████████████ │ 33%
|
4.0K ├── hello_file│ ░░░░░░░░░░░░░░░░█████████████████ │ 33%
|
||||||
8.0K ┌─┴ many │ ███████████████████████████████ │ 67%
|
8.0K ┌─┴ many │ █████████████████████████████████ │ 67%
|
||||||
12K ┌─┴ test_dir │██████████████████████████████████████████████ │ 100%
|
12K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string()
|
.to_string()
|
||||||
@@ -133,16 +133,18 @@ pub fn test_main_long_paths() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.stdout;
|
.stdout;
|
||||||
let output = str::from_utf8(&assert).unwrap();
|
let output = str::from_utf8(&assert).unwrap();
|
||||||
|
println!("{:?}", output.trim());
|
||||||
|
println!("{:?}", main_output_long_paths().trim());
|
||||||
assert!(output.contains(&main_output_long_paths()));
|
assert!(output.contains(&main_output_long_paths()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn main_output_long_paths() -> String {
|
fn main_output_long_paths() -> String {
|
||||||
r#"
|
r#"
|
||||||
0B ┌── /tmp/test_dir/many/a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── /tmp/test_dir/many/a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
4.0K ├── /tmp/test_dir/many/hello_file│███████████████████████████ │ 100%
|
4.0K ├── /tmp/test_dir/many/hello_file│█████████████████████████████ │ 100%
|
||||||
4.0K ┌─┴ /tmp/test_dir/many │███████████████████████████ │ 100%
|
4.0K ┌─┴ /tmp/test_dir/many │█████████████████████████████ │ 100%
|
||||||
4.0K ┌─┴ /tmp/test_dir │███████████████████████████ │ 100%
|
4.0K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string()
|
.to_string()
|
||||||
@@ -151,10 +153,10 @@ fn main_output_long_paths() -> String {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn main_output_long_paths() -> String {
|
fn main_output_long_paths() -> String {
|
||||||
r#"
|
r#"
|
||||||
0B ┌── /tmp/test_dir/many/a_file │ ░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── /tmp/test_dir/many/a_file │ ░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
4.0K ├── /tmp/test_dir/many/hello_file│ ░░░░░░░░░██████████ │ 33%
|
4.0K ├── /tmp/test_dir/many/hello_file│ ░░░░░░░░░░██████████ │ 33%
|
||||||
8.0K ┌─┴ /tmp/test_dir/many │ ███████████████████ │ 67%
|
8.0K ┌─┴ /tmp/test_dir/many │ ████████████████████ │ 67%
|
||||||
12K ┌─┴ /tmp/test_dir │███████████████████████████ │ 100%
|
12K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string()
|
.to_string()
|
||||||
@@ -178,10 +180,10 @@ pub fn test_apparent_size() {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn output_apparent_size() -> String {
|
fn output_apparent_size() -> String {
|
||||||
r#"
|
r#"
|
||||||
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
4.0K ┌─┴ many │ ████████████████████████ │ 50%
|
4.0K ┌─┴ many │ █████████████████████████ │ 50%
|
||||||
8.0K ┌─┴ test_dir │██████████████████████████████████████████████ │ 100%
|
8.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string()
|
.to_string()
|
||||||
@@ -190,10 +192,10 @@ fn output_apparent_size() -> String {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn output_apparent_size() -> String {
|
fn output_apparent_size() -> String {
|
||||||
r#"
|
r#"
|
||||||
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░░░██ │ 3%
|
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░░░░██ │ 3%
|
||||||
134B ┌─┴ many │ ███████████████████████████ │ 58%
|
134B ┌─┴ many │ ████████████████████████████ │ 58%
|
||||||
230B ┌─┴ test_dir │██████████████████████████████████████████████ │ 100%
|
230B ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string()
|
.to_string()
|
||||||
@@ -250,7 +252,7 @@ pub fn test_substring_of_names_and_long_names() {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn no_substring_of_names_output() -> String {
|
fn no_substring_of_names_output() -> String {
|
||||||
"
|
"
|
||||||
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this..
|
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
|
||||||
4.0K ├── dir_name_clash
|
4.0K ├── dir_name_clash
|
||||||
4.0K │ ┌── hello
|
4.0K │ ┌── hello
|
||||||
8.0K ├─┴ dir_substring
|
8.0K ├─┴ dir_substring
|
||||||
@@ -265,7 +267,7 @@ fn no_substring_of_names_output() -> String {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn no_substring_of_names_output() -> String {
|
fn no_substring_of_names_output() -> String {
|
||||||
"
|
"
|
||||||
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this..
|
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
|
||||||
4.0K │ ┌── hello
|
4.0K │ ┌── hello
|
||||||
4.0K ├─┴ dir_substring
|
4.0K ├─┴ dir_substring
|
||||||
4.0K ├── dir_name_clash
|
4.0K ├── dir_name_clash
|
||||||
@@ -296,9 +298,9 @@ pub fn test_unicode_directories() {
|
|||||||
fn unicode_dir() -> String {
|
fn unicode_dir() -> String {
|
||||||
// The way unicode & asian characters are rendered on the terminal should make this line up
|
// The way unicode & asian characters are rendered on the terminal should make this line up
|
||||||
"
|
"
|
||||||
0B ┌── 👩.unicode │ █ │ 0%
|
0B ┌── 👩.unicode │ █ │ 0%
|
||||||
0B ├── ラウトは難しいです!.japan│ █ │ 0%
|
0B ├── ラウトは難しいです!.japan│ █ │ 0%
|
||||||
4.0K ┌─┴ test_dir3 │████████████████████████████████ │ 100%
|
4.0K ┌─┴ test_dir3 │██████████████████████████████████ │ 100%
|
||||||
"
|
"
|
||||||
.trim()
|
.trim()
|
||||||
.into()
|
.into()
|
||||||
@@ -307,9 +309,9 @@ fn unicode_dir() -> String {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn unicode_dir() -> String {
|
fn unicode_dir() -> String {
|
||||||
"
|
"
|
||||||
0B ┌── 👩.unicode │ █ │ 0%
|
0B ┌── 👩.unicode │ █ │ 0%
|
||||||
0B ├── ラウトは難しいです!.japan│ █ │ 0%
|
0B ├── ラウトは難しいです!.japan│ █ │ 0%
|
||||||
0B ┌─┴ test_dir3 │ █ │ 0%
|
0B ┌─┴ test_dir3 │ █ │ 0%
|
||||||
"
|
"
|
||||||
.trim()
|
.trim()
|
||||||
.into()
|
.into()
|
||||||
|
|||||||
@@ -25,7 +25,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
|
// 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 {
|
fn get_file_name(name: String) -> String {
|
||||||
let terminal_plus_buffer = (get_width_of_terminal() - 16) as usize;
|
let terminal_plus_buffer = (get_width_of_terminal() - 14) as usize;
|
||||||
if UnicodeWidthStr::width(&*name) > terminal_plus_buffer {
|
if UnicodeWidthStr::width(&*name) > terminal_plus_buffer {
|
||||||
let trimmed_name = name
|
let trimmed_name = name
|
||||||
.chars()
|
.chars()
|
||||||
|
|||||||
Reference in New Issue
Block a user