use std::io;
use crossterm::style::Color;
use super::terminal::Terminal;
pub use super::command_checker::CheckerEnv;
#[allow(unused_imports)]
pub use super::command_checker::{CommandChecker, CommandExistence};
pub use super::highlight_scanner::HighlightScanner;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HighlightStyle {
Default,
Keyword,
Operator,
Redirect,
String,
DoubleString,
Variable,
CommandSub,
ArithSub,
Comment,
CommandValid,
CommandInvalid,
IoNumber,
Assignment,
Tilde,
Error,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ColorSpan {
pub start: usize,
pub end: usize,
pub style: HighlightStyle,
}
pub fn apply_style<T: Terminal>(term: &mut T, style: HighlightStyle) -> io::Result<()> {
match style {
HighlightStyle::Default => {
}
HighlightStyle::Keyword => {
term.set_bold(true)?;
term.set_fg_color(Color::Magenta)?;
}
HighlightStyle::Operator | HighlightStyle::Redirect => {
term.set_fg_color(Color::Cyan)?;
}
HighlightStyle::String | HighlightStyle::DoubleString => {
term.set_fg_color(Color::Yellow)?;
}
HighlightStyle::Variable | HighlightStyle::Tilde => {
term.set_bold(true)?;
term.set_fg_color(Color::Green)?;
}
HighlightStyle::CommandSub | HighlightStyle::ArithSub => {
term.set_bold(true)?;
term.set_fg_color(Color::Yellow)?;
}
HighlightStyle::Comment => {
term.set_dim(true)?;
}
HighlightStyle::CommandValid => {
term.set_bold(true)?;
term.set_fg_color(Color::Green)?;
}
HighlightStyle::CommandInvalid => {
term.set_bold(true)?;
term.set_fg_color(Color::Red)?;
}
HighlightStyle::IoNumber | HighlightStyle::Assignment => {
term.set_fg_color(Color::Blue)?;
}
HighlightStyle::Error => {
term.set_fg_color(Color::Red)?;
term.set_underline(true)?;
}
}
Ok(())
}