1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use bitflags::bitflags;
use serde::{Deserialize, Serialize};
pub mod charset;
pub mod control;
pub mod graphics;
pub mod iterm2_image_protocol;
pub mod kitty_graphics_protocol;
pub mod kitty_virtual;
pub mod mode;
pub mod sixel;
#[derive(Default, Clone, Serialize, Deserialize, Copy, Debug, Eq, PartialEq)]
pub enum CursorShape {
/// Cursor is a block like `▒`.
#[default]
#[serde(alias = "block")]
Block,
/// Cursor is an underscore like `_`.
#[serde(alias = "underline")]
Underline,
/// Cursor is a vertical bar `⎸`.
#[serde(alias = "beam")]
Beam,
/// Cursor is hidden.
#[serde(alias = "hidden")]
Hidden,
}
impl CursorShape {
pub fn from_char(c: char) -> CursorShape {
match c {
'_' => CursorShape::Underline,
'|' => CursorShape::Beam,
_ => CursorShape::Block,
}
}
}
impl From<CursorShape> for char {
fn from(value: CursorShape) -> Self {
match value {
CursorShape::Underline => '_',
CursorShape::Beam => '|',
_ => '▇',
}
}
}
#[derive(Debug)]
pub enum ClearMode {
/// Clear below cursor.
Below,
/// Clear above cursor.
Above,
/// Clear entire terminal.
All,
/// Clear 'saved' lines (scrollback).
Saved,
}
#[derive(Debug)]
pub enum TabulationClearMode {
/// Clear stop under cursor.
Current,
/// Clear all stops.
All,
}
#[derive(Debug)]
pub enum LineClearMode {
/// Clear right of cursor.
Right,
/// Clear left of cursor.
Left,
/// Clear entire line.
All,
}
bitflags! {
/// A set of [`kitty keyboard protocol'] modes.
///
/// [`kitty keyboard protocol']: https://sw.kovidgoyal.net/kitty/keyboard-protocol
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct KeyboardModes : u8 {
/// No keyboard protocol mode is set.
const NO_MODE = 0b0000_0000;
/// Report `Esc`, `alt` + `key`, `ctrl` + `key`, `ctrl` + `alt` + `key`, `shift`
/// + `alt` + `key` keys using `CSI u` sequence instead of raw ones.
const DISAMBIGUATE_ESC_CODES = 0b0000_0001;
/// Report key presses, release, and repetition alongside the escape. Key events
/// that result in text are reported as plain UTF-8, unless the
/// [`Self::REPORT_ALL_KEYS_AS_ESC`] is enabled.
const REPORT_EVENT_TYPES = 0b0000_0010;
/// Additionally report shifted key an dbase layout key.
const REPORT_ALTERNATE_KEYS = 0b0000_0100;
/// Report every key as an escape sequence.
const REPORT_ALL_KEYS_AS_ESC = 0b0000_1000;
/// Report the text generated by the key event.
const REPORT_ASSOCIATED_TEXT = 0b0001_0000;
}
}
/// Describes how the new [`KeyboardModes`] should be applied.
#[repr(u8)]
#[derive(Default, Clone, Copy, PartialEq, Eq)]
pub enum KeyboardModesApplyBehavior {
/// Replace the active flags with the new ones.
#[default]
Replace,
/// Merge the given flags with currently active ones.
Union,
/// Remove the given flags from the active ones.
Difference,
}