1 // use crate::color::Color; 2 use tui::style::Color; 3 4 /// This enum stores most types of ansi escape sequences 5 /// 6 /// You can turn an escape sequence to this enum variant using 7 /// from(u8) trait. 8 /// This doesn't support all of them but does support most of them. 9 10 #[derive(Debug, PartialEq)] 11 #[repr(u8)] 12 pub enum AnsiCode { 13 /// Reset the terminal 14 Reset, 15 /// Set font to bold 16 Bold, 17 /// Set font to faint 18 Faint, 19 /// Set font to italic 20 Italic, 21 /// Set font to underline 22 Underline, 23 /// Set cursor to slowblink 24 SlowBlink, 25 /// Set cursor to rapidblink 26 RapidBlink, 27 /// Invert the colors 28 Reverse, 29 /// Conceal text 30 Conceal, 31 /// Display crossed out text 32 CrossedOut, 33 /// Choose primary font 34 PrimaryFont, 35 /// Choose alternate font 36 AlternateFont, 37 /// Choose alternate fonts 1-9 38 AlternateFonts(u8), // = 11..19, // from 11 to 19 39 /// Fraktur ? No clue 40 Fraktur, 41 /// Turn off bold 42 BoldOff, 43 /// Set text to normal 44 Normal, 45 /// Turn off Italic 46 NotItalic, 47 /// Turn off underline 48 UnderlineOff, 49 /// Turn off blinking 50 BlinkOff, 51 // 26 ? 52 /// Don't invert colors 53 InvertOff, 54 /// Reveal text 55 Reveal, 56 /// Turn off Crossedout text 57 CrossedOutOff, 58 /// Set foreground color (4-bit) 59 ForegroundColor(Color), //, 31..37//Issue 60553 https://github.com/rust-lang/rust/issues/60553 60 /// Set foreground color (8-bit and 24-bit) 61 SetForegroundColor, 62 /// Default foreground color 63 DefaultForegroundColor, 64 /// Set background color (4-bit) 65 BackgroundColor(Color), // 41..47 66 /// Set background color (8-bit and 24-bit) 67 SetBackgroundColor, 68 /// Default background color 69 DefaultBackgroundColor, // 49 70 } 71 72 impl From<u8> for AnsiCode { from(code: u8) -> Self73 fn from(code: u8) -> Self { 74 match code { 75 0 => AnsiCode::Reset, 76 1 => AnsiCode::Bold, 77 2 => AnsiCode::Faint, 78 3 => AnsiCode::Italic, 79 4 => AnsiCode::Underline, 80 5 => AnsiCode::SlowBlink, 81 6 => AnsiCode::RapidBlink, 82 7 => AnsiCode::Reverse, 83 8 => AnsiCode::Conceal, 84 9 => AnsiCode::CrossedOut, 85 10 => AnsiCode::PrimaryFont, 86 11 => AnsiCode::AlternateFont, 87 // AnsiCode::// AlternateFont = 11..19, // from 11 to 19 88 20 => AnsiCode::Fraktur, 89 21 => AnsiCode::BoldOff, 90 22 => AnsiCode::Normal, 91 23 => AnsiCode::NotItalic, 92 24 => AnsiCode::UnderlineOff, 93 25 => AnsiCode::BlinkOff, 94 // 26 ? 95 27 => AnsiCode::InvertOff, 96 28 => AnsiCode::Reveal, 97 29 => AnsiCode::CrossedOutOff, 98 30 => AnsiCode::ForegroundColor(Color::Black), 99 31 => AnsiCode::ForegroundColor(Color::Red), 100 32 => AnsiCode::ForegroundColor(Color::Green), 101 33 => AnsiCode::ForegroundColor(Color::Yellow), 102 34 => AnsiCode::ForegroundColor(Color::Blue), 103 35 => AnsiCode::ForegroundColor(Color::Magenta), 104 36 => AnsiCode::ForegroundColor(Color::Cyan), 105 37 => AnsiCode::ForegroundColor(Color::Gray), 106 38 => AnsiCode::SetForegroundColor, 107 39 => AnsiCode::DefaultForegroundColor, 108 40 => AnsiCode::BackgroundColor(Color::Black), 109 41 => AnsiCode::BackgroundColor(Color::Red), 110 42 => AnsiCode::BackgroundColor(Color::Green), 111 43 => AnsiCode::BackgroundColor(Color::Yellow), 112 44 => AnsiCode::BackgroundColor(Color::Blue), 113 45 => AnsiCode::BackgroundColor(Color::Magenta), 114 46 => AnsiCode::BackgroundColor(Color::Cyan), 115 47 => AnsiCode::BackgroundColor(Color::Gray), 116 48 => AnsiCode::SetBackgroundColor, 117 49 => AnsiCode::DefaultBackgroundColor, 118 _ => AnsiCode::Reset, 119 } 120 } 121 } 122