mirror of
https://github.com/nushell/nushell.git
synced 2025-04-09 21:28:55 +02:00
remove ansi colors if this is not a tty (#4058)
This commit is contained in:
parent
5e34ef6dff
commit
d395816929
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2900,8 +2900,10 @@ dependencies = [
|
|||||||
name = "nu-table"
|
name = "nu-table"
|
||||||
version = "0.37.1"
|
version = "0.37.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"atty",
|
||||||
"nu-ansi-term",
|
"nu-ansi-term",
|
||||||
"regex",
|
"regex",
|
||||||
|
"strip-ansi-escapes",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@ name = "table"
|
|||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
atty = "0.2.14"
|
||||||
nu-ansi-term = { version = "0.37.1", path="../nu-ansi-term" }
|
nu-ansi-term = { version = "0.37.1", path="../nu-ansi-term" }
|
||||||
|
|
||||||
regex = "1.4"
|
regex = "1.4"
|
||||||
|
strip-ansi-escapes = "0.1.1"
|
||||||
unicode-width = "0.1.8"
|
unicode-width = "0.1.8"
|
||||||
|
@ -27,8 +27,18 @@ fn main() {
|
|||||||
let color_hm: HashMap<String, nu_ansi_term::Style> = HashMap::new();
|
let color_hm: HashMap<String, nu_ansi_term::Style> = HashMap::new();
|
||||||
// Capture the table as a string
|
// Capture the table as a string
|
||||||
let output_table = draw_table(&table, width, &color_hm);
|
let output_table = draw_table(&table, width, &color_hm);
|
||||||
// Draw the table
|
|
||||||
println!("{}", output_table)
|
if atty::is(atty::Stream::Stdout) {
|
||||||
|
// Draw the table with ansi colors
|
||||||
|
println!("{}", output_table)
|
||||||
|
} else {
|
||||||
|
// Draw the table without ansi colors
|
||||||
|
if let Ok(bytes) = strip_ansi_escapes::strip(&output_table) {
|
||||||
|
println!("{}", String::from_utf8_lossy(&bytes))
|
||||||
|
} else {
|
||||||
|
println!("{}", output_table)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_table_data() -> (Vec<&'static str>, Vec<&'static str>) {
|
fn make_table_data() -> (Vec<&'static str>, Vec<&'static str>) {
|
||||||
|
@ -918,7 +918,17 @@ impl WrappedTable {
|
|||||||
output.push_str(&self.print_separator(SeparatorPosition::Bottom, color_hm));
|
output.push_str(&self.print_separator(SeparatorPosition::Bottom, color_hm));
|
||||||
}
|
}
|
||||||
|
|
||||||
output
|
if atty::is(atty::Stream::Stdout) {
|
||||||
|
// Draw the table with ansi colors
|
||||||
|
output
|
||||||
|
} else {
|
||||||
|
// Draw the table without ansi colors
|
||||||
|
if let Ok(bytes) = strip_ansi_escapes::strip(&output) {
|
||||||
|
String::from_utf8_lossy(&bytes).to_string()
|
||||||
|
} else {
|
||||||
|
output
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user