uncurses/screen/cursor.rs
1//! Cursor shape selection for the [`Screen`](super::Screen) facade.
2//!
3//! The facade exposes the cursor as a shape plus a separate blinking flag,
4//! rather than the underlying DECSCUSR codes which interleave the two. A
5//! shape and blinking flag map to one of the underlying cursor styles.
6
7use crate::ansi::cursor::CursorStyle;
8
9/// The visual shape of the text cursor, independent of whether it blinks.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
11pub enum CursorShape {
12 /// A full-cell block.
13 #[default]
14 Block,
15 /// A horizontal underline at the bottom of the cell.
16 Underline,
17 /// A vertical bar at the left of the cell.
18 Bar,
19}
20
21impl CursorShape {
22 /// Map a shape and blinking flag to the underlying cursor style.
23 pub(super) fn style(self, blinking: bool) -> CursorStyle {
24 match (self, blinking) {
25 (CursorShape::Block, true) => CursorStyle::BlinkingBlock,
26 (CursorShape::Block, false) => CursorStyle::SteadyBlock,
27 (CursorShape::Underline, true) => CursorStyle::BlinkingUnderline,
28 (CursorShape::Underline, false) => CursorStyle::SteadyUnderline,
29 (CursorShape::Bar, true) => CursorStyle::BlinkingBar,
30 (CursorShape::Bar, false) => CursorStyle::SteadyBar,
31 }
32 }
33}