Handle any string replacement.
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 3857fa8 · Browse files · 4 files·+6 added−24 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+6 added−24 removed
- other:+6 added−24 removed
Provenance
- Commit
29bf9d7- Tree
8b44406- Author
Nathan Moreau <nathan.moreau@m4x.org>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
3857fa8
4 files changed+6 added−24 removed
modified:src/internal/opts.rs+1 added-1 removed
75 unmodified lines76 /// Whether or not to display filesystem errors77 pub show_filesystem_errors: bool,78 79 /// The separator used to print file paths.80- pub path_separator: Option<u8>,80+ pub path_separator: Option<String>,81 }modified:src/app.rs+1 added-2 removed
256 unmodified lines257 , "Show absolute instead of relative paths"258 , "Shows the full path starting from the root as opposed to relative paths.");259 doc!(h, "path-separator"260 , "Set the path separator to use when printing file paths."261- , "Set the path separator to use when printing file paths. \262- A path separator is limited to a single byte.");261+ , "Set the path separator to use when printing file paths.");262 doc!(h, "follow"263 , "Follow symbolic links"264 , "By default, fd does not descend into symlinked directories. Using this flag, symbolic \265 links are also traversed.");124 unmodified linesmodified:src/main.rs+2 added-13 removed
112 unmodified lines113 Some("never") => false,114 _ => atty::is(Stream::Stdout),115 };116 117- let path_separator: Option<u8> = match matches.value_of("path-separator") {118- Some(sep_str) => {119- let sep = sep_str.as_bytes();120- if sep.len() != 1 {121- print_error_and_exit!(122- "'{}' is not a valid path separator. See 'fd --help'.",123- sep_str124- );125- }126- Some(sep[0])127- }128- None => None,129- };117+ let path_separator: Option<String> =118+ matches.value_of("path-separator").map(|str| str.to_owned());119 120 #[cfg(windows)]121 let colored_output = colored_output && ansi_term::enable_ansi_support().is_ok();122 148 unmodified linesmodified:src/output.rs+2 added-8 removed
67 unmodified lines68 .unwrap_or(default_style);69 70 let path_string = component.to_string_lossy();71 72- match config.path_separator {72+ match &config.path_separator {73 None => write!(stdout, "{}", style.paint(path_string))?,74 Some(sep) => {75- let mut path_bytes = path_string.as_bytes().to_vec();76- for b in &mut path_bytes {77- if *b == b'/' || (cfg!(windows) && *b == b'\\') {78- *b = sep;79- }80- }81- let path_string = String::from_utf8_lossy(&path_bytes);75+ let path_string = path_string.replace(std::path::MAIN_SEPARATOR, &sep);76 write!(stdout, "{}", style.paint(path_string))?77 }78 }79 23 unmodified lines