Skip to content

Commit

Permalink
try to use lscolors gnu_legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Nov 30, 2023
1 parent 8c8558e commit 2787039
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ indicatif = "0.17"
itertools = "0.12.0"
libc = "0.2.150"
lscolors = { version = "0.16.0", default-features = false, features = [
"nu-ansi-term",
"nu-ansi-term", "gnu_legacy",
] }
memchr = "2"
memmap2 = "0.9"
Expand Down
2 changes: 1 addition & 1 deletion src/uu/ls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ number_prefix = { workspace = true }
uutils_term_grid = { workspace = true }
terminal_size = { workspace = true }
glob = { workspace = true }
lscolors = { workspace = true }
lscolors = { workspace = true, features = ["gnu_legacy"] }
uucore = { workspace = true, features = [
"entries",
"fs",
Expand Down
2 changes: 1 addition & 1 deletion src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3097,7 +3097,7 @@ fn display_file_name(
fn color_name(name: String, path: &Path, md: Option<&Metadata>, ls_colors: &LsColors) -> String {

Check failure on line 3097 in src/uu/ls/src/ls.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/ls/src/ls.rs', line:3097; use `cargo fmt -- "src/uu/ls/src/ls.rs"`)
match ls_colors.style_for_path_with_metadata(path, md) {
Some(style) => {
return style.to_nu_ansi_term_style().paint(name).to_string();
return style.to_nu_ansi_term_style().reset_before_style().paint(name).to_string();
}
None => name,
}
Expand Down
52 changes: 38 additions & 14 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,9 @@ fn test_ls_long_symlink_color() {
expected_target: &str,

Check failure on line 1174 in tests/by-util/test_ls.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'tests/by-util/test_ls.rs', line:1174; use `cargo fmt -- "tests/by-util/test_ls.rs"`)
) {
// Names are always compared.
println!("name = {} / expected {}", to_ascii_representation(name), to_ascii_representation(expected_name));
assert_eq!(&name, &expected_name);
println!("target = {} / expected {}", to_ascii_representation(target), to_ascii_representation(expected_target));
assert_eq!(&target, &expected_target);

// Colors are only compared when we have inferred what color we are looking for.
Expand Down Expand Up @@ -1962,6 +1964,17 @@ fn test_ls_recursive_1() {
.stdout_is(out);
}

Check failure on line 1966 in tests/by-util/test_ls.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'tests/by-util/test_ls.rs', line:1966; use `cargo fmt -- "tests/by-util/test_ls.rs"`)
// Function to convert a string to its ASCII representation
fn to_ascii_representation(input: &str) -> String {
input.chars().map(|c| {
if c.is_ascii_control() || !c.is_ascii() {
format!("\\x{:02x}", c as u32)
} else {
c.to_string()
}
}).collect::<String>()
}

#[test]
fn test_ls_color() {
let scene = TestScenario::new(util_name!());
Expand All @@ -1979,10 +1992,10 @@ fn test_ls_color() {
.to_string();

Check failure on line 1992 in tests/by-util/test_ls.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'tests/by-util/test_ls.rs', line:1992; use `cargo fmt -- "tests/by-util/test_ls.rs"`)
at.touch(nested_file);
at.touch("test-color");

let a_with_colors = "\x1b[1;34ma\x1b[0m";
let z_with_colors = "\x1b[1;34mz\x1b[0m";
let nested_dir_with_colors = "\x1b[1;34mnested_dir\x1b[0m"; // spell-checker:disable-line
let a_with_colors = "\x1b[0m\x1b[01;34ma\x1b[0m\x0a";
let z_with_colors = "\x1b[0m\x1b[01;34mz\x1b[0m\x0a";
let nested_dir_with_colors = "\x1b[0m\x1b[01;34mnested_dir\x1b[0m\x0anested_file\x0a"; // spell-checker:disable-line

// Color is disabled by default
let result = scene.ucmd().succeeds();
Expand All @@ -1991,12 +2004,19 @@ fn test_ls_color() {

Check failure on line 2004 in tests/by-util/test_ls.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'tests/by-util/test_ls.rs', line:2004; use `cargo fmt -- "tests/by-util/test_ls.rs"`)
// Color should be enabled
for param in ["--color", "--col", "--color=always", "--col=always"] {
scene

println!(
"a_with_colors {} / z_with_colors {}",
to_ascii_representation(a_with_colors),
to_ascii_representation(z_with_colors)
);
let result = scene
.ucmd()
.arg(param)
.succeeds()
.stdout_contains(a_with_colors)
.stdout_contains(z_with_colors);
.succeeds();
println!("stdout = {} / ascii = {}", result.stdout_str(), to_ascii_representation(result.stdout_str()));
assert!(result.stdout_str().contains(a_with_colors));
assert!(result.stdout_str().contains(z_with_colors));
}

// Color should be disabled
Expand All @@ -2005,12 +2025,14 @@ fn test_ls_color() {
assert!(!result.stdout_str().contains(z_with_colors));

Check failure on line 2025 in tests/by-util/test_ls.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'tests/by-util/test_ls.rs', line:2025; use `cargo fmt -- "tests/by-util/test_ls.rs"`)

// Nested dir should be shown and colored
scene
let result = scene
.ucmd()
.arg("--color")
.arg("a")
.succeeds()
.stdout_contains(nested_dir_with_colors);
.succeeds();
println!("stdout = {} / ascii = {}", result.stdout_str(), to_ascii_representation(result.stdout_str()));
assert!(result.stdout_str().contains(nested_dir_with_colors));


// No output
scene
Expand All @@ -2022,13 +2044,15 @@ fn test_ls_color() {

// The colors must not mess up the grid layout
at.touch("b");
scene
let result = scene
.ucmd()
.arg("--color")
.arg("-w=15")

Check failure on line 2050 in tests/by-util/test_ls.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'tests/by-util/test_ls.rs', line:2050; use `cargo fmt -- "tests/by-util/test_ls.rs"`)
.arg("-C")
.succeeds()
.stdout_only(format!("{a_with_colors} test-color\nb {z_with_colors}\n"));
.succeeds();
println!("stdout = {} / ascii = {}", result.stdout_str(), to_ascii_representation(result.stdout_str()));
println!("expected {}", to_ascii_representation("{a_with_colors} test-color\nb {z_with_colors}\n"));
assert!(result.stdout_str() == format!("{a_with_colors} test-color\x0ab {z_with_colors}\n"));
}

#[cfg(unix)]
Expand Down

0 comments on commit 2787039

Please sign in to comment.