Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not color health summary when stdout is piped #2836

Merged
merged 2 commits into from
Jun 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions helix-term/src/health.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crossterm::style::{Color, Print, Stylize};
use crossterm::{
style::{Color, Print, Stylize},
tty::IsTty,
};
use helix_core::config::{default_syntax_loader, user_syntax_loader};
use helix_loader::grammar::load_runtime_file;
use std::io::Write;
Expand Down Expand Up @@ -106,17 +109,19 @@ pub fn languages_all() -> std::io::Result<()> {

let terminal_cols = crossterm::terminal::size().map(|(c, _)| c).unwrap_or(80);
let column_width = terminal_cols as usize / headings.len();
let is_terminal = std::io::stdout().is_tty();

let column = |item: &str, color: Color| {
let data = format!(
let mut data = format!(
"{:width$}",
item.get(..column_width - 2)
.map(|s| format!("{}…", s))
.unwrap_or_else(|| item.to_string()),
width = column_width,
)
.stylize()
.with(color);
);
if is_terminal {
data = data.stylize().with(color).to_string();
}

// We can't directly use println!() because of
// https://github.com/crossterm-rs/crossterm/issues/589
Expand Down