on master help sign in
fix: do not color health summary when stdout is piped (#2836)

* fix: do not color health summary when stdout is piped * fix: use crossterm instead of is-terminal

commit55f4f6951571d44862d5f1bc3ad7094953b788b6 authorlazytanuki <43273245+lazytanuki@users.noreply.github.com> dateMon 20 Jun 2022, 17:07 (4 years ago) parente2878a6
1 file changed+10−5
helix-term/src/health.rs+10−5
helix-term/src/health.rs+10−5
@@ -1,4 +1,7 @@
1−use crossterm::style::{Color, Print, Stylize};
1+use crossterm::{
2+ style::{Color, Print, Stylize},
3+ tty::IsTty,
4+};
25use helix_core::config::{default_syntax_loader, user_syntax_loader};
36use helix_loader::grammar::load_runtime_file;
47use std::io::Write;
@@ -106,17 +109,19 @@ pub fn languages_all() -> std::io::Result<()> {
106109
107110 let terminal_cols = crossterm::terminal::size().map(|(c, _)| c).unwrap_or(80);
108111 let column_width = terminal_cols as usize / headings.len();
112+ let is_terminal = std::io::stdout().is_tty();
109113
110114 let column = |item: &str, color: Color| {
111− let data = format!(
115+ let mut data = format!(
112116 "{:width$}",
113117 item.get(..column_width - 2)
114118 .map(|s| format!("{}…", s))
115119 .unwrap_or_else(|| item.to_string()),
116120 width = column_width,
117− )
118− .stylize()
119− .with(color);
121+ );
122+ if is_terminal {
123+ data = data.stylize().with(color).to_string();
124+ }
120125
121126 // We can't directly use println!() because of
122127 // https://github.com/crossterm-rs/crossterm/issues/589