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
//! Cleanroom Rust port of upstream Go source file: `cursor.go`
//! Upstream Target Tag / Version: `v2.0.8`
//!
//! <public-docs>
//! # Cursor Position & Shape
//!
//! Terminal cursor position structures, shape definitions, and position query requests.
//! </public-docs>
use crate::color::Color;
use crate::model::Cmd;
/// Position represents a position in the terminal.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Position {
/// X coordinate (column).
pub x: usize,
/// Y coordinate (row).
pub y: usize,
}
/// CursorPositionMsg represents the terminal cursor position.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CursorPositionMsg {
/// X coordinate (column).
pub x: usize,
/// Y coordinate (row).
pub y: usize,
}
/// CursorShape represents a terminal cursor shape.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CursorShape {
/// Block cursor shape.
CursorBlock,
/// Underline cursor shape.
CursorUnderline,
/// Bar cursor shape.
CursorBar,
}
/// Cursor configuration for a View.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Cursor {
/// Cursor position.
pub position: Position,
/// Cursor shape.
pub shape: CursorShape,
/// Whether cursor is blinking.
pub blink: bool,
/// Cursor color.
pub color: Option<Color>,
}
impl Cursor {
/// <upstream-comment>NewCursor returns a new cursor with the default settings and the given
/// position.</upstream-comment>
pub fn new(x: usize, y: usize) -> Cursor {
Cursor {
position: Position { x, y },
shape: CursorShape::CursorBlock,
blink: true,
color: None,
}
}
}
/// RequestCursorPosMsg is a message that requests the cursor position.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RequestCursorPosMsg;
/// RequestCursorPosition is a command that requests the cursor position.
/// The cursor position will be sent as a [`CursorPositionMsg`] message.
pub fn request_cursor_position() -> Cmd {
Some(Box::new(|| Some(Box::new(RequestCursorPosMsg))))
}