返回 CodeWhale
glyphs.rs
1 //! Codewhale's terminal glyph charter.
2 //!
3 //! Renderers use semantic names from this module instead of choosing visual
4 //! punctuation ad hoc. The solid current marker (`●`) is the recurring
5 //! Codewhale anchor: it marks the active speaker or current human choice.
6 //! ASCII-safe terminals receive the semantic fallback from the same owner.
7 //!
8 //! Extracted from the Codewhale engine's `crates/tui/src/tui/glyphs.rs`
9 //! (`Hmbown/CodeWhale` `58b1dd3dd`, last changed in `d7712814e`). One meaning
10 //! per glyph: `●` current or running, `✓` done, `✕` failed, `◆` needs you,
11 //! `○` ready, `■` stopped, `▸` selection, `?` unknown.
12
13 /// Current speaker or current human choice — the recurring identity anchor.
14 pub const CURRENT: &str = "●";
15 /// Available but not current.
16 pub const AVAILABLE: &str = "○";
17 /// Keyboard/list selection pointer.
18 pub const SELECTION: &str = "▸";
19 /// Finished user-authored message marker.
20 pub const USER: &str = "▎";
21 /// Transcript continuation rail, including its authored trailing space.
22 pub const TRANSCRIPT_RAIL: &str = "▏ ";
23 /// Settled successful state.
24 pub const DONE: &str = "✓";
25 /// Settled failed state.
26 pub const FAILED: &str = "✕";
27 /// State that needs human attention.
28 pub const ATTENTION: &str = "◆";
29 /// Ready but not active.
30 pub const READY: &str = "○";
31 /// Paused work.
32 pub const PAUSED: &str = "⏸";
33 /// Stopped by a person, or cancelled.
34 pub const STOPPED: &str = "■";
35 /// A state nobody reported. Never shown as a failure.
36 pub const UNKNOWN: &str = "?";
37 /// Blocked state waiting on a hard precondition or external gate.
38 pub const BLOCKED: &str = "⊘";
39 /// Resting state between active runs.
40 pub const RESTING: &str = "◡";
41 /// Asleep or suspended state.
42 pub const ASLEEP: &str = "☾";
43 /// The one ellipsis.
44 pub const ELLIPSIS: &str = "…";
45 /// Typographic minus sign for signed numbers and diffs.
46 pub const MINUS: &str = "\u{2212}";
47 /// Fleet role marks share the same charter while retaining distinct shapes.
48 pub const ROLE_MANAGER: &str = "◆";
49 pub const ROLE_BUILDER: &str = "■";
50 pub const ROLE_REVIEWER: &str = "◇";
51 pub const ROLE_VERIFIER: &str = CURRENT;
52 pub const ROLE_SYNTHESIZER: &str = "▲";
53 pub const NEUTRAL: &str = "·";
54
55 #[must_use]
56 pub const fn selection_marker(selected: bool) -> &'static str {
57 if selected { SELECTION } else { " " }
58 }
59
60 /// `symbol`, or its ASCII fallback when `ascii` is set. Symbols without a
61 /// fallback are returned unchanged.
62 #[must_use]
63 pub fn pick(symbol: &'static str, ascii: bool) -> &'static str {
64 if ascii {
65 ascii_fallback(symbol).unwrap_or(symbol)
66 } else {
67 symbol
68 }
69 }
70
71 /// Reduce a single Codewhale-authored decorative glyph to narrow ASCII.
72 /// Language text and model/user content are intentionally outside this map.
73 #[must_use]
74 pub fn ascii_fallback(symbol: &str) -> Option<&'static str> {
75 match symbol {
76 "─" | "━" | "═" | "╌" | "╍" | "┄" | "┅" | "┈" | "┉" | "—" | "–" | "\u{2212}" => {
77 Some("-")
78 }
79 "│" | "┃" | "║" | "╎" | "╏" | "▏" | "▎" | "▍" | "▌" | "▐" | "▕" => {
80 Some("|")
81 }
82 "┌" | "┐" | "└" | "┘" | "╭" | "╮" | "╰" | "╯" | "├" | "┤" | "┬" | "┴" | "┼" => {
83 Some("+")
84 }
85 "█" | "▉" | "▊" | "▋" | "▀" | "▄" | "▅" | "▆" | "▇" | "▙" | "▛" | "▜" | "▟" | "▰" => {
86 Some("#")
87 }
88 "▁" | "▂" | "▃" => Some("_"),
89 // Tideline action glyphs (spec §2): one cell each, no wide glyphs.
90 "⌁" => Some("+"),
91 "⚙" => Some("*"),
92 "↺" => Some("<"),
93 "▤" => Some("="),
94 "◐" => Some("*"),
95 "⑂" => Some("y"),
96 "∼" | "∿" => Some("~"),
97 "⋯" => Some("."),
98 "▖" | "▗" | "▘" | "▝" => Some("."),
99 "▚" => Some("\\"),
100 "▞" => Some("/"),
101 "░" | "▒" | "▓" => Some(":"),
102 "▱" => Some("-"),
103 "▶" | "▷" | "▸" | "›" | "❯" | "→" | "↗" | "↘" | "»" => Some(">"),
104 "◀" | "◂" | "‹" | "❮" | "←" | "↖" | "↙" | "«" => Some("<"),
105 "▼" | "▾" | "▽" | "↓" => Some("v"),
106 "▲" | "△" | "↑" => Some("^"),
107 "◆" | "◇" | "♦" | "✦" | "◍" | "◉" | "★" | "☆" => Some("*"),
108 "■" | "□" | "▪" | "▫" | "◼" | "◻" => Some("#"),
109 // Filled marks stay a dot; hollow ones become `o` so CURRENT and
110 // AVAILABLE stay distinguishable on ASCII terminals.
111 "●" | "∘" | "•" | "·" => Some("."),
112 "○" | "☐" | "◌" | "˚" | "°" | "◦" => Some("o"),
113 "✓" | "✔" | "☑" => Some("Y"),
114 "✕" | "×" | "✗" | "✘" | "☒" => Some("X"),
115 "⊘" => Some("!"),
116 "◡" => Some("~"),
117 "☾" => Some("z"),
118 "⏸" => Some("="),
119 // Schedule/timer (the activity band's automation slot) — cron's `@`.
120 "⏱" => Some("@"),
121 // The launch warning line's gate glyph ("no model connected").
122 "⚠" => Some("!"),
123 // The working screen's MCP chip marker (`⋮ MCP n/m`).
124 "⋮" => Some("|"),
125 "≈≈>" => Some("~>"),
126 "≈" | "~" => Some("~"),
127 "🐳" | "🐋" => Some("w"),
128 "…" => Some("."),
129 "▏ " => Some("| "),
130 _ => None,
131 }
132 }
133
134 /// Preserve the working-bubble fill signal when Braille is unavailable.
135 #[must_use]
136 pub fn braille_ascii_fallback(ch: char) -> Option<&'static str> {
137 if !(('\u{2800}'..='\u{28FF}').contains(&ch)) {
138 return None;
139 }
140 let dots = ((ch as u32) - 0x2800).count_ones();
141 Some(match dots {
142 0 => " ",
143 1..=2 => ".",
144 3..=4 => ":",
145 5..=6 => "+",
146 _ => "#",
147 })
148 }
149
150 #[cfg(test)]
151 mod tests {
152 use super::*;
153
154 #[test]
155 fn charter_has_narrow_semantic_fallbacks() {
156 for (rich, safe) in [
157 (SELECTION, ">"),
158 ("▷", ">"),
159 (CURRENT, "."),
160 (AVAILABLE, "o"),
161 (READY, "o"),
162 ("☐", "o"),
163 ("•", "."),
164 (NEUTRAL, "."),
165 (USER, "|"),
166 (DONE, "Y"),
167 (FAILED, "X"),
168 (ATTENTION, "*"),
169 ("≈≈>", "~>"),
170 ("≈", "~"),
171 ("~", "~"),
172 ("⌁", "+"),
173 ("↺", "<"),
174 ("▤", "="),
175 ("◐", "*"),
176 ("⑂", "y"),
177 ("∼", "~"),
178 ("∿", "~"),
179 ("⋯", "."),
180 ("⏱", "@"),
181 ("🐳", "w"),
182 ("🐋", "w"),
183 (STOPPED, "#"),
184 (BLOCKED, "!"),
185 (RESTING, "~"),
186 (ASLEEP, "z"),
187 (ELLIPSIS, "."),
188 (MINUS, "-"),
189 ] {
190 assert_eq!(ascii_fallback(rich), Some(safe));
191 }
192 assert_ne!(
193 ascii_fallback(CURRENT),
194 ascii_fallback(AVAILABLE),
195 "current and available must stay distinct in ASCII"
196 );
197 assert_eq!(braille_ascii_fallback('\u{2801}'), Some("."));
198 assert_eq!(braille_ascii_fallback('A'), None);
199 }
200
201 #[test]
202 fn every_public_mark_has_an_ascii_form() {
203 for mark in [
204 CURRENT,
205 AVAILABLE,
206 SELECTION,
207 USER,
208 TRANSCRIPT_RAIL,
209 DONE,
210 FAILED,
211 ATTENTION,
212 READY,
213 PAUSED,
214 STOPPED,
215 UNKNOWN,
216 BLOCKED,
217 RESTING,
218 ASLEEP,
219 ELLIPSIS,
220 MINUS,
221 ROLE_MANAGER,
222 ROLE_BUILDER,
223 ROLE_REVIEWER,
224 ROLE_VERIFIER,
225 ROLE_SYNTHESIZER,
226 NEUTRAL,
227 selection_marker(true),
228 selection_marker(false),
229 ] {
230 let safe = pick(mark, true);
231 assert!(safe.is_ascii(), "{mark:?} -> {safe:?}");
232 assert_eq!(safe.len(), mark.chars().count(), "{mark:?} keeps its width");
233 }
234 }
235 }
236
236 lines RUST