mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:06:40 +02:00
optionally remove table output color (#455)
This commit is contained in:
@ -12,10 +12,10 @@ name = "table"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
# nu-ansi-term = "0.39.0"
|
||||
nu-ansi-term = { path = "../nu-ansi-term" }
|
||||
nu-protocol = { path = "../nu-protocol"}
|
||||
regex = "1.4"
|
||||
unicode-width = "0.1.8"
|
||||
strip-ansi-escapes = "0.1.1"
|
||||
ansi-cut = "0.1.1"
|
||||
ansi-cut = "0.1.1"
|
||||
atty = "0.2.14"
|
||||
|
@ -883,10 +883,11 @@ impl WrappedTable {
|
||||
fn print_table(&self, color_hm: &HashMap<String, Style>, config: &Config) -> String {
|
||||
let mut output = String::new();
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let _ = nu_ansi_term::enable_ansi_support();
|
||||
}
|
||||
// TODO: This may be unnecessary after JTs changes. Let's remove it and see.
|
||||
// #[cfg(windows)]
|
||||
// {
|
||||
// let _ = nu_ansi_term::enable_ansi_support();
|
||||
// }
|
||||
|
||||
if self.data.is_empty() {
|
||||
return output;
|
||||
@ -952,7 +953,18 @@ impl WrappedTable {
|
||||
output.push_str(&self.print_separator(SeparatorPosition::Bottom, color_hm));
|
||||
}
|
||||
|
||||
output
|
||||
// the atty is for when people do ls from vim, there should be no coloring there
|
||||
if config.without_color || !atty::is(atty::Stream::Stdout) {
|
||||
// Draw the table without ansi colors
|
||||
if let Ok(bytes) = strip_ansi_escapes::strip(&output) {
|
||||
String::from_utf8_lossy(&bytes).to_string()
|
||||
} else {
|
||||
output
|
||||
}
|
||||
} else {
|
||||
// Draw the table with ansi colors
|
||||
output
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user