fix (hx --health): Don't print headers in white (#12355)

This commit is contained in:
Jean Abou Samra 2024-12-29 17:38:28 +01:00 committed by GitHub
parent 6d07ae4f07
commit 9cc056e755
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,6 @@
use crate::config::{Config, ConfigLoadError}; use crate::config::{Config, ConfigLoadError};
use crossterm::{ use crossterm::{
style::{Color, Print, Stylize}, style::{Color, StyledContent, Stylize},
tty::IsTty, tty::IsTty,
}; };
use helix_core::config::{default_lang_config, user_lang_config}; use helix_core::config::{default_lang_config, user_lang_config};
@ -164,25 +164,20 @@ pub fn languages_all() -> std::io::Result<()> {
let column_width = terminal_cols as usize / headings.len(); let column_width = terminal_cols as usize / headings.len();
let is_terminal = std::io::stdout().is_tty(); let is_terminal = std::io::stdout().is_tty();
let column = |item: &str, color: Color| { let fit = |s: &str| -> StyledContent<String> {
let mut data = format!( format!(
"{:width$}", "{:column_width$}",
item.get(..column_width - 2) s.get(..column_width - 2)
.map(|s| format!("{}", s)) .map(|s| format!("{}", s))
.unwrap_or_else(|| item.to_string()), .unwrap_or_else(|| s.to_string())
width = column_width, )
); .stylize()
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
let _ = crossterm::execute!(std::io::stdout(), Print(data));
}; };
let color = |s: StyledContent<String>, c: Color| if is_terminal { s.with(c) } else { s };
let bold = |s: StyledContent<String>| if is_terminal { s.bold() } else { s };
for heading in headings { for heading in headings {
column(heading, Color::White); write!(stdout, "{}", bold(fit(heading)))?;
} }
writeln!(stdout)?; writeln!(stdout)?;
@ -192,14 +187,14 @@ pub fn languages_all() -> std::io::Result<()> {
let check_binary = |cmd: Option<&str>| match cmd { let check_binary = |cmd: Option<&str>| match cmd {
Some(cmd) => match helix_stdx::env::which(cmd) { Some(cmd) => match helix_stdx::env::which(cmd) {
Ok(_) => column(&format!("{}", cmd), Color::Green), Ok(_) => color(fit(&format!("{}", cmd)), Color::Green),
Err(_) => column(&format!("{}", cmd), Color::Red), Err(_) => color(fit(&format!("{}", cmd)), Color::Red),
}, },
None => column("None", Color::Yellow), None => color(fit("None"), Color::Yellow),
}; };
for lang in &syn_loader_conf.language { for lang in &syn_loader_conf.language {
column(&lang.language_id, Color::Reset); write!(stdout, "{}", fit(&lang.language_id))?;
let mut cmds = lang.language_servers.iter().filter_map(|ls| { let mut cmds = lang.language_servers.iter().filter_map(|ls| {
syn_loader_conf syn_loader_conf
@ -207,28 +202,28 @@ pub fn languages_all() -> std::io::Result<()> {
.get(&ls.name) .get(&ls.name)
.map(|config| config.command.as_str()) .map(|config| config.command.as_str())
}); });
check_binary(cmds.next()); write!(stdout, "{}", check_binary(cmds.next()))?;
let dap = lang.debugger.as_ref().map(|dap| dap.command.as_str()); let dap = lang.debugger.as_ref().map(|dap| dap.command.as_str());
check_binary(dap); write!(stdout, "{}", check_binary(dap))?;
let formatter = lang let formatter = lang
.formatter .formatter
.as_ref() .as_ref()
.map(|formatter| formatter.command.as_str()); .map(|formatter| formatter.command.as_str());
check_binary(formatter); write!(stdout, "{}", check_binary(formatter))?;
for ts_feat in TsFeature::all() { for ts_feat in TsFeature::all() {
match load_runtime_file(&lang.language_id, ts_feat.runtime_filename()).is_ok() { match load_runtime_file(&lang.language_id, ts_feat.runtime_filename()).is_ok() {
true => column("", Color::Green), true => write!(stdout, "{}", color(fit(""), Color::Green))?,
false => column("", Color::Red), false => write!(stdout, "{}", color(fit(""), Color::Red))?,
} }
} }
writeln!(stdout)?; writeln!(stdout)?;
for cmd in cmds { for cmd in cmds {
column("", Color::Reset); write!(stdout, "{}", fit(""))?;
check_binary(Some(cmd)); check_binary(Some(cmd));
writeln!(stdout)?; writeln!(stdout)?;
} }