unicode_rs/unicode/symbols.rs
1//! Symbol Unicode characters
2//!
3//! General symbols and special characters for common use cases.
4//!
5//! # Examples
6//!
7//! ```rust
8//! use unicode_rs::prelude::*;
9//!
10//! // Get a checkmark in different themes
11//! let minimal_check = Symbol::Check.get_char(UnicodeTheme::Minimal); // 'v'
12//! let rich_check = Symbol::Check.get_char(UnicodeTheme::Rich); // '✓'
13//! let fancy_check = Symbol::Check.get_char(UnicodeTheme::Fancy); // '✅'
14//!
15//! // Use with global configuration
16//! set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Rich));
17//! let check = get_char(&Symbol::Check, None); // '✓'
18//! ```
19//!
20//! # Character Reference
21//!
22//! | Symbol | Minimal | Basic | Rich | Fancy |
23//! |--------|---------|-------|------|-------|
24//! | Check | `v` | `✓` | `✓` | `✅` |
25//! | X | `X` | `✗` | `✖` | `❌` |
26//! | ! | `!` | `!` | `❗` | `❗` |
27//! | ? | `?` | `?` | `❓` | `❓` |
28
29use super::{UnicodeProvider, UnicodeTheme};
30
31/// General symbols for common UI elements and indicators
32///
33/// This enum provides access to commonly used symbols with support for different
34/// Unicode themes. Each symbol can be rendered in four different styles depending
35/// on the terminal capabilities and user preferences.
36///
37/// # Examples
38///
39/// ```rust
40/// use unicode_rs::prelude::*;
41///
42/// // Basic usage
43/// let check = Symbol::Check.get_char(UnicodeTheme::Rich);
44/// println!("Task completed {}", check); // Task completed ✓
45///
46/// // Compare themes
47/// for theme in [UnicodeTheme::Minimal, UnicodeTheme::Rich] {
48/// let symbol = Symbol::X.get_char(theme);
49/// println!("Error symbol in {:?} theme: {}", theme, symbol);
50/// }
51/// ```
52#[derive(Debug, Clone, Copy, PartialEq, Eq)]
53pub enum Symbol {
54 /// Checkmark symbol - indicates success, completion, or affirmative state
55 ///
56 /// # Theme variants
57 /// - Minimal: `v`
58 /// - Basic: `✓`
59 /// - Rich: `✓`
60 /// - Fancy: `✅`
61 Check,
62 /// X mark symbol - indicates failure, error, or negative state
63 ///
64 /// # Theme variants
65 /// - Minimal: `X`
66 /// - Basic: `✗`
67 /// - Rich: `✖`
68 /// - Fancy: `❌`
69 X,
70 /// Exclamation symbol - indicates warning or important information
71 ///
72 /// # Theme variants
73 /// - Minimal: `!`
74 /// - Basic: `!`
75 /// - Rich: `❗`
76 /// - Fancy: `❗`
77 Exclamation,
78 /// Question mark symbol - indicates uncertainty or help
79 ///
80 /// # Theme variants
81 /// - Minimal: `?`
82 /// - Basic: `?`
83 /// - Rich: `❓`
84 /// - Fancy: `❓`
85 Question,
86 /// At symbol
87 At,
88 /// Hash/pound
89 Hash,
90 /// Dollar sign
91 Dollar,
92 /// Percent
93 Percent,
94 /// Ampersand
95 Ampersand,
96 /// Copyright
97 Copyright,
98 /// Trademark
99 Trademark,
100 /// Registered
101 Registered,
102}
103
104impl UnicodeProvider for Symbol {
105 fn get_char(&self, theme: UnicodeTheme) -> char {
106 match (self, theme) {
107 (Symbol::Check, UnicodeTheme::Minimal) => 'v',
108 (Symbol::Check, UnicodeTheme::Basic) => '✓',
109 (Symbol::Check, UnicodeTheme::Rich) => '✓',
110 (Symbol::Check, UnicodeTheme::Fancy) => '✅',
111
112 (Symbol::X, UnicodeTheme::Minimal) => 'X',
113 (Symbol::X, UnicodeTheme::Basic) => '✗',
114 (Symbol::X, UnicodeTheme::Rich) => '✖',
115 (Symbol::X, UnicodeTheme::Fancy) => '❌',
116
117 (Symbol::Exclamation, UnicodeTheme::Minimal) => '!',
118 (Symbol::Exclamation, UnicodeTheme::Basic) => '!',
119 (Symbol::Exclamation, UnicodeTheme::Rich) => '❗',
120 (Symbol::Exclamation, UnicodeTheme::Fancy) => '❗',
121
122 (Symbol::Question, UnicodeTheme::Minimal) => '?',
123 (Symbol::Question, UnicodeTheme::Basic) => '?',
124 (Symbol::Question, UnicodeTheme::Rich) => '❓',
125 (Symbol::Question, UnicodeTheme::Fancy) => '❓',
126
127 (Symbol::At, _) => '@',
128 (Symbol::Hash, _) => '#',
129 (Symbol::Dollar, _) => '$',
130 (Symbol::Percent, _) => '%',
131 (Symbol::Ampersand, _) => '&',
132
133 (Symbol::Copyright, UnicodeTheme::Minimal) => 'C',
134 (Symbol::Copyright, UnicodeTheme::Basic) => '©',
135 (Symbol::Copyright, UnicodeTheme::Rich) => '©',
136 (Symbol::Copyright, UnicodeTheme::Fancy) => '©',
137
138 (Symbol::Trademark, UnicodeTheme::Minimal) => 'T',
139 (Symbol::Trademark, UnicodeTheme::Basic) => '™',
140 (Symbol::Trademark, UnicodeTheme::Rich) => '™',
141 (Symbol::Trademark, UnicodeTheme::Fancy) => '™',
142
143 (Symbol::Registered, UnicodeTheme::Minimal) => 'R',
144 (Symbol::Registered, UnicodeTheme::Basic) => '®',
145 (Symbol::Registered, UnicodeTheme::Rich) => '®',
146 (Symbol::Registered, UnicodeTheme::Fancy) => '®',
147 }
148 }
149}
150
151/// Convenience constants for symbols
152pub mod chars {
153 use super::*;
154
155 pub const CHECK: Symbol = Symbol::Check;
156 pub const X: Symbol = Symbol::X;
157 pub const EXCLAMATION: Symbol = Symbol::Exclamation;
158 pub const QUESTION: Symbol = Symbol::Question;
159 pub const AT: Symbol = Symbol::At;
160 pub const HASH: Symbol = Symbol::Hash;
161 pub const DOLLAR: Symbol = Symbol::Dollar;
162 pub const PERCENT: Symbol = Symbol::Percent;
163 pub const AMPERSAND: Symbol = Symbol::Ampersand;
164 pub const COPYRIGHT: Symbol = Symbol::Copyright;
165 pub const TRADEMARK: Symbol = Symbol::Trademark;
166 pub const REGISTERED: Symbol = Symbol::Registered;
167}