| 1 | //! The protocol vocabulary: the enums an SGR/DECSET stream selects, shared by |
| 2 | //! the parser, the grid model, and the renderer. |
| 3 | |
| 4 | /// A cell colour: terminal default, a palette index, or direct RGB (SGR 30-49, |
| 5 | /// 90-107, and the `38`/`48`/`58` extended forms). |
| 6 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Default)] |
| 7 | pub enum Color { |
| 8 | #[default] |
| 9 | Default, |
| 10 | Indexed(u8), |
| 11 | Rgb(u8, u8, u8), |
| 12 | } |
| 13 | |
| 14 | /// Underline style (SGR 4 / 4:x / 21). |
| 15 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Default)] |
| 16 | pub enum Underline { |
| 17 | #[default] |
| 18 | None, |
| 19 | Single, |
| 20 | Double, |
| 21 | Curly, |
| 22 | Dotted, |
| 23 | Dashed, |
| 24 | } |
| 25 | |
| 26 | /// Cursor shape (DECSCUSR, `CSI Ps SP q`). |
| 27 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Default)] |
| 28 | pub enum CursorShape { |
| 29 | #[default] |
| 30 | Block, |
| 31 | Underline, |
| 32 | Beam, |
| 33 | } |
| 34 | |
| 35 | /// Which mouse events the application has asked to receive (DECSET 9/1000-1003). |
| 36 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Default)] |
| 37 | pub enum MouseProtocol { |
| 38 | /// No reporting; the pointer drives local selection/scroll. |
| 39 | #[default] |
| 40 | Off, |
| 41 | /// X10 (9): button presses only. |
| 42 | X10, |
| 43 | /// Normal (1000): button press and release. |
| 44 | Normal, |
| 45 | /// Button-event (1002): press, release, and motion while a button is held. |
| 46 | Button, |
| 47 | /// Any-event (1003): press, release, and all pointer motion. |
| 48 | Any, |
| 49 | } |
| 50 | |
| 51 | /// How mouse events are framed on the wire (default byte form, UTF-8, or SGR). |
| 52 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Default)] |
| 53 | pub enum MouseEncoding { |
| 54 | /// Legacy `CSI M Cb Cx Cy`, each value a byte offset by 32 (<= 223). |
| 55 | #[default] |
| 56 | X10, |
| 57 | /// As X10 but coordinates above 95 are UTF-8 encoded (DECSET 1005). |
| 58 | Utf8, |
| 59 | /// `CSI < Cb ; Cx ; Cy M/m`, decimal and unbounded (DECSET 1006). |
| 60 | Sgr, |
| 61 | } |
| 62 | |
| 63 | /// Shell-integration prompt mark on a line (OSC 133): the start of a prompt, |
| 64 | /// the start of typed command input, the start of command output, or the line |
| 65 | /// where the command finished. |
| 66 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 67 | pub enum PromptKind { |
| 68 | PromptStart, |
| 69 | CmdStart, |
| 70 | OutputStart, |
| 71 | CmdEnd, |
| 72 | } |
| 73 | |
| 74 | /// Map an OSC 133 mark letter (`A`/`B`/`C`/`D`) to a [`PromptKind`]. |
| 75 | pub fn prompt_kind(b: u8) -> Option<PromptKind> { |
| 76 | match b { |
| 77 | b'A' => Some(PromptKind::PromptStart), |
| 78 | b'B' => Some(PromptKind::CmdStart), |
| 79 | b'C' => Some(PromptKind::OutputStart), |
| 80 | b'D' => Some(PromptKind::CmdEnd), |
| 81 | _ => None, |
| 82 | } |
| 83 | } |