Skip to main content

tui_test/input/
mouse.rs

1//! SGR mouse-event encoders.
2
3const CSI: &str = "\u{1b}[";
4
5/// SGR press at (x, y), 0-based; button 0=left, 1=middle, 2=right.
6pub fn down(x: u16, y: u16, button: u8) -> String {
7    format!("{CSI}<{};{};{}M", button, x + 1, y + 1)
8}
9
10/// SGR release at (x, y), 0-based.
11pub fn up(x: u16, y: u16, button: u8) -> String {
12    format!("{CSI}<{};{};{}m", button, x + 1, y + 1)
13}
14
15/// SGR motion at (x, y), 0-based (button-motion bit set).
16pub fn motion(x: u16, y: u16) -> String {
17    format!("{CSI}<35;{};{}M", x + 1, y + 1)
18}
19
20/// Scroll wheel: SGR codes 64 (up) and 65 (down).
21pub fn scroll(x: u16, y: u16, up: bool) -> String {
22    let code = if up { 64 } else { 65 };
23    format!("{CSI}<{};{};{}M", code, x + 1, y + 1)
24}
25
26/// A full click: press then release.
27pub fn click(x: u16, y: u16, button: u8) -> String {
28    format!("{}{}", down(x, y, button), up(x, y, button))
29}