From 92665144c9ddf100d5044dc0c52af122a94587d0 Mon Sep 17 00:00:00 2001 From: sreehari prasad <52113972+matrixhead@users.noreply.github.com> Date: Tue, 25 Jun 2024 01:08:10 +0530 Subject: [PATCH] ls: gnu `color-norm` test fix (#6481) --- Cargo.lock | 8 +- Cargo.toml | 2 +- src/uu/ls/src/colors.rs | 162 +++++++++++++++++++++++++++++++++++++++ src/uu/ls/src/ls.rs | 128 ++++++++----------------------- tests/by-util/test_ls.rs | 130 +++++++++++++++++++++++++++++++ util/build-gnu.sh | 15 +++- 6 files changed, 342 insertions(+), 103 deletions(-) create mode 100644 src/uu/ls/src/colors.rs diff --git a/Cargo.lock b/Cargo.lock index fa56efa1e..856d392a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1383,9 +1383,9 @@ dependencies = [ [[package]] name = "lscolors" -version = "0.16.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab0b209ec3976527806024406fe765474b9a1750a0ed4b8f0372364741f50e7b" +checksum = "02a5d67fc8a616f260ee9a36868547da09ac24178a4b84708cd8ea781372fbe4" dependencies = [ "nu-ansi-term", ] @@ -1484,9 +1484,9 @@ dependencies = [ [[package]] name = "nu-ansi-term" -version = "0.49.0" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c073d3c1930d0751774acf49e66653acecb416c3a54c6ec095a9b11caddb5a68" +checksum = "dd2800e1520bdc966782168a627aa5d1ad92e33b984bf7c7615d31280c83ff14" dependencies = [ "windows-sys 0.48.0", ] diff --git a/Cargo.toml b/Cargo.toml index 3a17ac6dd..aa6b4424d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -290,7 +290,7 @@ hostname = "0.4" indicatif = "0.17.8" itertools = "0.13.0" libc = "0.2.153" -lscolors = { version = "0.16.0", default-features = false, features = [ +lscolors = { version = "0.18.0", default-features = false, features = [ "gnu_legacy", ] } memchr = "2.7.2" diff --git a/src/uu/ls/src/colors.rs b/src/uu/ls/src/colors.rs new file mode 100644 index 000000000..d41df2c09 --- /dev/null +++ b/src/uu/ls/src/colors.rs @@ -0,0 +1,162 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. +use super::get_metadata_with_deref_opt; +use super::PathData; +use lscolors::{Indicator, LsColors, Style}; +use std::fs::{DirEntry, Metadata}; +use std::io::{BufWriter, Stdout}; + +/// We need this struct to be able to store the previous style. +/// This because we need to check the previous value in case we don't need +/// the reset +pub(crate) struct StyleManager<'a> { + /// last style that is applied, if `None` that means reset is applied. + pub(crate) current_style: Option