Skip to content
Myr

Factor into a helper function; adapt to print_entry_uncolorized.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nathan Moreau · committed by David Peter · parent 29bf9d7 · Browse files · 1 file+11 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+11 added−8 removed

  • other:+11 added−8 removed

1 file+11 added−8 removed

modified:src/output.rs+11 added-8 removed
8 unmodified lines
9use crate::exit_codes::ExitCode;10use crate::internal::opts::FdOptions;11use lscolors::{LsColors, Style};1213use std::borrow::Cow;14use std::io::{self, StdoutLock, Write};15use std::path::{Component, Path, PathBuf};16use std::process;17use std::sync::atomic::{AtomicBool, Ordering};
34 unmodified lines
52 process::exit(ExitCode::GeneralError.into());53 }54}5556fn replace_path_separator<'a>(config: &FdOptions, str: Cow<'a, str>) -> Cow<'a, str> {57 match &config.path_separator {58 None => str,59 Some(sep) => Cow::from(str.replace(std::path::MAIN_SEPARATOR, &sep)),60 }61}6263fn print_entry_colorized(64 stdout: &mut StdoutLock,65 path: &Path,66 config: &FdOptions,
8 unmodified lines
75 .map(Style::to_ansi_term_style)76 .unwrap_or(default_style);7778 let path_string = component.to_string_lossy();79 let path_string = replace_path_separator(&config, path_string);80 write!(stdout, "{}", style.paint(path_string))?;8172 match &config.path_separator {73 None => write!(stdout, "{}", style.paint(path_string))?,74 Some(sep) => {75 let path_string = path_string.replace(std::path::MAIN_SEPARATOR, &sep);76 write!(stdout, "{}", style.paint(path_string))?77 }78 }7982 if wants_to_quit.load(Ordering::Relaxed) {83 writeln!(stdout)?;84 process::exit(ExitCode::KilledBySigint.into());85 }
13 unmodified lines
99) -> io::Result<()> {100 let separator = if config.null_separator { "\0" } else { "\n" };101102 let path_str = path.to_string_lossy();103 let path_str = replace_path_separator(&config, path_str);104 write!(stdout, "{}{}", path_str, separator)105}