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};
|
||||
#[cfg(any(unix, target_os = "redox"))]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
#[cfg(windows)]
|
||||
use std::env;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use ansi_term;
|
||||
|
||||
@ -42,7 +42,7 @@ fn get_separator() -> String {
|
||||
|
||||
#[cfg(windows)]
|
||||
fn get_separator() -> String {
|
||||
if let Some(_) = env::var_os("PATH") {
|
||||
if let Some(_) = env::var_os("HOME") {
|
||||
String::from("/")
|
||||
} else {
|
||||
path::MAIN_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<()> {
|
||||
let separator = if config.null_separator { "\0" } else { "\n" };
|
||||
|
||||
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> {
|
||||
|
Loading…
Reference in New Issue
Block a user