Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/health.rs')
| -rw-r--r-- | helix-term/src/health.rs | 93 |
1 files changed, 21 insertions, 72 deletions
diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 52112bf9..180e0652 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -1,33 +1,22 @@ use crate::config::{Config, ConfigLoadError}; +use crossterm::{ + style::{Color, StyledContent, Stylize}, + tty::IsTty, +}; use helix_core::config::{default_lang_config, user_lang_config}; use helix_loader::grammar::load_runtime_file; -use std::{ - collections::HashSet, - io::{IsTerminal, Write}, -}; -use termina::{ - style::{ColorSpec, StyleExt as _, Stylized}, - Terminal as _, -}; +use std::io::Write; #[derive(Copy, Clone)] pub enum TsFeature { Highlight, TextObject, AutoIndent, - Tags, - RainbowBracket, } impl TsFeature { pub fn all() -> &'static [Self] { - &[ - Self::Highlight, - Self::TextObject, - Self::AutoIndent, - Self::Tags, - Self::RainbowBracket, - ] + &[Self::Highlight, Self::TextObject, Self::AutoIndent] } pub fn runtime_filename(&self) -> &'static str { @@ -35,8 +24,6 @@ impl TsFeature { Self::Highlight => "highlights.scm", Self::TextObject => "textobjects.scm", Self::AutoIndent => "indents.scm", - Self::Tags => "tags.scm", - Self::RainbowBracket => "rainbows.scm", } } @@ -45,8 +32,6 @@ impl TsFeature { Self::Highlight => "Syntax Highlighting", Self::TextObject => "Treesitter Textobjects", Self::AutoIndent => "Auto Indent", - Self::Tags => "Code Navigation Tags", - Self::RainbowBracket => "Rainbow Brackets", } } @@ -55,8 +40,6 @@ impl TsFeature { Self::Highlight => "Highlight", Self::TextObject => "Textobject", Self::AutoIndent => "Indent", - Self::Tags => "Tags", - Self::RainbowBracket => "Rainbow", } } } @@ -151,15 +134,6 @@ pub fn clipboard() -> std::io::Result<()> { } pub fn languages_all() -> std::io::Result<()> { - languages(None) -} - -pub fn languages_selection() -> std::io::Result<()> { - let selection = helix_loader::grammar::get_grammar_names().unwrap_or_default(); - languages(selection) -} - -fn languages(selection: Option<HashSet<String>>) -> std::io::Result<()> { let stdout = std::io::stdout(); let mut stdout = stdout.lock(); @@ -186,24 +160,21 @@ fn languages(selection: Option<HashSet<String>>) -> std::io::Result<()> { headings.push(feat.short_title()) } - let terminal_cols = termina::PlatformTerminal::new() - .and_then(|terminal| terminal.get_dimensions()) - .map(|size| size.cols) - .unwrap_or(80); + 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_terminal(); + let is_terminal = std::io::stdout().is_tty(); - let fit = |s: &str| -> Stylized<'static> { + let fit = |s: &str| -> StyledContent<String> { format!( "{:column_width$}", s.get(..column_width - 2) .map(|s| format!("{}…", s)) .unwrap_or_else(|| s.to_string()) ) - .stylized() + .stylize() }; - let color = |s: Stylized<'static>, c: ColorSpec| if is_terminal { s.foreground(c) } else { s }; - let bold = |s: Stylized<'static>| if is_terminal { s.bold() } else { s }; + 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 { write!(stdout, "{}", bold(fit(heading)))?; @@ -216,22 +187,15 @@ fn languages(selection: Option<HashSet<String>>) -> std::io::Result<()> { let check_binary_with_name = |cmd: Option<(&str, &str)>| match cmd { Some((name, cmd)) => match helix_stdx::env::which(cmd) { - Ok(_) => color(fit(&format!("✓ {}", name)), ColorSpec::BRIGHT_GREEN), - Err(_) => color(fit(&format!("✘ {}", name)), ColorSpec::BRIGHT_RED), + Ok(_) => color(fit(&format!("✓ {}", name)), Color::Green), + Err(_) => color(fit(&format!("✘ {}", name)), Color::Red), }, - None => color(fit("None"), ColorSpec::BRIGHT_YELLOW), + None => color(fit("None"), Color::Yellow), }; let check_binary = |cmd: Option<&str>| check_binary_with_name(cmd.map(|cmd| (cmd, cmd))); for lang in &syn_loader_conf.language { - if selection - .as_ref() - .is_some_and(|s| !s.contains(&lang.language_id)) - { - continue; - } - write!(stdout, "{}", fit(&lang.language_id))?; let mut cmds = lang.language_servers.iter().filter_map(|ls| { @@ -253,8 +217,8 @@ fn languages(selection: Option<HashSet<String>>) -> std::io::Result<()> { for ts_feat in TsFeature::all() { match load_runtime_file(&lang.language_id, ts_feat.runtime_filename()).is_ok() { - true => write!(stdout, "{}", color(fit("✓"), ColorSpec::BRIGHT_GREEN))?, - false => write!(stdout, "{}", color(fit("✘"), ColorSpec::BRIGHT_RED))?, + true => write!(stdout, "{}", color(fit("✓"), Color::Green))?, + false => write!(stdout, "{}", color(fit("✘"), Color::Red))?, } } @@ -266,14 +230,6 @@ fn languages(selection: Option<HashSet<String>>) -> std::io::Result<()> { } } - if selection.is_some() { - writeln!( - stdout, - "\nThis list is filtered according to the 'use-grammars' option in languages.toml file.\n\ - To see the full list, use the '--health all' or '--health all-languages' option." - )?; - } - Ok(()) } @@ -365,8 +321,8 @@ fn probe_parser(grammar_name: &str) -> std::io::Result<()> { write!(stdout, "Tree-sitter parser: ")?; match helix_loader::grammar::get_language(grammar_name) { - Ok(Some(_)) => writeln!(stdout, "{}", "✓".green()), - Ok(None) | Err(_) => writeln!(stdout, "{}", "None".yellow()), + Ok(_) => writeln!(stdout, "{}", "✓".green()), + Err(_) => writeln!(stdout, "{}", "None".yellow()), } } @@ -435,16 +391,9 @@ fn probe_treesitter_feature(lang: &str, feature: TsFeature) -> std::io::Result<( pub fn print_health(health_arg: Option<String>) -> std::io::Result<()> { match health_arg.as_deref() { - Some("languages") => languages_selection()?, - Some("all-languages") => languages_all()?, + Some("languages") => languages_all()?, Some("clipboard") => clipboard()?, - None => { - general()?; - clipboard()?; - writeln!(std::io::stdout().lock())?; - languages_selection()?; - } - Some("all") => { + None | Some("all") => { general()?; clipboard()?; writeln!(std::io::stdout().lock())?; |