Skip to content
Myr

add actual path separator value to config

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

authored by Jonathan Goren · committed by Jonathan Goren · parent 38b84d0 · Browse files · 3 files+8 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

3 files+8 added−8 removed

  • other:+8 added−8 removed

3 files+8 added−8 removed

modified:src/config.rs+3 added
109 unmodified lines
110111 /// The separator used to print file paths.112 pub path_separator: Option<String>,113114 /// The actual separator, either the system default separator or `path_separator`115 pub actual_path_separator: String,116117 /// The maximum number of search results118 pub max_results: Option<usize>,119120 /// Whether or not to strip the './' prefix for search results
2 unmodified lines
modified:src/main.rs+4 added
220 unmodified lines
221222 let path_separator = matches223 .value_of("path-separator")224 .map_or_else(filesystem::default_path_separator, |s| Some(s.to_owned()));225 let actual_path_separator = path_separator226 .clone()227 .unwrap_or_else(|| std::path::MAIN_SEPARATOR.to_string());228 check_path_separator_length(path_separator.as_deref())?;229230 let size_limits = extract_size_limits(&matches)?;231 let time_constraints = extract_time_constraints(&matches)?;
138 unmodified lines
370 #[cfg(unix)]371 owner_constraint,372 show_filesystem_errors: matches.is_present("show-errors"),373 path_separator,374 actual_path_separator,375 max_results: matches376 .value_of("max-results")377 .map(|n| n.parse::<usize>())378 .transpose()
191 unmodified lines
modified:src/output.rs+1 added-8 removed
1 unmodified line
2use std::io::{self, Write};3use std::path::Path;45use lscolors::{Indicator, LsColors, Style};6use once_cell::sync::Lazy;67use crate::config::Config;8use crate::dir_entry::DirEntry;9use crate::error::print_error;10use crate::exit_codes::ExitCode;11use crate::filesystem::strip_current_dir;1214static MAIN_SEPARATOR_STR: Lazy<String> = Lazy::new(|| std::path::MAIN_SEPARATOR.to_string());1513fn replace_path_separator(path: &str, new_path_separator: &str) -> String {14 path.replace(std::path::MAIN_SEPARATOR, new_path_separator)15}16
35 unmodified lines
52 config: &Config,53 style: Option<&Style>,54) -> io::Result<()> {55 if entry.file_type().map_or(false, |ft| ft.is_dir()) {59 let separator = config60 .path_separator61 .as_ref()62 .unwrap_or(&MAIN_SEPARATOR_STR);56 write!(57 stdout,58 "{}",59 style60 .map(Style::to_ansi_term_style)61 .unwrap_or_default()69 .paint(separator)62 .paint(&config.actual_path_separator)63 )?;64 }65 Ok(())66}
105 unmodified lines