blue_lang_art/lib.rs
1//! blue's mark, wordmark, and theme.
2//!
3//! # The mark is a COLOUR shift across Nord's Frost band
4//!
5//! blue's central ratified metaphor is **blueshift** — the wave that shifts with
6//! the author across tatara-lisp and Rust as a program is written.
7//! A blueshift is a shift in **colour**, so the mark
8//! is four solid cells walking Nord's own Frost band toward blue:
9//!
10//! ```text
11//! ████ nord7 → nord8 → nord9 → nord10
12//! teal cyan light deep blue
13//! ```
14//!
15//! ## What this replaced, and why
16//!
17//! The first version was `░▒▓█` — a *density* ramp, every cell painted the same
18//! `Ink::Blue`. It was wrong twice over, and the operator spotted it immediately
19//! as "a blue box":
20//!
21//! - **It rendered a shift with nothing shifting.** One flat colour across four
22//! cells varies only density, which is not what a blueshift is.
23//! - **`░▒▓` read as fuzz.** katsuji's docs say so in as many words — "reach for
24//! it deliberately, not for 'texture'" — and the first draft quoted that
25//! warning and then argued past it on the grounds that the gradient *was* the
26//! meaning. Intent does not make an illegible glyph legible. Four dither cells
27//! ending in `█`, all one colour, look like a blue box because that is what
28//! they are.
29//!
30//! Solid blocks are legible at any size, and the colour does the work the shape
31//! was failing to do.
32//!
33//! # No truecolor, deliberately
34//!
35//! The Frost tones are named by their **ANSI slot**, never by hex. katsuji has no
36//! `Ink::Rgb` and no `from_hex` on purpose: a literal `\x1b[38;2;…m` "pins a
37//! colour that stops tracking" the user's theme. Naming the slot means the mark
38//! renders in *the reader's* Nord, and follows them if they retheme.
39//!
40//! # The theme is `irodori`'s Nord, never a local copy
41//!
42//! Colours come from [`irodori`], the fleet's Nord palette. blue carries no hex:
43//! the fleet rule is that an app's visual default *derives* from the shared
44//! tokens so one edit propagates, and copying another app's palette is the named
45//! anti-pattern. What blue chooses is which Nord *roles* to bind — see [`Theme`].
46
47use irodori::{Color, NordPalette, NORD};
48use katsuji::{Attr, Crisp, Ink, Line, Piece};
49
50/// The mark: four solid cells, one per Frost tone, walking toward blue.
51///
52/// A typed array rather than a string of escapes, so the ramp cannot silently
53/// lose a step or reorder — the *progression* is the meaning.
54///
55/// Named by ANSI slot, not hex, so the mark tracks the reader's theme. Under
56/// Nord these are `nord7 → nord8 → nord9 → nord10`; mado pins `ansi[4]` to
57/// `#5E81AC` (nord10) and `ansi[6]` to `#88C0D0` (nord8), which is the fleet's
58/// own binding rather than upstream Nord's.
59pub const SHIFT: [Ink; 4] = [Ink::BrightCyan, Ink::Cyan, Ink::BrightBlue, Ink::Blue];
60
61/// The glyph every cell of the mark uses. Solid — no dither.
62pub const CELL: Crisp = Crisp::Full;
63
64/// The mark as plain text, for contexts with no colour — a README, a commit
65/// message, a browser tab.
66///
67/// **The colour is the meaning, so plain text loses it.** This returns the
68/// shape only; anywhere colour is available, use [`mark_line`].
69#[must_use]
70pub fn mark() -> String {
71 core::iter::repeat_n(CELL.ch(), SHIFT.len()).collect()
72}
73
74/// The mark as a styled line — the real thing.
75#[must_use]
76pub fn mark_line() -> Line {
77 SHIFT
78 .iter()
79 .fold(Line::new(), |l, ink| l.piece(Piece::glyph(CELL).ink(*ink)))
80}
81
82/// blue's Nord bindings.
83///
84/// ## Why `nord10` leads and `nord8` accents
85///
86/// Nord's Frost band (`nord7..nord10`) runs from teal to deep blue. The fleet's
87/// established accent is `nord8` frost-cyan — katsuji names it for links, prompt
88/// marks and scrollbars, and every fleet app inherits it.
89///
90/// blue keeps that accent, because diverging would make one app's cyan mean
91/// something different from every other app's, and binds **`nord10`
92/// (`#5E81AC`), the deep blue, as its own primary**. A language called blue
93/// whose primary was a cyan would be a name that does not match its own output.
94/// So: `nord10` is the identity, `nord8` stays the shared interaction colour.
95/// The distinction is the point — identity and interaction are different roles.
96#[derive(Clone, Copy, Debug, PartialEq, Eq)]
97pub struct Theme {
98 /// blue's own colour — Nord `nord10`, the deep frost blue.
99 pub primary: Color,
100 /// The fleet's shared accent — Nord `nord8`, frost cyan. Not blue's to
101 /// change.
102 pub accent: Color,
103 /// Nord `nord0`, Polar Night.
104 pub background: Color,
105 /// Nord `nord6`, Snow Storm.
106 pub foreground: Color,
107 /// Nord `nord3`, for de-emphasis.
108 pub dim: Color,
109}
110
111/// The Nord indices blue binds. Named so a reader can check the choice against
112/// the palette without counting positions.
113const NORD_PRIMARY: usize = 10;
114const NORD_ACCENT: usize = 8;
115const NORD_BACKGROUND: usize = 0;
116const NORD_FOREGROUND: usize = 6;
117const NORD_DIM: usize = 3;
118
119impl Theme {
120 /// blue's theme, derived from a Nord palette.
121 ///
122 /// Takes the palette rather than reading the global so a consumer can pass a
123 /// customised one and still get blue's *role bindings* — the thing blue
124 /// owns — applied to it.
125 #[must_use]
126 pub fn from_palette(p: &NordPalette) -> Self {
127 // `get` returns Option; a missing index would mean the palette is not
128 // Nord. Falling back to the canonical NORD keeps this total without
129 // inventing a colour.
130 let at = |i: usize| {
131 p.get(i)
132 .or_else(|| NORD.get(i))
133 .unwrap_or(Color::new(0, 0, 0))
134 };
135 Self {
136 primary: at(NORD_PRIMARY),
137 accent: at(NORD_ACCENT),
138 background: at(NORD_BACKGROUND),
139 foreground: at(NORD_FOREGROUND),
140 dim: at(NORD_DIM),
141 }
142 }
143
144 /// blue's theme over the canonical fleet Nord.
145 #[must_use]
146 pub fn fleet() -> Self {
147 Self::from_palette(&NORD)
148 }
149}
150
151impl Default for Theme {
152 fn default() -> Self {
153 Self::fleet()
154 }
155}
156
157/// The wordmark: the blueshift ramp, the name, and the running version.
158///
159/// `version` is passed in, never written here — a literal would be a second
160/// place to update, and mado records that exact drift shipping a `0.1.0`
161/// wordmark against a `0.1.98` binary.
162#[must_use]
163pub fn wordmark(version: &str) -> Vec<Line> {
164 vec![
165 // The shift, then the name. One accent slot, gaps doing the spacing —
166 // the restraint mado's banner establishes.
167 SHIFT
168 .iter()
169 .fold(Line::new(), |l, ink| l.piece(Piece::glyph(CELL).ink(*ink)))
170 .piece(
171 Piece::text(" blue ")
172 .ink(Ink::BrightWhite)
173 .attr(Attr::Bold),
174 )
175 .piece(Piece::text(version).ink(Ink::BrightBlack)),
176 // A single rule under it, in the crisp light set. Not `━` heavy and not
177 // `╌` dashed: neither has renderer geometry.
178 Line::new().piece(Piece::glyphs(Crisp::Horizontal, 20).ink(Ink::BrightBlack)),
179 Line::new().piece(
180 Piece::text("a Ruby/Elixir surface on tatara-lisp and Rust").ink(Ink::BrightBlack),
181 ),
182 ]
183}
184
185#[cfg(test)]
186mod tests {
187 use super::*;
188
189 /// The mark is four solid cells — no dither.
190 #[test]
191 fn the_mark_is_four_solid_cells() {
192 assert_eq!(mark(), "████");
193 }
194
195 /// **No dither glyph may appear in the mark.**
196 ///
197 /// The first version was `░▒▓█`, which katsuji's own docs warn "read as fuzz
198 /// at cell size". It shipped, and the operator read it as a blue box. This
199 /// names the mistake so it cannot come back.
200 #[test]
201 fn the_mark_uses_no_dither_glyph() {
202 for bad in [Crisp::ShadeLight, Crisp::ShadeMedium, Crisp::ShadeDark] {
203 assert!(
204 !mark().contains(bad.ch()),
205 "{bad:?} reads as fuzz at cell size — the mark must be solid"
206 );
207 }
208 }
209
210 /// **The colour must actually shift.** This is the whole mark: a blueshift
211 /// with one flat colour is not a shift at all, which is precisely what the
212 /// first version shipped.
213 #[test]
214 fn every_cell_of_the_shift_is_a_different_ink() {
215 let mut seen: Vec<Ink> = Vec::new();
216 for ink in SHIFT {
217 assert!(
218 !seen.contains(&ink),
219 "{ink:?} repeats — a shift with a repeated colour is not shifting"
220 );
221 seen.push(ink);
222 }
223 assert_eq!(seen.len(), 4);
224 }
225
226 /// **And it must shift toward BLUE**, across Nord's Frost band in order:
227 /// nord7 teal → nord8 cyan → nord9 light → nord10 deep. Reversed, it is a
228 /// redshift.
229 #[test]
230 fn the_shift_walks_the_frost_band_toward_blue() {
231 assert_eq!(
232 SHIFT,
233 [Ink::BrightCyan, Ink::Cyan, Ink::BrightBlue, Ink::Blue],
234 "the direction is the meaning: toward blue, not away from it"
235 );
236 assert_eq!(
237 *SHIFT.last().expect("non-empty"),
238 Ink::Blue,
239 "it ends on blue"
240 );
241 }
242
243 /// **Named by ANSI slot, never by hex.** katsuji has no `Ink::Rgb` on
244 /// purpose — a truecolor literal pins a colour that stops tracking the
245 /// reader's theme. Rendering must therefore emit plain SGR.
246 #[test]
247 fn the_mark_emits_no_truecolor_escape() {
248 let rendered = mark_line().render();
249 assert!(
250 !rendered.contains("38;2;"),
251 "a truecolor escape would stop tracking the reader's theme: {rendered:?}"
252 );
253 }
254
255 /// The styled mark carries four distinct colour runs.
256 #[test]
257 fn the_styled_mark_paints_four_runs() {
258 let rendered = mark_line().render();
259 for ink in SHIFT {
260 let param = match ink {
261 Ink::BrightCyan => "96",
262 Ink::Cyan => "36",
263 Ink::BrightBlue => "94",
264 Ink::Blue => "34",
265 other => panic!("unexpected ink in SHIFT: {other:?}"),
266 };
267 assert!(
268 rendered.contains(param),
269 "expected SGR {param} for {ink:?} in {rendered:?}"
270 );
271 }
272 }
273
274 // ---- theme ----------------------------------------------------------
275
276 /// **blue's primary is Nord's deep blue, not the fleet cyan.** A language
277 /// called blue whose primary was a cyan would be a name that does not match
278 /// its own output.
279 #[test]
280 fn the_primary_is_nord10_deep_blue() {
281 let t = Theme::fleet();
282 assert_eq!(t.primary, Color::new(0x5E, 0x81, 0xAC), "nord10");
283 }
284
285 /// **And the shared accent is unchanged.** Diverging would make blue's cyan
286 /// mean something different from every other fleet app's.
287 #[test]
288 fn the_accent_is_the_fleets_nord8_frost_cyan() {
289 let t = Theme::fleet();
290 assert_eq!(t.accent, Color::new(0x88, 0xC0, 0xD0), "nord8");
291 assert_ne!(
292 t.primary, t.accent,
293 "identity and interaction are different roles and must be different colours"
294 );
295 }
296
297 /// Every colour comes from the palette — blue carries no hex of its own.
298 /// This is the drift test: if someone inlines a literal, it stops matching
299 /// the palette lookup.
300 #[test]
301 fn every_theme_colour_comes_from_the_nord_palette() {
302 let t = Theme::fleet();
303 let nord: Vec<Color> = (0..16).filter_map(|i| NORD.get(i)).collect();
304 for (name, c) in [
305 ("primary", t.primary),
306 ("accent", t.accent),
307 ("background", t.background),
308 ("foreground", t.foreground),
309 ("dim", t.dim),
310 ] {
311 assert!(
312 nord.contains(&c),
313 "{name} = {c:?} is not a Nord colour — blue must not carry its own hex"
314 );
315 }
316 }
317
318 /// The bindings follow a passed palette, so blue owns the *roles* and not
319 /// the values.
320 ///
321 /// `nord10` lives at `frost[3]` — the Frost band is `nord7..nord10`, so the
322 /// band-relative index is 3, not 10. Writing the flat index here would have
323 /// been an out-of-bounds panic rather than a wrong colour, which is at least
324 /// loud.
325 #[test]
326 fn the_theme_follows_a_customised_palette() {
327 let mut custom = NORD;
328 custom.frost[3] = Color::new(1, 2, 3);
329 assert_eq!(
330 Theme::from_palette(&custom).primary,
331 Color::new(1, 2, 3),
332 "a consumer's palette must drive the value; blue supplies the role"
333 );
334 }
335
336 // ---- wordmark -------------------------------------------------------
337
338 #[test]
339 fn the_wordmark_carries_the_name_the_mark_and_the_version() {
340 let lines = wordmark("9.9.9");
341 let rendered: String = lines.iter().map(Line::render).collect();
342 assert!(rendered.contains("blue"), "the name: {rendered:?}");
343 assert!(rendered.contains("9.9.9"), "the version: {rendered:?}");
344 assert!(
345 rendered.contains(CELL.ch()),
346 "the mark must appear: {rendered:?}"
347 );
348 }
349
350 /// **The version is never hardcoded.** mado shipped a `0.1.0` wordmark
351 /// against a `0.1.98` binary because a literal was a second place to update.
352 #[test]
353 fn the_wordmark_takes_its_version_from_the_caller() {
354 let a: String = wordmark("1.2.3").iter().map(Line::render).collect();
355 let b: String = wordmark("4.5.6").iter().map(Line::render).collect();
356 assert!(a.contains("1.2.3") && !a.contains("4.5.6"));
357 assert!(b.contains("4.5.6") && !b.contains("1.2.3"));
358 }
359}