forked from extern/nushell
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"
|
||||
version = "0.37.1"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"nu-ansi-term",
|
||||
"regex",
|
||||
"strip-ansi-escapes",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
|
@ -12,7 +12,9 @@ name = "table"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
atty = "0.2.14"
|
||||
nu-ansi-term = { version = "0.37.1", path="../nu-ansi-term" }
|
||||
|
||||
regex = "1.4"
|
||||
strip-ansi-escapes = "0.1.1"
|
||||
unicode-width = "0.1.8"
|
||||
|
@ -27,8 +27,18 @@ fn main() {
|
||||
let color_hm: HashMap<String, nu_ansi_term::Style> = HashMap::new();
|
||||
// Capture the table as a string
|
||||
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>) {
|
||||
|
@ -918,7 +918,17 @@ impl WrappedTable {
|
||||
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