brewery

beer

public

A terminal worth pouring time into

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/beer.git
crates/beer-protocols/src/style.rsRust84 lines2.2 KB
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
36
/// 9/1000-1003).
37
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
38
pub enum MouseProtocol {
39
  /// No reporting; the pointer drives local selection/scroll.
40
  #[default]
41
  Off,
42
  /// X10 (9): button presses only.
43
  X10,
44
  /// Normal (1000): button press and release.
45
  Normal,
46
  /// Button-event (1002): press, release, and motion while a button is held.
47
  Button,
48
  /// Any-event (1003): press, release, and all pointer motion.
49
  Any,
50
}
51
52
/// How mouse events are framed on the wire (default byte form, UTF-8, or SGR).
53
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
54
pub enum MouseEncoding {
55
  /// Legacy `CSI M Cb Cx Cy`, each value a byte offset by 32 (<= 223).
56
  #[default]
57
  X10,
58
  /// As X10 but coordinates above 95 are UTF-8 encoded (DECSET 1005).
59
  Utf8,
60
  /// `CSI < Cb ; Cx ; Cy M/m`, decimal and unbounded (DECSET 1006).
61
  Sgr,
62
}
63
64
/// Shell-integration prompt mark on a line (OSC 133): the start of a prompt,
65
/// the start of typed command input, the start of command output, or the line
66
/// where the command finished.
67
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
68
pub enum PromptKind {
69
  PromptStart,
70
  CmdStart,
71
  OutputStart,
72
  CmdEnd,
73
}
74
75
/// Map an OSC 133 mark letter (`A`/`B`/`C`/`D`) to a [`PromptKind`].
76
pub fn prompt_kind(b: u8) -> Option<PromptKind> {
77
  match b {
78
    b'A' => Some(PromptKind::PromptStart),
79
    b'B' => Some(PromptKind::CmdStart),
80
    b'C' => Some(PromptKind::OutputStart),
81
    b'D' => Some(PromptKind::CmdEnd),
82
    _ => None,
83
  }
84
}