1use std::sync::atomic::{AtomicU64, Ordering};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum CursorType {
5 TerminalCursor,
6 RenderedCursor,
7}
8
9impl TryFrom<u64> for CursorType {
10 type Error = ();
11
12 fn try_from(value: u64) -> Result<Self, Self::Error> {
13 Ok(match value {
14 0 => CursorType::TerminalCursor,
15 1 => CursorType::RenderedCursor,
16 _ => return Err(()),
17 })
18 }
19}
20
21static CURSOR_TYPE: AtomicU64 = AtomicU64::new(CursorType::TerminalCursor as u64);
22
23pub fn set_cursor_type(c: CursorType) {
24 CURSOR_TYPE.store(c as u64, Ordering::Release);
25}
26
27pub fn cursor_type() -> CursorType {
28 let cursor_type = CURSOR_TYPE.load(Ordering::Acquire);
29 cursor_type.try_into().expect("cursor-type")
30}