unicode_rs/unicode/
editor.rs

1//! Editor-specific Unicode characters
2//! Characters for editor functionality like cursors, selections, etc.
3
4use super::{UnicodeProvider, UnicodeTheme};
5
6/// Editor cursor types
7#[derive(Debug, Clone, Copy)]
8pub enum Cursor {
9    /// Text cursor
10    Text,
11    /// Block cursor
12    Block,
13    /// Underline cursor
14    Underline,
15    /// Vertical bar cursor
16    VerticalBar,
17}
18
19impl UnicodeProvider for Cursor {
20    fn get_char(&self, theme: UnicodeTheme) -> char {
21        match (self, theme) {
22            (Cursor::Text, UnicodeTheme::Minimal) => '|',
23            (Cursor::Text, UnicodeTheme::Basic) => '│',
24            (Cursor::Text, UnicodeTheme::Rich) => '│',
25            (Cursor::Text, UnicodeTheme::Fancy) => '┃',
26
27            (Cursor::Block, UnicodeTheme::Minimal) => '#',
28            (Cursor::Block, UnicodeTheme::Basic) => '█',
29            (Cursor::Block, UnicodeTheme::Rich) => '█',
30            (Cursor::Block, UnicodeTheme::Fancy) => '█',
31
32            (Cursor::Underline, UnicodeTheme::Minimal) => '_',
33            (Cursor::Underline, UnicodeTheme::Basic) => '▁',
34            (Cursor::Underline, UnicodeTheme::Rich) => '▁',
35            (Cursor::Underline, UnicodeTheme::Fancy) => '▁',
36
37            (Cursor::VerticalBar, UnicodeTheme::Minimal) => '|',
38            (Cursor::VerticalBar, UnicodeTheme::Basic) => '▎',
39            (Cursor::VerticalBar, UnicodeTheme::Rich) => '▎',
40            (Cursor::VerticalBar, UnicodeTheme::Fancy) => '▎',
41        }
42    }
43}
44
45/// Editor selection indicators
46#[derive(Debug, Clone, Copy)]
47pub enum Selection {
48    /// Primary selection
49    Primary,
50    /// Secondary selection
51    Secondary,
52    /// Selection start
53    Start,
54    /// Selection end
55    End,
56}
57
58impl UnicodeProvider for Selection {
59    fn get_char(&self, theme: UnicodeTheme) -> char {
60        match (self, theme) {
61            (Selection::Primary, UnicodeTheme::Minimal) => '*',
62            (Selection::Primary, UnicodeTheme::Basic) => '●',
63            (Selection::Primary, UnicodeTheme::Rich) => '●',
64            (Selection::Primary, UnicodeTheme::Fancy) => '🔴',
65
66            (Selection::Secondary, UnicodeTheme::Minimal) => 'o',
67            (Selection::Secondary, UnicodeTheme::Basic) => '○',
68            (Selection::Secondary, UnicodeTheme::Rich) => '○',
69            (Selection::Secondary, UnicodeTheme::Fancy) => '⚪',
70
71            (Selection::Start, UnicodeTheme::Minimal) => '[',
72            (Selection::Start, UnicodeTheme::Basic) => '⟨',
73            (Selection::Start, UnicodeTheme::Rich) => '⟨',
74            (Selection::Start, UnicodeTheme::Fancy) => '⟨',
75
76            (Selection::End, UnicodeTheme::Minimal) => ']',
77            (Selection::End, UnicodeTheme::Basic) => '⟩',
78            (Selection::End, UnicodeTheme::Rich) => '⟩',
79            (Selection::End, UnicodeTheme::Fancy) => '⟩',
80        }
81    }
82}
83
84/// Convenience constants for editor elements
85pub mod chars {
86    use super::*;
87
88    // Cursors
89    pub const TEXT_CURSOR: Cursor = Cursor::Text;
90    pub const BLOCK_CURSOR: Cursor = Cursor::Block;
91    pub const UNDERLINE_CURSOR: Cursor = Cursor::Underline;
92    pub const VERTICAL_BAR_CURSOR: Cursor = Cursor::VerticalBar;
93
94    // Selections
95    pub const PRIMARY_SELECTION: Selection = Selection::Primary;
96    pub const SECONDARY_SELECTION: Selection = Selection::Secondary;
97    pub const SELECTION_START: Selection = Selection::Start;
98    pub const SELECTION_END: Selection = Selection::End;
99}