mirror of
https://github.com/sharkdp/fd.git
synced 2024-10-02 15:01:30 +02:00
Adding windows specific method to change back slashes to forward slashes if running in cygwin when output is not colorized
This commit is contained in:
parent
062ba4b8ae
commit
d94e2ae027
@ -15,8 +15,8 @@ use std::ops::Deref;
|
|||||||
use std::path::{self, Path, PathBuf, Component};
|
use std::path::{self, Path, PathBuf, Component};
|
||||||
#[cfg(any(unix, target_os = "redox"))]
|
#[cfg(any(unix, target_os = "redox"))]
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
#[cfg(windows)]
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use ansi_term;
|
use ansi_term;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ fn get_separator() -> String {
|
|||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn get_separator() -> String {
|
fn get_separator() -> String {
|
||||||
if let Some(_) = env::var_os("PATH") {
|
if let Some(_) = env::var_os("HOME") {
|
||||||
String::from("/")
|
String::from("/")
|
||||||
} else {
|
} else {
|
||||||
path::MAIN_SEPARATOR.to_string()
|
path::MAIN_SEPARATOR.to_string()
|
||||||
@ -78,7 +78,7 @@ fn print_entry_colorized(path: &Path, config: &FdOptions, ls_colors: &LsColors)
|
|||||||
Component::RootDir => String::new(),
|
Component::RootDir => String::new(),
|
||||||
// Everything else uses a separator that is painted the same way as the component.
|
// Everything else uses a separator that is painted the same way as the component.
|
||||||
_ => {
|
_ => {
|
||||||
style.paint(get_separator()).to_string()
|
style.paint(get_separator()).to_string()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -90,11 +90,25 @@ fn print_entry_colorized(path: &Path, config: &FdOptions, ls_colors: &LsColors)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn write_entry_uncolorized(entry: Cow<str>, separator: str) -> io::Result<()> {
|
||||||
|
write!(&mut io::stdout(), "{}{}", entry, separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn write_entry_uncolorized(entry: Cow<str>, separator: &'static str) -> io::Result<()> {
|
||||||
|
if let Some(_) = env::var_os("HOME") {
|
||||||
|
write!(&mut io::stdout(), "{}{}", entry.replace("\\", "/"), separator)
|
||||||
|
} else {
|
||||||
|
write!(&mut io::stdout(), "{}{}", entry, separator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn print_entry_uncolorized(path: &Path, config: &FdOptions) -> io::Result<()> {
|
fn print_entry_uncolorized(path: &Path, config: &FdOptions) -> io::Result<()> {
|
||||||
let separator = if config.null_separator { "\0" } else { "\n" };
|
let separator = if config.null_separator { "\0" } else { "\n" };
|
||||||
|
|
||||||
let path_str = path.to_string_lossy();
|
let path_str = path.to_string_lossy();
|
||||||
write!(&mut io::stdout(), "{}{}", path_str, separator)
|
write_entry_uncolorized(path_str, separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_path_style<'a>(path: &Path, ls_colors: &'a LsColors) -> Option<&'a ansi_term::Style> {
|
fn get_path_style<'a>(path: &Path, ls_colors: &'a LsColors) -> Option<&'a ansi_term::Style> {
|
||||||
|
Loading…
Reference in New Issue
Block a user