television_previewers/ansi/
code.rsuse tui::style::Color;
#[derive(Debug, PartialEq, Clone)]
#[non_exhaustive]
pub enum AnsiCode {
Reset,
Bold,
Faint,
Italic,
Underline,
SlowBlink,
RapidBlink,
Reverse,
Conceal,
CrossedOut,
PrimaryFont,
AlternateFont,
#[allow(dead_code)]
AlternateFonts(u8), Fraktur,
BoldOff,
Normal,
NotItalic,
UnderlineOff,
BlinkOff,
InvertOff,
Reveal,
CrossedOutOff,
ForegroundColor(Color), SetForegroundColor,
DefaultForegroundColor,
BackgroundColor(Color), SetBackgroundColor,
DefaultBackgroundColor, Code(Vec<u8>),
}
impl From<u8> for AnsiCode {
fn from(code: u8) -> Self {
match code {
0 => AnsiCode::Reset,
1 => AnsiCode::Bold,
2 => AnsiCode::Faint,
3 => AnsiCode::Italic,
4 => AnsiCode::Underline,
5 => AnsiCode::SlowBlink,
6 => AnsiCode::RapidBlink,
7 => AnsiCode::Reverse,
8 => AnsiCode::Conceal,
9 => AnsiCode::CrossedOut,
10 => AnsiCode::PrimaryFont,
11 => AnsiCode::AlternateFont,
20 => AnsiCode::Fraktur,
21 => AnsiCode::BoldOff,
22 => AnsiCode::Normal,
23 => AnsiCode::NotItalic,
24 => AnsiCode::UnderlineOff,
25 => AnsiCode::BlinkOff,
27 => AnsiCode::InvertOff,
28 => AnsiCode::Reveal,
29 => AnsiCode::CrossedOutOff,
30 => AnsiCode::ForegroundColor(Color::Black),
31 => AnsiCode::ForegroundColor(Color::Red),
32 => AnsiCode::ForegroundColor(Color::Green),
33 => AnsiCode::ForegroundColor(Color::Yellow),
34 => AnsiCode::ForegroundColor(Color::Blue),
35 => AnsiCode::ForegroundColor(Color::Magenta),
36 => AnsiCode::ForegroundColor(Color::Cyan),
37 => AnsiCode::ForegroundColor(Color::Gray),
38 => AnsiCode::SetForegroundColor,
39 => AnsiCode::DefaultForegroundColor,
40 => AnsiCode::BackgroundColor(Color::Black),
41 => AnsiCode::BackgroundColor(Color::Red),
42 => AnsiCode::BackgroundColor(Color::Green),
43 => AnsiCode::BackgroundColor(Color::Yellow),
44 => AnsiCode::BackgroundColor(Color::Blue),
45 => AnsiCode::BackgroundColor(Color::Magenta),
46 => AnsiCode::BackgroundColor(Color::Cyan),
47 => AnsiCode::BackgroundColor(Color::Gray),
48 => AnsiCode::SetBackgroundColor,
49 => AnsiCode::DefaultBackgroundColor,
90 => AnsiCode::ForegroundColor(Color::DarkGray),
91 => AnsiCode::ForegroundColor(Color::LightRed),
92 => AnsiCode::ForegroundColor(Color::LightGreen),
93 => AnsiCode::ForegroundColor(Color::LightYellow),
94 => AnsiCode::ForegroundColor(Color::LightBlue),
95 => AnsiCode::ForegroundColor(Color::LightMagenta),
96 => AnsiCode::ForegroundColor(Color::LightCyan),
#[allow(clippy::match_same_arms)]
97 => AnsiCode::ForegroundColor(Color::White),
100 => AnsiCode::BackgroundColor(Color::DarkGray),
101 => AnsiCode::BackgroundColor(Color::LightRed),
102 => AnsiCode::BackgroundColor(Color::LightGreen),
103 => AnsiCode::BackgroundColor(Color::LightYellow),
104 => AnsiCode::BackgroundColor(Color::LightBlue),
105 => AnsiCode::BackgroundColor(Color::LightMagenta),
106 => AnsiCode::BackgroundColor(Color::LightCyan),
107 => AnsiCode::ForegroundColor(Color::White),
code => AnsiCode::Code(vec![code]),
}
}
}