Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,13 @@ jobs:
matrix:
job:
# - { os , target , cargo-options , features , use-cross , toolchain, skip-tests }
- { os: ubuntu-latest , target: arm-unknown-linux-gnueabihf, features: feat_os_unix_gnueabihf, use-cross: use-cross, skip-tests: true }
- { os: ubuntu-latest , target: arm-unknown-linux-gnueabihf , features: feat_os_unix_gnueabihf , use-cross: use-cross , skip-tests: true }
- { os: ubuntu-latest , target: aarch64-unknown-linux-gnu , features: feat_os_unix_gnueabihf , use-cross: use-cross , skip-tests: true }
- { os: ubuntu-latest , target: aarch64-unknown-linux-musl , features: feat_os_unix_musl , use-cross: use-cross , skip-tests: true }
# - { os: ubuntu-latest , target: x86_64-unknown-linux-gnu , features: feat_selinux , use-cross: use-cross }
- { os: ubuntu-latest , target: i686-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross }
- { os: ubuntu-latest , target: i686-unknown-linux-gnu , features: "feat_os_unix,test_risky_names", use-cross: use-cross }
- { os: ubuntu-latest , target: i686-unknown-linux-musl , features: feat_os_unix_musl , use-cross: use-cross }
- { os: ubuntu-latest , target: x86_64-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross }
- { os: ubuntu-latest , target: x86_64-unknown-linux-gnu , features: "feat_os_unix,test_risky_names", use-cross: use-cross }
- { os: ubuntu-latest , target: x86_64-unknown-linux-musl , features: feat_os_unix_musl , use-cross: use-cross }
- { os: ubuntu-latest , target: x86_64-unknown-redox , features: feat_os_unix_redox , use-cross: redoxer , skip-tests: true }
- { os: macos-latest , target: aarch64-apple-darwin , features: feat_os_macos } # M1 CPU
Expand Down
36 changes: 19 additions & 17 deletions src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use super::get_metadata_with_deref_opt;
use super::PathData;
use lscolors::{Indicator, LsColors, Style};
use std::ffi::OsString;
use std::fs::{DirEntry, Metadata};
use std::io::{BufWriter, Stdout};

Expand All @@ -31,9 +32,9 @@ impl<'a> StyleManager<'a> {
pub(crate) fn apply_style(
&mut self,
new_style: Option<&Style>,
name: &str,
name: OsString,
wrap: bool,
) -> String {
) -> OsString {
let mut style_code = String::new();
let mut force_suffix_reset: bool = false;

Expand All @@ -50,14 +51,14 @@ impl<'a> StyleManager<'a> {
// normal style is to be printed we could skip printing new color
// codes
if !self.is_current_style(new_style) {
style_code.push_str(&self.reset(!self.initial_reset_is_done));
style_code.push_str(self.reset(!self.initial_reset_is_done));
style_code.push_str(&self.get_style_code(new_style));
}
}
// if new style is None and current style is Normal we should reset it
else if matches!(self.get_normal_style().copied(), Some(norm_style) if self.is_current_style(&norm_style))
{
style_code.push_str(&self.reset(false));
style_code.push_str(self.reset(false));
// even though this is an unnecessary reset for gnu compatibility we allow it here
force_suffix_reset = true;
}
Expand All @@ -69,16 +70,17 @@ impl<'a> StyleManager<'a> {
// till the end of line
let clear_to_eol = if wrap { "\x1b[K" } else { "" };

format!(
"{style_code}{name}{}{clear_to_eol}",
self.reset(force_suffix_reset),
)
let mut ret: OsString = style_code.into();
ret.push(name);
ret.push(self.reset(force_suffix_reset));
ret.push(clear_to_eol);
ret
}

/// Resets the current style and returns the default ANSI reset code to
/// reset all text formatting attributes. If `force` is true, the reset is
/// done even if the reset has been applied before.
pub(crate) fn reset(&mut self, force: bool) -> String {
pub(crate) fn reset(&mut self, force: bool) -> &str {
// todo:
// We need to use style from `Indicator::Reset` but as of now ls colors
// uses a fallback mechanism and because of that if `Indicator::Reset`
Expand All @@ -87,9 +89,9 @@ impl<'a> StyleManager<'a> {
if self.current_style.is_some() || force {
self.initial_reset_is_done = true;
self.current_style = None;
return "\x1b[0m".to_string();
return "\x1b[0m";
}
String::new()
""
}

pub(crate) fn get_style_code(&mut self, new_style: &Style) -> String {
Expand Down Expand Up @@ -124,9 +126,9 @@ impl<'a> StyleManager<'a> {
&mut self,
path: &PathData,
md_option: Option<&Metadata>,
name: &str,
name: OsString,
wrap: bool,
) -> String {
) -> OsString {
let style = self
.colors
.style_for_path_with_metadata(&path.p_buf, md_option);
Expand All @@ -136,9 +138,9 @@ impl<'a> StyleManager<'a> {
pub(crate) fn apply_style_based_on_dir_entry(
&mut self,
dir_entry: &DirEntry,
name: &str,
name: OsString,
wrap: bool,
) -> String {
) -> OsString {
let style = self.colors.style_for(dir_entry);
self.apply_style(style, name, wrap)
}
Expand All @@ -149,13 +151,13 @@ impl<'a> StyleManager<'a> {
/// unnecessary calls to stat()
/// and manages the symlink errors
pub(crate) fn color_name(
name: &str,
name: OsString,
path: &PathData,
style_manager: &mut StyleManager,
out: &mut BufWriter<Stdout>,
target_symlink: Option<&PathData>,
wrap: bool,
) -> String {
) -> OsString {
// Check if the file has capabilities
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))]
{
Expand Down
3 changes: 1 addition & 2 deletions src/uu/ls/src/dired.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ pub fn update_positions(dired: &mut DiredOutput, start: usize, end: usize) {
/// we don't use clap here because we need to know if the argument is present
/// as it can be overridden by --hyperlink
pub fn is_dired_arg_present() -> bool {
let args: Vec<String> = std::env::args().collect();
args.iter().any(|x| x == "--dired" || x == "-D")
std::env::args_os().any(|x| x == "--dired" || x == "-D")
}

#[cfg(test)]
Expand Down
Loading
Loading