mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-17 17:35:16 +01:00
add actual path separator value to config
This commit is contained in:
parent
38b84d08d7
commit
47e30d3d4a
3 changed files with 8 additions and 8 deletions
|
@ -111,6 +111,9 @@ pub struct Config {
|
||||||
/// The separator used to print file paths.
|
/// The separator used to print file paths.
|
||||||
pub path_separator: Option<String>,
|
pub path_separator: Option<String>,
|
||||||
|
|
||||||
|
/// The actual separator, either the system default separator or `path_separator`
|
||||||
|
pub actual_path_separator: String,
|
||||||
|
|
||||||
/// The maximum number of search results
|
/// The maximum number of search results
|
||||||
pub max_results: Option<usize>,
|
pub max_results: Option<usize>,
|
||||||
|
|
||||||
|
|
|
@ -222,6 +222,9 @@ fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result<Co
|
||||||
let path_separator = matches
|
let path_separator = matches
|
||||||
.value_of("path-separator")
|
.value_of("path-separator")
|
||||||
.map_or_else(filesystem::default_path_separator, |s| Some(s.to_owned()));
|
.map_or_else(filesystem::default_path_separator, |s| Some(s.to_owned()));
|
||||||
|
let actual_path_separator = path_separator
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| std::path::MAIN_SEPARATOR.to_string());
|
||||||
check_path_separator_length(path_separator.as_deref())?;
|
check_path_separator_length(path_separator.as_deref())?;
|
||||||
|
|
||||||
let size_limits = extract_size_limits(&matches)?;
|
let size_limits = extract_size_limits(&matches)?;
|
||||||
|
@ -368,6 +371,7 @@ fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result<Co
|
||||||
owner_constraint,
|
owner_constraint,
|
||||||
show_filesystem_errors: matches.is_present("show-errors"),
|
show_filesystem_errors: matches.is_present("show-errors"),
|
||||||
path_separator,
|
path_separator,
|
||||||
|
actual_path_separator,
|
||||||
max_results: matches
|
max_results: matches
|
||||||
.value_of("max-results")
|
.value_of("max-results")
|
||||||
.map(|n| n.parse::<usize>())
|
.map(|n| n.parse::<usize>())
|
||||||
|
|
|
@ -3,7 +3,6 @@ use std::io::{self, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use lscolors::{Indicator, LsColors, Style};
|
use lscolors::{Indicator, LsColors, Style};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::dir_entry::DirEntry;
|
use crate::dir_entry::DirEntry;
|
||||||
|
@ -11,8 +10,6 @@ use crate::error::print_error;
|
||||||
use crate::exit_codes::ExitCode;
|
use crate::exit_codes::ExitCode;
|
||||||
use crate::filesystem::strip_current_dir;
|
use crate::filesystem::strip_current_dir;
|
||||||
|
|
||||||
static MAIN_SEPARATOR_STR: Lazy<String> = Lazy::new(|| std::path::MAIN_SEPARATOR.to_string());
|
|
||||||
|
|
||||||
fn replace_path_separator(path: &str, new_path_separator: &str) -> String {
|
fn replace_path_separator(path: &str, new_path_separator: &str) -> String {
|
||||||
path.replace(std::path::MAIN_SEPARATOR, new_path_separator)
|
path.replace(std::path::MAIN_SEPARATOR, new_path_separator)
|
||||||
}
|
}
|
||||||
|
@ -56,17 +53,13 @@ fn print_trailing_slash<W: Write>(
|
||||||
style: Option<&Style>,
|
style: Option<&Style>,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
if entry.file_type().map_or(false, |ft| ft.is_dir()) {
|
if entry.file_type().map_or(false, |ft| ft.is_dir()) {
|
||||||
let separator = config
|
|
||||||
.path_separator
|
|
||||||
.as_ref()
|
|
||||||
.unwrap_or(&MAIN_SEPARATOR_STR);
|
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout,
|
||||||
"{}",
|
"{}",
|
||||||
style
|
style
|
||||||
.map(Style::to_ansi_term_style)
|
.map(Style::to_ansi_term_style)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.paint(separator)
|
.paint(&config.actual_path_separator)
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue