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 | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 78b51939..dbf25e60 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -1,11 +1,14 @@ 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::Write}; +use std::{ + collections::HashSet, + io::{IsTerminal, Write}, +}; +use termina::{ + style::{ColorSpec, StyleExt as _, Stylized}, + Terminal as _, +}; #[derive(Copy, Clone)] pub enum TsFeature { @@ -183,21 +186,24 @@ fn languages(selection: Option<HashSet<String>>) -> std::io::Result<()> { headings.push(feat.short_title()) } - let terminal_cols = crossterm::terminal::size().map(|(c, _)| c).unwrap_or(80); + let terminal_cols = termina::PlatformTerminal::new() + .and_then(|terminal| terminal.get_dimensions()) + .map(|size| size.cols) + .unwrap_or(80); let column_width = terminal_cols as usize / headings.len(); - let is_terminal = std::io::stdout().is_tty(); + let is_terminal = std::io::stdout().is_terminal(); - let fit = |s: &str| -> StyledContent<String> { + let fit = |s: &str| -> Stylized<'static> { format!( "{:column_width$}", s.get(..column_width - 2) .map(|s| format!("{}…", s)) .unwrap_or_else(|| s.to_string()) ) - .stylize() + .stylized() }; - 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 }; + 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 }; for heading in headings { write!(stdout, "{}", bold(fit(heading)))?; @@ -210,10 +216,10 @@ 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)), Color::Green), - Err(_) => color(fit(&format!("✘ {}", name)), Color::Red), + Ok(_) => color(fit(&format!("✓ {}", name)), ColorSpec::BRIGHT_GREEN), + Err(_) => color(fit(&format!("✘ {}", name)), ColorSpec::BRIGHT_RED), }, - None => color(fit("None"), Color::Yellow), + None => color(fit("None"), ColorSpec::BRIGHT_YELLOW), }; let check_binary = |cmd: Option<&str>| check_binary_with_name(cmd.map(|cmd| (cmd, cmd))); @@ -247,8 +253,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("✓"), Color::Green))?, - false => write!(stdout, "{}", color(fit("✘"), Color::Red))?, + true => write!(stdout, "{}", color(fit("✓"), ColorSpec::BRIGHT_GREEN))?, + false => write!(stdout, "{}", color(fit("✘"), ColorSpec::BRIGHT_RED))?, } } |