Guide API
Skip to main content

tvision_rs/
theme.rs

1//! Theming: a [`Role`] → [`Style`] map plus a [`Glyphs`] holder.
2//!
3//! Every widget asks the [`Theme`] for colours by **semantic role** rather than
4//! a raw colour — a frame draws with `ctx.theme.style(Role::FrameActive)`, a
5//! button with `Role::ButtonNormal`, and so on — and reaches drawing glyphs
6//! (frame corners, scrollbar arrows, check/radio marks, shadows) through
7//! [`Glyphs`]. Swapping themes (or editing a single role) recolours the whole
8//! UI at once.
9//!
10//! [`Role`] is a **first-party closed enum**: third parties do not add roles.
11//! It covers the frames (active/passive/dragging), the
12//! normal/focused/disabled/pressed control quartet, the list-state matrix, and
13//! the per-widget families (buttons, labels, menus, the status line, …).
14//!
15//! **Guide:** [Theming & colors](../../../apps/theming.html).
16//!
17//! # Turbo Vision heritage
18//!
19//! The original framework resolved colours by walking an owner chain of
20//! length-prefixed palette strings and scattered drawing glyphs as literals
21//! through the widget source. tvision-rs collapses both into one [`Theme`] keyed by a
22//! semantic [`Role`] (deviation D7); each original colour lookup maps to one named
23//! role here.
24
25use crate::color::{Color, Style};
26
27/// A semantic colour role — the key a widget uses to ask the [`Theme`] for a
28/// [`Style`].
29///
30/// This enum is **closed and first-party** (not app-extensible).
31///
32/// # Window palette families and the Role enum
33///
34/// The original framework used per-widget 32-slot palette strings
35/// (`CGrayDialog`, `CBlueDialog`, `CCyanDialog`, `cpBlueWindow`,
36/// `cpCyanWindow`) indexed by a chained lookup through the owner hierarchy.
37/// tvision-rs collapses that entire chain into **named roles**:
38///
39/// | C++ palette scheme | Window / dialog type | Rust `Role` family |
40/// |---|---|---|
41/// | `cpBlueWindow` / `CBlueDialog` | [`WindowPalette::Blue`] windows and dialogs | `Role::Frame*` (Active/Passive/Dragging/Icon) |
42/// | `cpGrayWindow` / `CGrayDialog` | [`WindowPalette::Gray`] dialogs | `Role::FrameGray*` |
43/// | `cpCyanWindow` / `CCyanDialog` | [`WindowPalette::Cyan`] windows | `Role::FrameCyan*` |
44///
45/// The frame widget selects the correct `Frame*` family at draw time based on
46/// the owner window's [`WindowPalette`]. Descendant widgets (buttons, inputs,
47/// clusters, lists, …) pick **their own named `Role::*`** regardless of the
48/// window palette — the realistic owner assumption baked into `classic_blue`'s
49/// derivation comments is always a `CGrayDialog` for dialog-hosted widgets.
50///
51/// [`WindowPalette::Blue`]: crate::window::WindowPalette::Blue
52/// [`WindowPalette::Gray`]: crate::window::WindowPalette::Gray
53/// [`WindowPalette::Cyan`]: crate::window::WindowPalette::Cyan
54/// [`WindowPalette`]: crate::window::WindowPalette
55///
56/// # Turbo Vision heritage
57///
58/// Each colour lookup in the original framework maps to one named role here
59/// (deviation D7).
60#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
61pub enum Role {
62    /// The desktop background fill — the `░`/`·`/space pattern drawn by
63    /// [`Background::draw`](crate::desktop::Background) across the entire
64    /// desktop area behind all windows. In `classic_blue` this is lightgray
65    /// on blue (BIOS `0x71`), resolved from the C++ chain
66    /// `cpBackground[1]=0x01 → cpAppColor[1]=0x71`.
67    Background,
68    /// An active (focused) **blue-scheme** window frame — the border drawn by
69    /// [`Frame`](crate::Frame) when the owning window has keyboard focus and
70    /// [`WindowPalette`](crate::window::WindowPalette) is `Blue` (the default).
71    /// In `classic_blue` this is white on blue (`0x1F`), resolved from
72    /// `cpFrame[3]=0x02 → cpBlueWindow[2]=0x09 → cpAppColor[9]=0x1F`.
73    FrameActive,
74    /// A passive (unfocused) **blue-scheme** window frame — the border drawn by
75    /// [`Frame`](crate::Frame) when the owning window does not have keyboard
76    /// focus and [`WindowPalette`](crate::window::WindowPalette) is `Blue`.
77    /// In `classic_blue` this is lightgray on blue (`0x17`), resolved from
78    /// `cpFrame[1]=0x01 → cpBlueWindow[1]=0x08 → cpAppColor[8]=0x17`.
79    FramePassive,
80    /// A **blue-scheme** frame while the window is being dragged or resized —
81    /// drawn by [`Frame`](crate::Frame) when `sfDragging` is set and
82    /// [`WindowPalette`](crate::window::WindowPalette) is `Blue`. In
83    /// `classic_blue` this is lightgreen on blue (`0x1A`), resolved from
84    /// `cpFrame[5]=0x03 → cpBlueWindow[3]=0x0A → cpAppColor[10]=0x1A`.
85    FrameDragging,
86    /// A **blue-scheme** frame icon — the close `[×]`, zoom `[↑]`/`[↓]`, and
87    /// resize `[⟺]` glyphs drawn by [`Frame`](crate::Frame) when
88    /// [`WindowPalette`](crate::window::WindowPalette) is `Blue`. In
89    /// `classic_blue` this is lightgreen on blue (`0x1A`), the same attribute
90    /// as [`FrameDragging`](Role::FrameDragging) (both resolve via
91    /// `cpFrame[5]=0x03 → cpBlueWindow[3]=0x0A → cpAppColor[10]=0x1A`).
92    FrameIcon,
93    /// An active (focused) **gray-scheme** frame (dialogs and gray windows). The
94    /// frame selects the `FrameGray*` family when its owner's
95    /// [`WindowPalette`](crate::window::WindowPalette) is `Gray`. In
96    /// `classic_blue` this is white on lightgray (`0x7F`), resolved from
97    /// `cpFrame[3]=0x02 → cpGrayDialog[2]=0x21 → cpAppColor[33]=0x7F`.
98    FrameGrayActive,
99    /// A passive (unfocused) **gray-scheme** frame — drawn by
100    /// [`Frame`](crate::Frame) when the owning window lacks focus and
101    /// [`WindowPalette`](crate::window::WindowPalette) is `Gray`. In
102    /// `classic_blue` this is black on lightgray (`0x70`), resolved from
103    /// `cpFrame[1]=0x01 → cpGrayDialog[1]=0x20 → cpAppColor[32]=0x70`.
104    FrameGrayPassive,
105    /// A **gray-scheme** frame while the window is being dragged or resized.
106    /// Drawn by [`Frame`](crate::Frame) when `sfDragging` is set and
107    /// [`WindowPalette`](crate::window::WindowPalette) is `Gray`. In
108    /// `classic_blue` this is lightgreen on lightgray (`0x7A`), resolved from
109    /// `cpFrame[5]=0x03 → cpGrayDialog[3]=0x22 → cpAppColor[34]=0x7A`.
110    FrameGrayDragging,
111    /// A **gray-scheme** frame icon — the close, zoom, and resize glyphs drawn
112    /// by [`Frame`](crate::Frame) when
113    /// [`WindowPalette`](crate::window::WindowPalette) is `Gray`. In
114    /// `classic_blue` this is lightgreen on lightgray (`0x7A`), the same
115    /// attribute as [`FrameGrayDragging`](Role::FrameGrayDragging) (both
116    /// resolve via `cpFrame[5]=0x03 → cpGrayDialog[3]=0x22 → cpAppColor[34]=0x7A`).
117    FrameGrayIcon,
118    /// An active (focused) **cyan-scheme** frame (cyan windows). The frame
119    /// selects the `FrameCyan*` family when its owner's
120    /// [`WindowPalette`](crate::window::WindowPalette) is `Cyan`. In
121    /// `classic_blue` this is white on cyan (`0x3F`), resolved from
122    /// `cpFrame[3]=0x02 → cpCyanWindow[2]=0x11 → cpAppColor[17]=0x3F`.
123    FrameCyanActive,
124    /// A passive (unfocused) **cyan-scheme** frame — drawn by
125    /// [`Frame`](crate::Frame) when the owning window lacks focus and
126    /// [`WindowPalette`](crate::window::WindowPalette) is `Cyan`. In
127    /// `classic_blue` this is lightgray on cyan (`0x37`), resolved from
128    /// `cpFrame[1]=0x01 → cpCyanWindow[1]=0x10 → cpAppColor[16]=0x37`.
129    FrameCyanPassive,
130    /// A **cyan-scheme** frame while the window is being dragged or resized.
131    /// Drawn by [`Frame`](crate::Frame) when `sfDragging` is set and
132    /// [`WindowPalette`](crate::window::WindowPalette) is `Cyan`. In
133    /// `classic_blue` this is lightgreen on cyan (`0x3A`), resolved from
134    /// `cpFrame[5]=0x03 → cpCyanWindow[3]=0x12 → cpAppColor[18]=0x3A`.
135    FrameCyanDragging,
136    /// A **cyan-scheme** frame icon — the close, zoom, and resize glyphs drawn
137    /// by [`Frame`](crate::Frame) when
138    /// [`WindowPalette`](crate::window::WindowPalette) is `Cyan`. In
139    /// `classic_blue` this is lightgreen on cyan (`0x3A`), the same attribute
140    /// as [`FrameCyanDragging`](Role::FrameCyanDragging) (both resolve via
141    /// `cpFrame[5]=0x03 → cpCyanWindow[3]=0x12 → cpAppColor[18]=0x3A`).
142    FrameCyanIcon,
143    /// The `↓` arrow glyph of the history-dropdown icon drawn by
144    /// [`THistory`](crate::widgets::THistory). Sits in the center cell of the
145    /// three-cell icon `▐~↓~▌`. In `classic_blue` this is black on green
146    /// (`0x20`), resolved from
147    /// `cpHistory[1]=0x16 → cpGrayDialog[22]=0x35 → cpAppColor[53]=0x20`.
148    HistoryArrow,
149    /// The `▐` and `▌` side-block glyphs of the history-dropdown icon drawn by
150    /// [`THistory`](crate::widgets::THistory). Frames the center arrow on both
151    /// sides. In `classic_blue` this is green on lightgray (`0x72`), resolved
152    /// from `cpHistory[2]=0x17 → cpGrayDialog[23]=0x36 → cpAppColor[54]=0x72`.
153    HistorySides,
154    /// A normal item in the history dropdown list. One role serves the
155    /// active/inactive normals, the selected item, and the divider (they all share
156    /// a colour; surfaced through
157    /// [`ListViewer::list_roles`](crate::widgets::ListViewer::list_roles)).
158    HistoryViewerNormal,
159    /// The focused (cursor) item in the history dropdown list.
160    HistoryViewerFocused,
161    /// A scroll-bar page (trough) area — the `▒` fill between the thumb and
162    /// the arrow buttons, drawn by [`ScrollBar::draw`](crate::widgets::ScrollBar).
163    /// In `classic_blue` this is blue on cyan (`0x31`), resolved from
164    /// `cpScrollBar[1]=0x04 → cpBlueWindow[4]=0x0B → cpAppColor[11]=0x31`.
165    ScrollBarPage,
166    /// Scroll-bar control glyphs (arrows and thumb) — the `▲`/`▼`/`◄`/`►`
167    /// arrow buttons and the `■` thumb indicator drawn by
168    /// [`ScrollBar::draw`](crate::widgets::ScrollBar). In `classic_blue` this
169    /// is blue on cyan (`0x31`), the same as [`ScrollBarPage`](Role::ScrollBarPage)
170    /// (indices 2 and 3 in `cpScrollBar` both resolve to the same color).
171    ScrollBarControls,
172    /// Generic enabled control text — used by widgets that need a simple
173    /// active/normal color without a dedicated role family. In `classic_blue`
174    /// this is black on cyan (`0x30`). Used by the theme editor's role list
175    /// and any custom widget that reaches for a sensible default.
176    Normal,
177    /// A focused control — the highlight color applied to whichever view
178    /// currently holds keyboard focus, used by the theme editor's focused-row
179    /// highlight. In `classic_blue` this is white on green (`0x2F`).
180    Focused,
181    /// A disabled (greyed-out) control — used by widgets to render inactive
182    /// content that cannot receive input. In `classic_blue` this is darkgray
183    /// on blue (`0x18`).
184    Disabled,
185    /// A pressed control (e.g. a button mid-click) — the transient style
186    /// while a mouse button is held down. In `classic_blue` this is white on
187    /// green (`0x2F`), matching [`Focused`](Role::Focused).
188    Pressed,
189    /// A normal item's row surface in a [`ListViewer`](crate::widgets::ListViewer)
190    /// whose **owning pane** is active (see
191    /// [`DrawCtx::owner_active`](crate::view::DrawCtx::owner_active)) — and also
192    /// the empty-list fill. In `classic_blue` this is black on cyan (`0x30`),
193    /// resolved from `cpListViewer[1]=0x1A → cpGrayDialog[26]=0x39 →
194    /// cpAppColor[57]=0x30`.
195    ListNormal,
196    /// A normal item's row surface in a [`ListViewer`](crate::widgets::ListViewer)
197    /// whose owning pane is inactive — recedes as a unit with the rest of the
198    /// pane's content, independent of whether this particular list is the
199    /// current control. In `classic_blue` this matches
200    /// [`ListNormal`](Role::ListNormal) — both palette indices resolve to the
201    /// same dialog entry (`0x1A`).
202    ListInactive,
203    /// The middle content surface of a [`ListViewer`](crate::widgets::ListViewer):
204    /// its owning pane is active but a selectable sibling holds focus (the
205    /// three-surface rule, [`DrawCtx::content_surface`](crate::view::DrawCtx::content_surface)).
206    /// In `classic_blue` it equals [`ListNormal`](Role::ListNormal), preserving
207    /// classic per-window uniformity; a theme opts into sibling distinction by
208    /// giving it the pane-surface colour.
209    ListSurface,
210    /// The focused (cursor) item of an active
211    /// [`ListViewer`](crate::widgets::ListViewer). In `classic_blue` this is
212    /// white on green (`0x2F`), resolved from `cpListViewer[3]=0x1B →
213    /// cpGrayDialog[27]=0x3A → cpAppColor[58]=0x2F`.
214    ListFocused,
215    /// A selected (marked) item in a
216    /// [`ListViewer`](crate::widgets::ListViewer) that supports multi-select.
217    /// In `classic_blue` this is yellow on cyan (`0x3E`), resolved from
218    /// `cpListViewer[4]=0x1C → cpGrayDialog[28]=0x3B → cpAppColor[59]=0x3E`.
219    ListSelected,
220    /// The inter-column divider `│` in a multi-column
221    /// [`ListViewer`](crate::widgets::ListViewer). In `classic_blue` this is
222    /// blue on cyan (`0x31`), resolved from `cpListViewer[5]=0x1D →
223    /// cpGrayDialog[29]=0x3C → cpAppColor[60]=0x31`.
224    ListDivider,
225    /// The column-label row of a [`Table`](crate::widgets::Table), including
226    /// the sort marker. A tvision-rs-native role with no C++ palette ancestor
227    /// (Turbo Vision has no table); in `classic_blue` it is yellow on blue
228    /// (`0x1E`), a header bar that stands apart from the cyan list rows.
229    TableHeader,
230    /// The cell cursor of a [`Table`](crate::widgets::Table) with editable
231    /// columns: the cell on the focused row that Enter or F2 would edit. A
232    /// tvision-rs-native role; in `classic_blue` it is black on light gray
233    /// (`0x70`), distinct from the focused row (white on green) and from the
234    /// input line (white on blue) that opens over the cell.
235    TableCellCursor,
236    /// Error feedback — for widgets or dialogs that need to highlight an error
237    /// state. In `classic_blue` this is white on red (`0x4F`). This is a
238    /// tvision-rs-native role with no C++ palette ancestor.
239    Error,
240    /// Warning feedback — for widgets or dialogs that need to highlight a
241    /// warning. In `classic_blue` this is black on brown (`0x60`). This is a
242    /// tvision-rs-native role with no C++ palette ancestor.
243    Warning,
244    /// Informational feedback — for widgets or dialogs that need an
245    /// informational highlight. In `classic_blue` this is white on blue
246    /// (`0x1F`). This is a tvision-rs-native role with no C++ palette ancestor.
247    Info,
248    /// Success feedback — for widgets or dialogs that need a success highlight.
249    /// In `classic_blue` this is white on green (`0x2F`). This is a
250    /// tvision-rs-native role with no C++ palette ancestor.
251    Success,
252    /// Static (label/caption) text — the style applied to the body of a
253    /// [`StaticText`](crate::widgets::StaticText) or
254    /// [`ParamText`](crate::widgets::ParamText) widget. In `classic_blue` this
255    /// is black on lightgray (`0x70`), matching the gray-dialog surface.
256    /// Resolved from `cpStaticText[1]=0x06 → cpGrayDialog[6]=0x25 →
257    /// cpAppColor[37]=0x70`.
258    StaticText,
259    /// A cluster item's normal (unselected) text — drawn by
260    /// [`CheckBoxes`](crate::widgets::CheckBoxes) and
261    /// [`RadioButtons`](crate::widgets::RadioButtons) for each item that is
262    /// neither the focused cursor row nor disabled. In `classic_blue` this is
263    /// black on cyan (`0x30`), resolved from `cpCluster[1]=0x10 →
264    /// cpGrayDialog[16]=0x2F → cpAppColor[47]=0x30`.
265    ClusterNormal,
266    /// A cluster item's selected (cursor) text — the row under the keyboard
267    /// cursor when the cluster has focus. In `classic_blue` this is white on
268    /// cyan (`0x3F`), resolved from `cpCluster[2]=0x11 → cpGrayDialog[17]=0x30
269    /// → cpAppColor[48]=0x3F`.
270    ClusterSelected,
271    /// A cluster item's shortcut highlight in the normal (unselected) state —
272    /// the hotkey letter shown in a distinct color. In `classic_blue` this is
273    /// yellow on cyan (`0x3E`), resolved from `cpCluster[3]=0x12 →
274    /// cpGrayDialog[18]=0x31 → cpAppColor[49]=0x3E`.
275    ClusterNormalShortcut,
276    /// A cluster item's shortcut highlight in the selected (cursor) state.
277    /// In `classic_blue` this matches [`ClusterNormalShortcut`](Role::ClusterNormalShortcut)
278    /// — both palette indices (`cpCluster[3]` and `cpCluster[4]`) resolve to
279    /// the same dialog entry (`0x12`), giving yellow on cyan (`0x3E`).
280    ClusterSelectedShortcut,
281    /// A disabled cluster item's text — drawn when the whole cluster has its
282    /// `disabled` state flag set. In `classic_blue` this is darkgray on cyan
283    /// (`0x38`), resolved from `cpCluster[5]=0x1F → cpGrayDialog[31]=0x3E →
284    /// cpAppColor[62]=0x38`.
285    ClusterDisabled,
286    /// The line/column position indicator drawn by
287    /// [`Indicator`](crate::widgets::Indicator) when its owner window is **not**
288    /// being dragged/resized. In `classic_blue` this is white on blue (`0x1F`),
289    /// resolved from `cpIndicator[1]=0x02 → cpBlueWindow[2]=0x09 →
290    /// cpAppColor[9]=0x1F`.
291    IndicatorNormal,
292    /// The line/column position indicator drawn by
293    /// [`Indicator`](crate::widgets::Indicator) while its owner window is being
294    /// **dragged or resized**. In `classic_blue` this is lightgreen on blue
295    /// (`0x1A`), resolved from `cpIndicator[2]=0x03 → cpBlueWindow[3]=0x0A →
296    /// cpAppColor[10]=0x1A`. The `═` frame glyph also changes to `─` during drag.
297    IndicatorDragging,
298    /// A [`Button`](crate::widgets::Button)'s face text when it is neither the
299    /// default button, nor focused, nor disabled. In `classic_blue` this is
300    /// black on green (`0x20`), resolved from `cpButton[1]=0x0A →
301    /// cpGrayDialog[10]=0x29 → cpAppColor[41]=0x20`.
302    ButtonNormal,
303    /// A [`Button`](crate::widgets::Button)'s face text when it is the **default**
304    /// button (the one activated by Enter when no other button is focused). In
305    /// `classic_blue` this is lightcyan on green (`0x2B`), resolved from
306    /// `cpButton[2]=0x0B → cpGrayDialog[11]=0x2A → cpAppColor[42]=0x2B`.
307    ButtonDefault,
308    /// A [`Button`](crate::widgets::Button)'s face text while it is selected
309    /// (mouse-pressed or keyboard-activated). In `classic_blue` this is white on
310    /// green (`0x2F`), resolved from `cpButton[3]=0x0C → cpGrayDialog[12]=0x2B
311    /// → cpAppColor[43]=0x2F`.
312    ButtonSelected,
313    /// A [`Button`](crate::widgets::Button)'s face text when the button is
314    /// disabled. In `classic_blue` this is darkgray on lightgray (`0x78`),
315    /// resolved from `cpButton[4]=0x0D → cpGrayDialog[13]=0x2C →
316    /// cpAppColor[44]=0x78`.
317    ButtonDisabled,
318    /// A [`Button`](crate::widgets::Button)'s hotkey letter highlight in the
319    /// **normal** state. In `classic_blue` this is yellow on green (`0x2E`),
320    /// resolved from `cpButton[5]=0x0E → cpGrayDialog[14]=0x2D →
321    /// cpAppColor[45]=0x2E`.
322    ButtonNormalShortcut,
323    /// A [`Button`](crate::widgets::Button)'s hotkey letter highlight in the
324    /// **default** state. In `classic_blue` this matches
325    /// [`ButtonNormalShortcut`](Role::ButtonNormalShortcut) — all three shortcut
326    /// indices resolve to the same dialog entry (`cpButton[6]=0x0E`).
327    ButtonDefaultShortcut,
328    /// A [`Button`](crate::widgets::Button)'s hotkey letter highlight in the
329    /// **selected** state. In `classic_blue` this matches
330    /// [`ButtonNormalShortcut`](Role::ButtonNormalShortcut) — `cpButton[7]=0x0E`
331    /// resolves to the same dialog entry as indices 5 and 6.
332    ButtonSelectedShortcut,
333    /// The drop-shadow cells drawn one column to the right and one row below a
334    /// [`Button`](crate::widgets::Button)'s bounding box. In `classic_blue` this
335    /// is black on lightgray (`0x70`), resolved from `cpButton[8]=0x0F →
336    /// cpGrayDialog[15]=0x2E → cpAppColor[46]=0x70`.
337    ButtonShadow,
338    /// A [`Label`](crate::widgets::Label)'s caption text when its linked control
339    /// is **unfocused** (the label is "dark"). In `classic_blue` this is black
340    /// on lightgray (`0x70`), resolved from `cpLabel[1]=0x07 →
341    /// cpGrayDialog[7]=0x26 → cpAppColor[38]=0x70`.
342    LabelNormal,
343    /// A [`Label`](crate::widgets::Label)'s caption text when its linked control
344    /// **has focus** (the label is "lit"). In `classic_blue` this is white on
345    /// lightgray (`0x7F`), resolved from `cpLabel[2]=0x08 → cpGrayDialog[8]=0x27
346    /// → cpAppColor[39]=0x7F`.
347    LabelLight,
348    /// A [`Label`](crate::widgets::Label)'s hotkey letter highlight in the
349    /// **dark** (unfocused) state. In `classic_blue` this is yellow on lightgray
350    /// (`0x7E`), resolved from `cpLabel[3]=0x09 → cpGrayDialog[9]=0x28 →
351    /// cpAppColor[40]=0x7E`.
352    LabelNormalShortcut,
353    /// A [`Label`](crate::widgets::Label)'s hotkey letter highlight in the **lit**
354    /// (focused) state. In `classic_blue` this matches
355    /// [`LabelNormalShortcut`](Role::LabelNormalShortcut) — `cpLabel[4]=0x09`
356    /// resolves to the same dialog entry as index 3. Kept as a distinct role so
357    /// future theming can give the lit shortcut a different colour.
358    LabelLightShortcut,
359    /// An [`InputLine`](crate::widgets::InputLine)'s field text — applied to
360    /// the entire field area regardless of focus state (the C++ palette uses
361    /// the same byte for both passive and active). In `classic_blue` this is
362    /// white on blue (`0x1F`), resolved from `cpInputLine[1]=cpInputLine[2]=0x13
363    /// → cpGrayDialog[19]=0x32 → cpAppColor[50]=0x1F`.
364    InputNormal,
365    /// An input line's background when its **owning pane** is inactive (see
366    /// [`DrawCtx::owner_active`](crate::view::DrawCtx::owner_active)) — every
367    /// field in the pane recedes together, regardless of which field itself
368    /// holds focus. Heritage: this is the C++ `cpInputLine[1]` slot
369    /// (`TInputLine::draw` selects it via `getColor(sfFocused ? 2 : 1)`, the
370    /// unfocused entry); tvision-rs repurposes it onto the owning-pane axis. In
371    /// `classic_blue` it equals [`InputNormal`](Role::InputNormal); a theme may
372    /// dim it to signal an inactive pane.
373    InputInactive,
374    /// The middle content surface of an [`InputLine`](crate::widgets::InputLine):
375    /// its owning pane is active but a selectable sibling holds focus (the
376    /// three-surface rule, [`DrawCtx::content_surface`](crate::view::DrawCtx::content_surface)).
377    /// In `classic_blue` it equals [`InputNormal`](Role::InputNormal), preserving
378    /// classic per-window uniformity; a theme opts into sibling distinction by
379    /// giving it the pane-surface colour.
380    InputSurface,
381    /// An [`InputLine`](crate::widgets::InputLine)'s selection highlight —
382    /// the text region between the cursor and the mark anchor. In
383    /// `classic_blue` this is white on green (`0x2F`), resolved from
384    /// `cpInputLine[3]=0x14 → cpGrayDialog[20]=0x33 → cpAppColor[51]=0x2F`.
385    InputSelected,
386    /// The `◄`/`►` overflow-scroll arrows shown at the left/right edge of an
387    /// [`InputLine`](crate::widgets::InputLine) when the field content is wider
388    /// than the visible area. In `classic_blue` this is lightgreen on blue
389    /// (`0x1A`), resolved from `cpInputLine[4]=0x15 → cpGrayDialog[21]=0x34 →
390    /// cpAppColor[52]=0x1A`.
391    InputArrow,
392    /// A [`Scroller`](crate::widgets::Scroller)'s / [`Editor`](crate::widgets::Editor)'s
393    /// content fill — applied to every cell of the scrollable area that does not
394    /// carry selected text. The realistic owner is a blue window (the most common
395    /// scroller/editor container). In `classic_blue` this is yellow on blue
396    /// (`0x1E`), resolved from `cpScroller[1]=0x06 → cpBlueWindow[6]=0x0D →
397    /// cpAppColor[13]=0x1E`.
398    ScrollerNormal,
399    /// A [`Scroller`](crate::widgets::Scroller)'s / [`Editor`](crate::widgets::Editor)'s
400    /// selected-text (highlighted) fill — applied to cells within the current
401    /// selection. In `classic_blue` this is blue on lightgray (`0x71`), resolved
402    /// from `cpScroller[2]=0x07 → cpBlueWindow[7]=0x0E → cpAppColor[14]=0x71`.
403    ScrollerSelected,
404    /// A [`MenuBar`](crate::menu::MenuBar) / [`MenuBox`](crate::menu::MenuBox)
405    /// normal item text — and also the bar's background fill between items. Used
406    /// by [`MenuColors::resolve`](crate::menu::MenuColors::resolve). In
407    /// `classic_blue` this is black on lightgray (`0x70`), resolved in one hop:
408    /// `cpMenuView[1]=0x02 → cpAppColor[2]=0x70` (menus are owned directly by
409    /// the program, no window remap).
410    MenuNormal,
411    /// A menu's normal item shortcut letter highlight. In `classic_blue` this
412    /// is red on lightgray (`0x74`), resolved from `cpMenuView[3]=0x04 →
413    /// cpAppColor[4]=0x74`.
414    MenuNormalShortcut,
415    /// A menu's **selected** (highlighted cursor) item text. In `classic_blue`
416    /// this is black on green (`0x20`), resolved from `cpMenuView[4]=0x05 →
417    /// cpAppColor[5]=0x20`.
418    MenuSelected,
419    /// A menu's selected item shortcut letter highlight. In `classic_blue` this
420    /// is red on green (`0x24`), resolved from `cpMenuView[6]=0x07 →
421    /// cpAppColor[7]=0x24`.
422    MenuSelectedShortcut,
423    /// A menu's **disabled** item text (no separate shortcut highlight is
424    /// applied when an item is disabled). In `classic_blue` this is darkgray on
425    /// lightgray (`0x78`), resolved from `cpMenuView[2]=0x03 → cpAppColor[3]=0x78`.
426    MenuDisabled,
427    /// A menu's **selected-and-disabled** item text — the cursor rests on an
428    /// item that is in the disabled command set. In `classic_blue` this is
429    /// darkgray on green (`0x28`), resolved from `cpMenuView[5]=0x06 →
430    /// cpAppColor[6]=0x28`.
431    MenuSelectedDisabled,
432    /// The normal (non-selected, enabled) item text and row background fill
433    /// drawn by [`StatusLine`](crate::StatusLine). Applied to both the item
434    /// label text and any unfilled cells in the status row. In `classic_blue`
435    /// this is black on lightgray (`0x70`), resolved from
436    /// `cpStatusLine[1]=0x02 → cpAppColor[2]=0x70`.
437    StatusNormal,
438    /// The shortcut-key highlight within a normal (non-selected) status item,
439    /// drawn by [`StatusLine`](crate::StatusLine) over the key character.
440    /// In `classic_blue` this is red on lightgray (`0x74`), resolved from
441    /// `cpStatusLine[3]=0x04 → cpAppColor[4]=0x74`.
442    StatusShortcut,
443    /// The text of the currently hovered (selected/pressed) status item, drawn
444    /// by [`StatusLine`](crate::StatusLine) when the mouse cursor rests on an
445    /// enabled item. In `classic_blue` this is black on green (`0x20`),
446    /// resolved from `cpStatusLine[4]=0x05 → cpAppColor[5]=0x20`.
447    StatusSelect,
448    /// The shortcut-key highlight within a hovered status item — the key
449    /// character rendered by [`StatusLine`](crate::StatusLine) while the item
450    /// is selected. In `classic_blue` this is red on green (`0x24`), resolved
451    /// from `cpStatusLine[6]=0x07 → cpAppColor[7]=0x24`.
452    StatusShortcutSelect,
453    /// The text of a disabled (greyed-out) status item drawn by
454    /// [`StatusLine`](crate::StatusLine) when the item's command is absent
455    /// from the enabled command set. In `classic_blue` this is darkgray on
456    /// lightgray (`0x78`), resolved from
457    /// `cpStatusLine[2]=0x03 → cpAppColor[3]=0x78`.
458    StatusDisabled,
459    /// The text of a status item that is simultaneously selected (hovered) and
460    /// disabled, drawn by [`StatusLine`](crate::StatusLine). In `classic_blue`
461    /// this is darkgray on green (`0x28`), resolved from
462    /// `cpStatusLine[5]=0x06 → cpAppColor[6]=0x28`.
463    StatusSelDisabled,
464    /// The file-dialog info pane text — the path, file-size, and date display
465    /// drawn by [`FileInfoPane::draw`](crate::dialog::FileInfoPane). In
466    /// `classic_blue` this is cyan on blue (`0x13`), resolved from
467    /// `cpInfoPane[1]=0x1E → cpGrayDialog[30]=0x3D → cpAppColor[61]=0x13`.
468    InfoPane,
469
470    // -- Outline viewer ------------------------------------------------------
471    /// Style for a normal (non-focused, non-selected) outline row: applied to
472    /// the graph prefix and the text of an expanded node. Used by
473    /// [`ov_draw`](crate::widgets::outline::ov_draw) for every row that is
474    /// neither focused nor selected.
475    OutlineNormal,
476    /// An outline's normal-row background when its **owning pane** is inactive
477    /// (see [`DrawCtx::owner_active`](crate::view::DrawCtx::owner_active)),
478    /// regardless of the outline's own focus. A tvision-rs deviation (C++
479    /// `TOutlineViewer` has no active/inactive normal): lets splitter-pane
480    /// layouts dim unfocused trees. In `classic_blue` it equals
481    /// [`OutlineNormal`](Role::OutlineNormal).
482    OutlineInactive,
483    /// The middle content surface of an [`Outline`](crate::widgets::Outline):
484    /// its owning pane is active but a selectable sibling holds focus (the
485    /// three-surface rule, [`DrawCtx::content_surface`](crate::view::DrawCtx::content_surface)).
486    /// In `classic_blue` it equals [`OutlineNormal`](Role::OutlineNormal),
487    /// preserving classic per-window uniformity; a theme opts into sibling
488    /// distinction by giving it the pane-surface colour.
489    OutlineSurface,
490    /// Style for the focused row of an outline viewer when the viewer has
491    /// keyboard focus. Applied to both the graph prefix and the node text,
492    /// regardless of whether the node is expanded or collapsed.
493    OutlineFocused,
494    /// Style for a selected (highlighted) outline row that does not currently
495    /// hold focus. Used by outline subclasses that implement multi-selection
496    /// by overriding [`OutlineViewer::is_selected`](crate::widgets::OutlineViewer::is_selected).
497    OutlineSelected,
498    /// Style for the text of a collapsed (not-expanded) node on a normal row.
499    /// Applies only when the row is neither focused nor selected, making
500    /// collapsed nodes visually dimmer than expanded ones.
501    OutlineNotExpanded,
502
503    /// Window/menu drop shadows — dark gray on black, applied by the shadow pass
504    /// ([`DrawCtx::cast_shadow`](crate::view::DrawCtx::cast_shadow)).
505    Shadow,
506}
507
508/// Number of [`Role`] variants — the fixed length of [`Theme`]'s style array.
509pub(crate) const ROLE_COUNT: usize = 82;
510
511/// All role variants in index order (appended families grouped semantically) — used by the theme editor.
512pub(crate) const ALL: [Role; ROLE_COUNT] = [
513    Role::Background,
514    Role::FrameActive,
515    Role::FramePassive,
516    Role::FrameDragging,
517    Role::FrameIcon,
518    Role::ScrollBarPage,
519    Role::ScrollBarControls,
520    Role::Normal,
521    Role::Focused,
522    Role::Disabled,
523    Role::Pressed,
524    Role::ListNormal,
525    Role::ListInactive,
526    Role::ListSurface,
527    Role::ListFocused,
528    Role::ListSelected,
529    Role::ListDivider,
530    Role::Error,
531    Role::Warning,
532    Role::Info,
533    Role::Success,
534    Role::StaticText,
535    Role::ClusterNormal,
536    Role::ClusterSelected,
537    Role::ClusterNormalShortcut,
538    Role::ClusterSelectedShortcut,
539    Role::ClusterDisabled,
540    Role::IndicatorNormal,
541    Role::IndicatorDragging,
542    Role::ButtonNormal,
543    Role::ButtonDefault,
544    Role::ButtonSelected,
545    Role::ButtonDisabled,
546    Role::ButtonNormalShortcut,
547    Role::ButtonDefaultShortcut,
548    Role::ButtonSelectedShortcut,
549    Role::ButtonShadow,
550    Role::LabelNormal,
551    Role::LabelLight,
552    Role::LabelNormalShortcut,
553    Role::LabelLightShortcut,
554    Role::InputNormal,
555    Role::InputInactive,
556    Role::InputSurface,
557    Role::InputSelected,
558    Role::InputArrow,
559    Role::ScrollerNormal,
560    Role::ScrollerSelected,
561    Role::MenuNormal,
562    Role::MenuNormalShortcut,
563    Role::MenuSelected,
564    Role::MenuSelectedShortcut,
565    Role::MenuDisabled,
566    Role::MenuSelectedDisabled,
567    Role::StatusNormal,
568    Role::StatusShortcut,
569    Role::StatusSelect,
570    Role::StatusShortcutSelect,
571    Role::StatusDisabled,
572    Role::StatusSelDisabled,
573    Role::InfoPane,
574    Role::OutlineNormal,
575    Role::OutlineInactive,
576    Role::OutlineSurface,
577    Role::OutlineFocused,
578    Role::OutlineSelected,
579    Role::OutlineNotExpanded,
580    Role::Shadow,
581    Role::FrameGrayActive,
582    Role::FrameGrayPassive,
583    Role::FrameGrayDragging,
584    Role::FrameGrayIcon,
585    Role::FrameCyanActive,
586    Role::FrameCyanPassive,
587    Role::FrameCyanDragging,
588    Role::FrameCyanIcon,
589    Role::HistoryArrow,
590    Role::HistorySides,
591    Role::HistoryViewerNormal,
592    Role::HistoryViewerFocused,
593    Role::TableHeader,
594    Role::TableCellCursor,
595];
596
597impl Role {
598    /// Short display name for UI labels (e.g. `"FrameActive"`).
599    /// Fits in 16 characters so the theme editor's list column stays readable.
600    pub fn name(self) -> &'static str {
601        match self {
602            Role::Background => "Background",
603            Role::FrameActive => "FrameActive",
604            Role::FramePassive => "FramePassive",
605            Role::FrameDragging => "FrameDragging",
606            Role::FrameIcon => "FrameIcon",
607            Role::FrameGrayActive => "FrameGrayActive",
608            Role::FrameGrayPassive => "FrameGrayPassive",
609            Role::FrameGrayDragging => "FrameGrayDrag",
610            Role::FrameGrayIcon => "FrameGrayIcon",
611            Role::FrameCyanActive => "FrameCyanActive",
612            Role::FrameCyanPassive => "FrameCyanPassive",
613            Role::FrameCyanDragging => "FrameCyanDrag",
614            Role::FrameCyanIcon => "FrameCyanIcon",
615            Role::HistoryArrow => "HistoryArrow",
616            Role::HistorySides => "HistorySides",
617            Role::HistoryViewerNormal => "HistViewerNormal",
618            Role::HistoryViewerFocused => "HistViewerFocusd",
619            Role::ScrollBarPage => "ScrollBarPage",
620            Role::ScrollBarControls => "ScrollBarCtrl",
621            Role::Normal => "Normal",
622            Role::Focused => "Focused",
623            Role::Disabled => "Disabled",
624            Role::Pressed => "Pressed",
625            Role::ListNormal => "ListNormal",
626            Role::ListInactive => "ListInactive",
627            Role::ListSurface => "ListSurface",
628            Role::ListFocused => "ListFocused",
629            Role::ListSelected => "ListSelected",
630            Role::ListDivider => "ListDivider",
631            Role::TableHeader => "TableHeader",
632            Role::TableCellCursor => "TableCellCursor",
633            Role::Error => "Error",
634            Role::Warning => "Warning",
635            Role::Info => "Info",
636            Role::Success => "Success",
637            Role::StaticText => "StaticText",
638            Role::ClusterNormal => "ClusterNormal",
639            Role::ClusterSelected => "ClusterSelected",
640            Role::ClusterNormalShortcut => "ClusterNormSc",
641            Role::ClusterSelectedShortcut => "ClusterSelSc",
642            Role::ClusterDisabled => "ClusterDisabled",
643            Role::IndicatorNormal => "IndicatorNormal",
644            Role::IndicatorDragging => "IndicatorDragg",
645            Role::ButtonNormal => "ButtonNormal",
646            Role::ButtonDefault => "ButtonDefault",
647            Role::ButtonSelected => "ButtonSelected",
648            Role::ButtonDisabled => "ButtonDisabled",
649            Role::ButtonNormalShortcut => "ButtonNormSc",
650            Role::ButtonDefaultShortcut => "ButtonDefSc",
651            Role::ButtonSelectedShortcut => "ButtonSelSc",
652            Role::ButtonShadow => "ButtonShadow",
653            Role::LabelNormal => "LabelNormal",
654            Role::LabelLight => "LabelLight",
655            Role::LabelNormalShortcut => "LabelNormSc",
656            Role::LabelLightShortcut => "LabelLightSc",
657            Role::InputNormal => "InputNormal",
658            Role::InputInactive => "InputInactive",
659            Role::InputSurface => "InputSurface",
660            Role::InputSelected => "InputSelected",
661            Role::InputArrow => "InputArrow",
662            Role::ScrollerNormal => "ScrollerNormal",
663            Role::ScrollerSelected => "ScrollerSelected",
664            Role::MenuNormal => "MenuNormal",
665            Role::MenuNormalShortcut => "MenuNormSc",
666            Role::MenuSelected => "MenuSelected",
667            Role::MenuSelectedShortcut => "MenuSelSc",
668            Role::MenuDisabled => "MenuDisabled",
669            Role::MenuSelectedDisabled => "MenuSelDisabled",
670            Role::StatusNormal => "StatusNormal",
671            Role::StatusShortcut => "StatusShortcut",
672            Role::StatusSelect => "StatusSelect",
673            Role::StatusShortcutSelect => "StatusScSelect",
674            Role::StatusDisabled => "StatusDisabled",
675            Role::StatusSelDisabled => "StatusSelDisab",
676            Role::InfoPane => "InfoPane",
677            Role::OutlineNormal => "OutlineNormal",
678            Role::OutlineInactive => "OutlineInactive",
679            Role::OutlineSurface => "OutlineSurface",
680            Role::OutlineFocused => "OutlineFocused",
681            Role::OutlineSelected => "OutlineSelected",
682            Role::OutlineNotExpanded => "OutlineNotExpnd",
683            Role::Shadow => "Shadow",
684        }
685    }
686
687    /// Total mapping of each variant to its index into the style array.
688    ///
689    /// A `match` (rather than `#[repr(usize)]` games) keeps this explicit and
690    /// total; the compiler enforces exhaustiveness when new roles are added.
691    fn index(self) -> usize {
692        match self {
693            Role::Background => 0,
694            Role::FrameActive => 1,
695            Role::FramePassive => 2,
696            Role::FrameDragging => 3,
697            Role::FrameIcon => 4,
698            Role::ScrollBarPage => 5,
699            Role::ScrollBarControls => 6,
700            Role::Normal => 7,
701            Role::Focused => 8,
702            Role::Disabled => 9,
703            Role::Pressed => 10,
704            Role::ListNormal => 11,
705            Role::ListInactive => 12,
706            Role::ListFocused => 13,
707            Role::ListSelected => 14,
708            Role::ListDivider => 15,
709            Role::Error => 16,
710            Role::Warning => 17,
711            Role::Info => 18,
712            Role::Success => 19,
713            Role::StaticText => 20,
714            Role::ClusterNormal => 21,
715            Role::ClusterSelected => 22,
716            Role::ClusterNormalShortcut => 23,
717            Role::ClusterSelectedShortcut => 24,
718            Role::ClusterDisabled => 25,
719            Role::IndicatorNormal => 26,
720            Role::IndicatorDragging => 27,
721            Role::ButtonNormal => 28,
722            Role::ButtonDefault => 29,
723            Role::ButtonSelected => 30,
724            Role::ButtonDisabled => 31,
725            Role::ButtonNormalShortcut => 32,
726            Role::ButtonDefaultShortcut => 33,
727            Role::ButtonSelectedShortcut => 34,
728            Role::ButtonShadow => 35,
729            Role::LabelNormal => 36,
730            Role::LabelLight => 37,
731            Role::LabelNormalShortcut => 38,
732            Role::LabelLightShortcut => 39,
733            Role::InputNormal => 40,
734            Role::InputInactive => 75,
735            Role::InputSurface => 77,
736            Role::InputSelected => 41,
737            Role::InputArrow => 42,
738            Role::ScrollerNormal => 43,
739            Role::ScrollerSelected => 56,
740            Role::MenuNormal => 44,
741            Role::MenuNormalShortcut => 45,
742            Role::MenuSelected => 46,
743            Role::MenuSelectedShortcut => 47,
744            Role::MenuDisabled => 48,
745            Role::MenuSelectedDisabled => 49,
746            Role::StatusNormal => 50,
747            Role::StatusShortcut => 51,
748            Role::StatusSelect => 52,
749            Role::StatusShortcutSelect => 53,
750            Role::StatusDisabled => 54,
751            Role::StatusSelDisabled => 55,
752            Role::InfoPane => 57,
753            Role::OutlineNormal => 58,
754            Role::OutlineInactive => 76,
755            Role::OutlineFocused => 59,
756            Role::OutlineSelected => 60,
757            Role::OutlineNotExpanded => 61,
758            Role::Shadow => 62,
759            Role::FrameGrayActive => 63,
760            Role::FrameGrayPassive => 64,
761            Role::FrameGrayDragging => 65,
762            Role::FrameGrayIcon => 66,
763            Role::FrameCyanActive => 67,
764            Role::FrameCyanPassive => 68,
765            Role::FrameCyanDragging => 69,
766            Role::FrameCyanIcon => 70,
767            Role::HistoryArrow => 71,
768            Role::HistorySides => 72,
769            Role::HistoryViewerNormal => 73,
770            Role::HistoryViewerFocused => 74,
771            Role::ListSurface => 78,
772            Role::OutlineSurface => 79,
773            Role::TableHeader => 80,
774            Role::TableCellCursor => 81,
775        }
776    }
777}
778
779/// The role triple a focusable content widget paints its surface from,
780/// consumed by [`DrawCtx::content_surface`](crate::view::DrawCtx::content_surface)
781/// (three-surface rule).
782#[derive(Clone, Copy, Debug, PartialEq, Eq)]
783pub struct SurfaceRoles {
784    /// Active pane and this widget is focused (or can never be focused).
785    pub normal: Role,
786    /// Active pane, a selectable sibling holds focus.
787    pub surface: Role,
788    /// Owning pane receded.
789    pub inactive: Role,
790}
791
792/// Holder for the framework's drawing glyphs — frame corners/tee-connectors,
793/// scrollbar arrows, check/radio marks, shadows, window decorations.
794///
795/// Defaults match the classic CP437/BIOS character set.
796///
797/// # Scrollbar glyphs
798///
799/// ```text
800/// vChars = { '\x1E', '\x1F', '\xB1', '\xFE', '\xB2' };
801/// hChars = { '\x11', '\x10', '\xB1', '\xFE', '\xB2' };
802/// ```
803/// Indices: `[0]`=back-arrow, `[1]`=fwd-arrow, `[2]`=page/trough, `[3]`=thumb,
804/// `[4]`=page-when-no-range.
805///
806/// # Frame glyphs
807///
808/// The frame border is drawn from CP437 box characters, stored as **named
809/// glyphs** (single- and double-line corners and edges) plus four icon strings
810/// that carry the `~`-toggle markers consumed by
811/// [`DrawCtx::put_cstr`](crate::view::DrawCtx::put_cstr). The tee/cross glyphs
812/// (`frame_tee_*`, `frame_cross`) feed
813/// [`crate::junction::frame_junction`] / [`crate::junction::divider_junction`]
814/// for line-joining.
815///
816/// Box-drawing pieces:
817/// ```text
818/// ┌ ┐ └ ┘ ─ │   (single-line)
819/// ╔ ╗ ╚ ╝ ═ ║   (double-line)
820/// close "[~■~]"  zoom "[~↑~]"  un-zoom "[~↕~]"
821/// drag "~─┘~"    drag-left "~└─~"
822/// ```
823///
824/// # Turbo Vision heritage
825///
826/// Ports the glyph tables in `tvtext1.cpp`. The original encoded the frame box as
827/// a bit-mask fed table plus a sibling tee-join walk; tvision-rs stores plain named box
828/// pieces instead and skips the sibling walk (deviation D3).
829#[derive(Clone, Copy, Debug, PartialEq, Eq)]
830pub struct Glyphs {
831    // --- Scrollbar glyphs ---
832    /// Vertical scrollbar: up-arrow / back-arrow. `vChars[0]` = `'\x1E'` (▲).
833    pub sb_v_arrow_back: char,
834    /// Vertical scrollbar: down-arrow / fwd-arrow. `vChars[1]` = `'\x1F'` (▼).
835    pub sb_v_arrow_fwd: char,
836    /// Horizontal scrollbar: left-arrow / back-arrow. `hChars[0]` = `'\x11'` (◄).
837    pub sb_h_arrow_back: char,
838    /// Horizontal scrollbar: right-arrow / fwd-arrow. `hChars[1]` = `'\x10'` (►).
839    pub sb_h_arrow_fwd: char,
840    /// Page/trough fill character (both orientations). `vChars[2]` = `'\xB1'` (▒).
841    pub sb_page: char,
842    /// Thumb/indicator character (both orientations). `vChars[3]` = `'\xFE'` (■).
843    pub sb_thumb: char,
844    /// Page fill when range is zero (both orientations). `vChars[4]` = `'\xB2'` (▓).
845    pub sb_page_no_range: char,
846
847    // --- Frame glyphs — single-line box ---
848    /// Single-line top-left corner `┌` (`\xDA`).
849    pub frame_tl: char,
850    /// Single-line top-right corner `┐` (`\xBF`).
851    pub frame_tr: char,
852    /// Single-line bottom-left corner `└` (`\xC0`).
853    pub frame_bl: char,
854    /// Single-line bottom-right corner `┘` (`\xD9`).
855    pub frame_br: char,
856    /// Single-line horizontal edge `─` (`\xC4`).
857    pub frame_h: char,
858    /// Single-line vertical edge `│` (`\xB3`).
859    pub frame_v: char,
860
861    // --- Frame glyphs — double-line box (active frame) ---
862    /// Double-line top-left corner `╔` (`\xC9`).
863    pub frame_tl_d: char,
864    /// Double-line top-right corner `╗` (`\xBB`).
865    pub frame_tr_d: char,
866    /// Double-line bottom-left corner `╚` (`\xC8`).
867    pub frame_bl_d: char,
868    /// Double-line bottom-right corner `╝` (`\xBC`).
869    pub frame_br_d: char,
870    /// Double-line horizontal edge `═` (`\xCD`).
871    pub frame_h_d: char,
872    /// Double-line vertical edge `║` (`\xBA`).
873    pub frame_v_d: char,
874
875    // --- Frame glyphs — single-line tee/cross joins ---
876    /// Single-line left tee `├` (`\xC3`).
877    pub frame_tee_l: char,
878    /// Single-line right tee `┤` (`\xB4`).
879    pub frame_tee_r: char,
880    /// Single-line top tee `┬` (`\xC2`).
881    pub frame_tee_t: char,
882    /// Single-line bottom tee `┴` (`\xC1`).
883    pub frame_tee_b: char,
884    /// Single-line cross `┼` (`\xC5`).
885    pub frame_cross: char,
886
887    // --- Frame glyphs — double-line tee/cross joins ---
888    /// Double-line left tee `╠` (U+2560).
889    pub frame_tee_l_d: char,
890    /// Double-line right tee `╣` (U+2563).
891    pub frame_tee_r_d: char,
892    /// Double-line top tee `╦` (U+2566).
893    pub frame_tee_t_d: char,
894    /// Double-line bottom tee `╩` (U+2569).
895    pub frame_tee_b_d: char,
896    /// Double-line cross `╬` (U+256C).
897    pub frame_cross_d: char,
898
899    // --- Frame glyphs — mixed: double BAR, single perpendicular STEM ---
900    /// Double-bar top tee, single stem `╤` (U+2564).
901    pub frame_tee_t_dh: char,
902    /// Double-bar bottom tee, single stem `╧` (U+2567).
903    pub frame_tee_b_dh: char,
904    /// Double-bar left tee, single stem `╟` (U+255F).
905    pub frame_tee_l_dv: char,
906    /// Double-bar right tee, single stem `╢` (U+2562).
907    pub frame_tee_r_dv: char,
908    /// Double-bar cross, single horizontal stem `╪` (U+256A).
909    pub frame_cross_dh: char,
910    /// Double-bar cross, single vertical stem `╫` (U+256B).
911    pub frame_cross_dv: char,
912
913    // --- Frame glyphs — mixed: single BAR, double perpendicular STEM ---
914    /// Single-bar top tee, double stem `╥` (U+2565).
915    pub frame_tee_t_sh: char,
916    /// Single-bar bottom tee, double stem `╨` (U+2568).
917    pub frame_tee_b_sh: char,
918    /// Single-bar left tee, double stem `╞` (U+255E).
919    pub frame_tee_l_sv: char,
920    /// Single-bar right tee, double stem `╡` (U+2561).
921    pub frame_tee_r_sv: char,
922
923    // --- Frame icon strings — `~`-toggled for `put_cstr` ---
924    /// Close icon `"[~■~]"` — `[` `]` in the frame role, `■` in `FrameIcon`.
925    pub close_icon: &'static str,
926    /// Zoom icon `"[~↑~]"` (window not maximized).
927    pub zoom_icon: &'static str,
928    /// Un-zoom icon `"[~↕~]"` (window maximized).
929    pub unzoom_icon: &'static str,
930    /// Resize/drag icon (bottom-right) `"~─┘~"`.
931    pub drag_icon: &'static str,
932    /// Resize/drag icon (bottom-left) `"~└─~"`.
933    pub drag_left_icon: &'static str,
934
935    // --- Indicator glyphs ---
936    /// The editor indicator frame `═` — drawn when the owner is **not** dragging.
937    pub indicator_frame_normal: char,
938    /// The editor indicator frame `─` — drawn while the owner is dragging.
939    pub indicator_frame_dragging: char,
940    /// The "buffer modified" marker `☼` drawn at column 0.
941    pub indicator_modified: char,
942
943    // --- Button shadow glyphs ---
944    /// Button shadow `▄` — drawn at the top of the button's right-edge shadow
945    /// column (`y == 0`).
946    pub button_shadow_top: char,
947    /// Button shadow `█` — drawn down the button's right-edge shadow column
948    /// (`y > 0`).
949    pub button_shadow_side: char,
950    /// Button shadow `▀` — the button's bottom-row shadow fill.
951    pub button_shadow_bottom: char,
952
953    // --- Input-line glyphs ---
954    /// Input-line left-scroll arrow `◄` (U+25C4) — drawn at column 0 when the
955    /// field can scroll left.
956    pub input_left_arrow: char,
957    /// Input-line right-scroll arrow `►` (U+25BA) — drawn at the last column when
958    /// the field can scroll right.
959    pub input_right_arrow: char,
960    /// Reveal-eye glyph shown while a masked field is hidden `⊝` (U+229D).
961    pub reveal_eye_hidden: char,
962    /// Reveal-eye glyph shown while a masked field is revealed `◉` (U+25C9).
963    pub reveal_eye_revealed: char,
964
965    // --- Menu bar glyphs ---
966    /// The collapsed application menu bar's "kebab" affordance, drawn at the
967    /// top-right when a `Fullscreen::Screen` window covers the menu row. Themable;
968    /// its display width sets the collapsed bar's width (so it may be other than
969    /// 3 columns).
970    pub menu_kebab: &'static str,
971}
972
973impl Default for Glyphs {
974    /// Classic CP437/BIOS glyphs.
975    fn default() -> Self {
976        Glyphs {
977            // Vertical scrollbar arrows: ▲ (0x1E) / ▼ (0x1F)
978            sb_v_arrow_back: '\u{25B2}',
979            sb_v_arrow_fwd: '\u{25BC}',
980            // Horizontal scrollbar arrows: ◄ (0x11) / ► (0x10)
981            sb_h_arrow_back: '\u{25C4}',
982            sb_h_arrow_fwd: '\u{25BA}',
983            // Trough / page fill: ▒ (0xB1)
984            sb_page: '\u{2592}',
985            // Thumb / indicator: ■ (0xFE)
986            sb_thumb: '\u{25A0}',
987            // Trough when range is zero: ▓ (0xB2)
988            sb_page_no_range: '\u{2593}',
989
990            // Frame box — single-line: ┌ ┐ └ ┘ ─ │
991            frame_tl: '\u{250C}',
992            frame_tr: '\u{2510}',
993            frame_bl: '\u{2514}',
994            frame_br: '\u{2518}',
995            frame_h: '\u{2500}',
996            frame_v: '\u{2502}',
997
998            // Frame box — double-line: ╔ ╗ ╚ ╝ ═ ║
999            frame_tl_d: '\u{2554}',
1000            frame_tr_d: '\u{2557}',
1001            frame_bl_d: '\u{255A}',
1002            frame_br_d: '\u{255D}',
1003            frame_h_d: '\u{2550}',
1004            frame_v_d: '\u{2551}',
1005
1006            // Frame tee/cross joins (unused — sibling walk not reproduced): ├ ┤ ┬ ┴ ┼
1007            frame_tee_l: '\u{251C}',
1008            frame_tee_r: '\u{2524}',
1009            frame_tee_t: '\u{252C}',
1010            frame_tee_b: '\u{2534}',
1011            frame_cross: '\u{253C}',
1012
1013            // Frame double-line tee/cross joins: ╠ ╣ ╦ ╩ ╬
1014            frame_tee_l_d: '\u{2560}',
1015            frame_tee_r_d: '\u{2563}',
1016            frame_tee_t_d: '\u{2566}',
1017            frame_tee_b_d: '\u{2569}',
1018            frame_cross_d: '\u{256C}',
1019
1020            // Mixed: double bar / single stem: ╤ ╧ ╟ ╢ ╪ ╫
1021            frame_tee_t_dh: '\u{2564}',
1022            frame_tee_b_dh: '\u{2567}',
1023            frame_tee_l_dv: '\u{255F}', // ╟ — double vertical bar + single right stem
1024            frame_tee_r_dv: '\u{2562}', // ╢ — double vertical bar + single left stem
1025            frame_cross_dh: '\u{256A}',
1026            frame_cross_dv: '\u{256B}',
1027
1028            // Mixed: single bar / double stem: ╥ ╨ ╞ ╡
1029            frame_tee_t_sh: '\u{2565}',
1030            frame_tee_b_sh: '\u{2568}',
1031            frame_tee_l_sv: '\u{255E}', // ╞ — single vertical bar + double right stem
1032            frame_tee_r_sv: '\u{2561}', // ╡ — single vertical bar + double left stem
1033
1034            // Frame icon strings (~ toggles the FrameIcon style for the bright glyph):
1035            //   close "[~■~]"  zoom "[~↑~]"  unZoom "[~↕~]"
1036            //   drag "~─┘~"    dragLeft "~└─~"
1037            close_icon: "[~\u{25A0}~]",
1038            zoom_icon: "[~\u{2191}~]",
1039            unzoom_icon: "[~\u{2195}~]",
1040            drag_icon: "~\u{2500}\u{2518}~",
1041            drag_left_icon: "~\u{2514}\u{2500}~",
1042
1043            // Indicator: ═ (0xCD) not-dragging, ─ (0xC4) dragging, ☼ (0x0F) modified.
1044            indicator_frame_normal: '\u{2550}',
1045            indicator_frame_dragging: '\u{2500}',
1046            indicator_modified: '\u{263C}',
1047
1048            // Button shadow: ▄ (0xDC) top, █ (0xDB) side, ▀ (0xDF) bottom.
1049            button_shadow_top: '\u{2584}',
1050            button_shadow_side: '\u{2588}',
1051            button_shadow_bottom: '\u{2580}',
1052
1053            // Input line: ◄ (0x11) left scroll arrow, ► (0x10) right.
1054            input_left_arrow: '\u{25C4}',
1055            input_right_arrow: '\u{25BA}',
1056            // Reveal eye: ⊝ hidden, ◉ revealed.
1057            reveal_eye_hidden: '\u{229D}',
1058            reveal_eye_revealed: '\u{25C9}',
1059
1060            // Menu bar kebab: [⋮] (3 display columns).
1061            menu_kebab: "[\u{22EE}]",
1062        }
1063    }
1064}
1065
1066/// A theme: a fixed [`Role`] → [`Style`] map plus a [`Glyphs`] holder.
1067///
1068/// # Turbo Vision heritage
1069///
1070/// Collapses the original palette chain and scattered glyph literals into one
1071/// role-keyed table (deviation D7).
1072#[derive(Clone, Debug, PartialEq, Eq)]
1073pub struct Theme {
1074    styles: [Style; ROLE_COUNT],
1075    glyphs: Glyphs,
1076}
1077
1078impl Theme {
1079    /// The default theme — the classic Turbo Vision blue look.
1080    ///
1081    /// Every value is a `(foreground, background)` BIOS-colour pair. Each role is
1082    /// set with an inline comment recording how the original framework derived that
1083    /// colour — the widget's palette string resolved through its realistic owner
1084    /// (dialog widgets → a gray dialog; window-content widgets → a blue window;
1085    /// program-owned widgets → one direct hop) down to the final attribute byte.
1086    /// Those derivation comments are kept deliberately: they are the project's
1087    /// documented justification for each colour choice (see the `theme` design
1088    /// notes). Roles marked "tvision-rs-native" have no inherited chain.
1089    pub fn classic_blue() -> Self {
1090        // BIOS 4-bit palette reminder: 0=black 1=blue 2=green 3=cyan 4=red
1091        // 5=magenta 6=brown 7=lightgray 8=darkgray 9=lightblue ... F=white.
1092        let mut styles = [Style::default(); ROLE_COUNT];
1093        // The default theme pins canonical true-color RGB (via `Color::bios_rgb`) so
1094        // contrast is correct regardless of the terminal's BIOS palette. The BIOS
1095        // nibbles in the call sites below remain as readable documentation of the
1096        // colour derivation; only the stored color becomes definite RGB. The
1097        // `Color::Bios` variant remains available for apps that want
1098        // terminal-palette colors.
1099        let set = |styles: &mut [Style; ROLE_COUNT], role: Role, fg: u8, bg: u8| {
1100            styles[role.index()] = Style::new(Color::bios_rgb(fg), Color::bios_rgb(bg));
1101        };
1102
1103        // Desktop / frames. Derivation: the frame's color slots resolve through
1104        // cpFrame into the owner's cpBlueWindow, then into cpAppColor; the
1105        // background resolves through the desktop's empty (pass-through) palette.
1106        set(&mut styles, Role::Background, 0x7, 0x1); // lightgray on blue (chain: cpBackground[1]=0x01 → desktop pass-through → cpAppColor[1]=0x71)
1107        set(&mut styles, Role::FrameActive, 0xF, 0x1); // white on blue (chain: cpFrame[3]=0x02 → cpBlueWindow[2]=0x09 → cpAppColor[9]=0x1F)
1108        set(&mut styles, Role::FramePassive, 0x7, 0x1); // lightgray on blue (chain: cpFrame[1]=0x01 → cpBlueWindow[1]=0x08 → cpAppColor[8]=0x17)
1109        set(&mut styles, Role::FrameDragging, 0xA, 0x1); // lightgreen on blue (chain: cpFrame[5]=0x03 → cpBlueWindow[3]=0x0A → cpAppColor[10]=0x1A)
1110        set(&mut styles, Role::FrameIcon, 0xA, 0x1); // lightgreen on blue (chain: cpFrame[5]=0x03 → cpBlueWindow[3]=0x0A → cpAppColor[10]=0x1A)
1111
1112        // Gray-scheme frames (dialogs / gray windows). Derivation: the frame's
1113        // color slots resolve through cpFrame into the OWNER's palette, here
1114        // cpGrayDialog instead of cpBlueWindow, then into cpAppColor:
1115        //   active   cpFrame[3]=0x02 → cpGrayDialog[2]=0x21 → cpAppColor[33]=0x7F
1116        //   passive  cpFrame[1]=0x01 → cpGrayDialog[1]=0x20 → cpAppColor[32]=0x70
1117        //   dragging cpFrame[5]=0x03 → cpGrayDialog[3]=0x22 → cpAppColor[34]=0x7A
1118        //   icon     cpFrame[5]=0x03 → cpGrayDialog[3]=0x22 → cpAppColor[34]=0x7A
1119        set(&mut styles, Role::FrameGrayActive, 0xF, 0x7); // white on lightgray (0x7F)
1120        set(&mut styles, Role::FrameGrayPassive, 0x0, 0x7); // black on lightgray (0x70)
1121        set(&mut styles, Role::FrameGrayDragging, 0xA, 0x7); // lightgreen on lightgray (0x7A)
1122        set(&mut styles, Role::FrameGrayIcon, 0xA, 0x7); // lightgreen on lightgray (0x7A)
1123
1124        // Cyan-scheme frames (cyan windows). Same cpFrame slots, resolved through
1125        // cpCyanWindow into cpAppColor:
1126        set(&mut styles, Role::FrameCyanActive, 0xF, 0x3); // white on cyan (chain: cpFrame[3]=0x02 → cpCyanWindow[2]=0x11 → cpAppColor[17]=0x3F)
1127        set(&mut styles, Role::FrameCyanPassive, 0x7, 0x3); // lightgray on cyan (chain: cpFrame[1]=0x01 → cpCyanWindow[1]=0x10 → cpAppColor[16]=0x37)
1128        set(&mut styles, Role::FrameCyanDragging, 0xA, 0x3); // lightgreen on cyan (chain: cpFrame[5]=0x03 → cpCyanWindow[3]=0x12 → cpAppColor[18]=0x3A)
1129        set(&mut styles, Role::FrameCyanIcon, 0xA, 0x3); // lightgreen on cyan (chain: cpFrame[5]=0x03 → cpCyanWindow[3]=0x12 → cpAppColor[18]=0x3A)
1130
1131        // History family. The history icon sits in a gray dialog (cpHistory →
1132        // cpGrayDialog → cpAppColor); the recall viewer adds one more hop through
1133        // its history-window owner (cpHistoryViewer → cpHistoryWindow →
1134        // cpGrayDialog → cpAppColor).
1135        set(&mut styles, Role::HistoryArrow, 0x0, 0x2); // black on green (chain: cpHistory[1]=0x16 → cpGrayDialog[22]=0x35 → cpAppColor[53]=0x20)
1136        set(&mut styles, Role::HistorySides, 0x2, 0x7); // green on lightgray (chain: cpHistory[2]=0x17 → cpGrayDialog[23]=0x36 → cpAppColor[54]=0x72)
1137        set(&mut styles, Role::HistoryViewerNormal, 0xF, 0x1); // white on blue (chain: cpHistoryViewer[1]=[2]=[4]=[5]=0x06 → cpHistoryWindow[6]=0x13 → cpGrayDialog[19]=0x32 → cpAppColor[50]=0x1F)
1138        set(&mut styles, Role::HistoryViewerFocused, 0xF, 0x2); // white on green (chain: cpHistoryViewer[3]=0x07 → cpHistoryWindow[7]=0x14 → cpGrayDialog[20]=0x33 → cpAppColor[51]=0x2F)
1139
1140        set(&mut styles, Role::ScrollBarPage, 0x1, 0x3); // blue on cyan (chain: cpScrollBar[1]=0x04 → cpBlueWindow[4]=0x0B → cpAppColor[11]=0x31)
1141        set(&mut styles, Role::ScrollBarControls, 0x1, 0x3); // blue on cyan (chain: cpScrollBar[2]=cpScrollBar[3]=0x05 → cpBlueWindow[5]=0x0C → cpAppColor[12]=0x31)
1142
1143        // Generic control states — tvision-rs-native roles (no inherited palette chain).
1144        set(&mut styles, Role::Normal, 0x0, 0x3); // black on cyan
1145        set(&mut styles, Role::Focused, 0xF, 0x2); // white on green
1146        set(&mut styles, Role::Disabled, 0x8, 0x1); // darkgray on blue
1147        set(&mut styles, Role::Pressed, 0xF, 0x2); // white on green
1148
1149        // List matrix (cpListViewer idx 1..5). Derivation: a list viewer inside a
1150        // gray dialog — the realistic list-box case: cpListViewer → cpGrayDialog →
1151        // cpAppColor. Indices 1 and 2 map to the same dialog entry 26, so the
1152        // active and inactive normals coincide.
1153        set(&mut styles, Role::ListNormal, 0x0, 0x3); // black on cyan (chain: cpListViewer[1]=0x1A → cpGrayDialog[26]=0x39 → cpAppColor[57]=0x30)
1154        set(&mut styles, Role::ListInactive, 0x0, 0x3); // black on cyan (chain: cpListViewer[2]=0x1A → cpGrayDialog[26]=0x39 → cpAppColor[57]=0x30)
1155        set(&mut styles, Role::ListSurface, 0x0, 0x3); // == ListNormal; middle content surface (three-surface rule), themes may restyle to the pane surface
1156        set(&mut styles, Role::ListFocused, 0xF, 0x2); // white on green (chain: cpListViewer[3]=0x1B → cpGrayDialog[27]=0x3A → cpAppColor[58]=0x2F)
1157        set(&mut styles, Role::ListSelected, 0xE, 0x3); // yellow on cyan (chain: cpListViewer[4]=0x1C → cpGrayDialog[28]=0x3B → cpAppColor[59]=0x3E)
1158        set(&mut styles, Role::ListDivider, 0x1, 0x3); // blue on cyan (chain: cpListViewer[5]=0x1D → cpGrayDialog[29]=0x3C → cpAppColor[60]=0x31)
1159        set(&mut styles, Role::TableHeader, 0xE, 0x1); // yellow on blue (tvision-rs-native: the Table column-label row)
1160        set(&mut styles, Role::TableCellCursor, 0x0, 0x7); // black on lightgray (tvision-rs-native: the Table cell cursor; distinct from the focused row (white on green) and the input line (white on blue))
1161
1162        // Feedback family — tvision-rs-native roles (no inherited chain).
1163        set(&mut styles, Role::Error, 0xF, 0x4); // white on red
1164        set(&mut styles, Role::Warning, 0x0, 0x6); // black on brown
1165        set(&mut styles, Role::Info, 0xF, 0x1); // white on blue
1166        set(&mut styles, Role::Success, 0xF, 0x2); // white on green
1167
1168        // Static text + cluster family. Derivation: a static text / cluster inside
1169        // a gray dialog (the realistic owner): cpStaticText / cpCluster →
1170        // cpGrayDialog → cpAppColor. Clusters sit on the classic cyan strip (the
1171        // familiar checkbox/radio look); both shortcut indices map to the same
1172        // dialog entry 18, so the two shortcut roles coincide.
1173        set(&mut styles, Role::StaticText, 0x0, 0x7); // black on lightgray (chain: cpStaticText[1]=0x06 → cpGrayDialog[6]=0x25 → cpAppColor[37]=0x70)
1174        set(&mut styles, Role::ClusterNormal, 0x0, 0x3); // black on cyan (chain: cpCluster[1]=0x10 → cpGrayDialog[16]=0x2F → cpAppColor[47]=0x30)
1175        set(&mut styles, Role::ClusterSelected, 0xF, 0x3); // white on cyan (chain: cpCluster[2]=0x11 → cpGrayDialog[17]=0x30 → cpAppColor[48]=0x3F)
1176        set(&mut styles, Role::ClusterNormalShortcut, 0xE, 0x3); // yellow on cyan (chain: cpCluster[3]=0x12 → cpGrayDialog[18]=0x31 → cpAppColor[49]=0x3E)
1177        set(&mut styles, Role::ClusterSelectedShortcut, 0xE, 0x3); // yellow on cyan (chain: cpCluster[4]=0x12 → cpGrayDialog[18]=0x31 → cpAppColor[49]=0x3E)
1178        set(&mut styles, Role::ClusterDisabled, 0x8, 0x3); // darkgray on cyan (chain: cpCluster[5]=0x1F → cpGrayDialog[31]=0x3E → cpAppColor[62]=0x38)
1179
1180        // Indicator (editor row/col display). Derivation: an indicator inside an
1181        // edit window — a blue window (the edit window does not override the window
1182        // palette, so cpBlueWindow applies): cpIndicator → cpBlueWindow →
1183        // cpAppColor.
1184        set(&mut styles, Role::IndicatorNormal, 0xF, 0x1); // white on blue (chain: cpIndicator[1]=0x02 → cpBlueWindow[2]=0x09 → cpAppColor[9]=0x1F)
1185        set(&mut styles, Role::IndicatorDragging, 0xA, 0x1); // lightgreen on blue (chain: cpIndicator[2]=0x03 → cpBlueWindow[3]=0x0A → cpAppColor[10]=0x1A)
1186
1187        // Button family. Derivation: a button inside a gray dialog (the realistic
1188        // owner): cpButton → cpGrayDialog → cpAppColor. Indices 5..7 all map to the
1189        // same dialog entry 14, so the three shortcut roles coincide.
1190        set(&mut styles, Role::ButtonNormal, 0x0, 0x2); // black on green (chain: cpButton[1]=0x0A → cpGrayDialog[10]=0x29 → cpAppColor[41]=0x20)
1191        set(&mut styles, Role::ButtonDefault, 0xB, 0x2); // lightcyan on green (chain: cpButton[2]=0x0B → cpGrayDialog[11]=0x2A → cpAppColor[42]=0x2B)
1192        set(&mut styles, Role::ButtonSelected, 0xF, 0x2); // white on green (chain: cpButton[3]=0x0C → cpGrayDialog[12]=0x2B → cpAppColor[43]=0x2F)
1193        set(&mut styles, Role::ButtonDisabled, 0x8, 0x7); // darkgray on lightgray (chain: cpButton[4]=0x0D → cpGrayDialog[13]=0x2C → cpAppColor[44]=0x78)
1194        set(&mut styles, Role::ButtonNormalShortcut, 0xE, 0x2); // yellow on green (chain: cpButton[5]=0x0E → cpGrayDialog[14]=0x2D → cpAppColor[45]=0x2E)
1195        set(&mut styles, Role::ButtonDefaultShortcut, 0xE, 0x2); // yellow on green (chain: cpButton[6]=0x0E → cpGrayDialog[14]=0x2D → cpAppColor[45]=0x2E)
1196        set(&mut styles, Role::ButtonSelectedShortcut, 0xE, 0x2); // yellow on green (chain: cpButton[7]=0x0E → cpGrayDialog[14]=0x2D → cpAppColor[45]=0x2E)
1197        set(&mut styles, Role::ButtonShadow, 0x0, 0x7); // black on lightgray (chain: cpButton[8]=0x0F → cpGrayDialog[15]=0x2E → cpAppColor[46]=0x70)
1198
1199        // Label family. Derivation: a label inside a gray dialog (the realistic
1200        // owner): cpLabel → cpGrayDialog → cpAppColor. Both shortcut indices map to
1201        // the same dialog entry 9, so the two shortcut roles coincide.
1202        set(&mut styles, Role::LabelNormal, 0x0, 0x7); // black on lightgray (chain: cpLabel[1]=0x07 → cpGrayDialog[7]=0x26 → cpAppColor[38]=0x70)
1203        set(&mut styles, Role::LabelLight, 0xF, 0x7); // white on lightgray (chain: cpLabel[2]=0x08 → cpGrayDialog[8]=0x27 → cpAppColor[39]=0x7F)
1204        set(&mut styles, Role::LabelNormalShortcut, 0xE, 0x7); // yellow on lightgray (chain: cpLabel[3]=0x09 → cpGrayDialog[9]=0x28 → cpAppColor[40]=0x7E)
1205        set(&mut styles, Role::LabelLightShortcut, 0xE, 0x7); // yellow on lightgray (chain: cpLabel[4]=0x09 → cpGrayDialog[9]=0x28 → cpAppColor[40]=0x7E)
1206
1207        // Input line. Derivation: an input line inside a gray dialog (the realistic
1208        // owner): cpInputLine → cpGrayDialog → cpAppColor. Indices 1 (passive) and
1209        // 2 (active) both map to dialog entry 0x13, so one role serves both field
1210        // states: the classic white-on-blue input field over the gray dialog
1211        // surface.
1212        set(&mut styles, Role::InputNormal, 0xF, 0x1); // white on blue (chain: cpInputLine[1]=cpInputLine[2]=0x13 → cpGrayDialog[19]=0x32 → cpAppColor[50]=0x1F)
1213        set(&mut styles, Role::InputInactive, 0xF, 0x1); // == InputNormal (C++ cpInputLine[1]==cpInputLine[2]==0x13); themes may dim to signal focus
1214        set(&mut styles, Role::InputSurface, 0xF, 0x1); // == InputNormal; middle content surface (three-surface rule), themes may restyle to the pane surface
1215        set(&mut styles, Role::InputSelected, 0xF, 0x2); // white on green (chain: cpInputLine[3]=0x14 → cpGrayDialog[20]=0x33 → cpAppColor[51]=0x2F)
1216        set(&mut styles, Role::InputArrow, 0xA, 0x1); // lightgreen on blue (chain: cpInputLine[4]=0x15 → cpGrayDialog[21]=0x34 → cpAppColor[52]=0x1A)
1217
1218        // Scroller / editor content fill. Derivation: a scroller/editor inside a
1219        // (blue) window — the realistic case, since tvision-rs collapsed per-window
1220        // palettes into a single role:
1221        //   cpScroller[1]=0x06 → cpBlueWindow[6]=0x0D → cpAppColor[0x0D]=0x1E (normal)
1222        //   cpScroller[2]=0x07 → cpBlueWindow[7]=0x0E → cpAppColor[0x0E]=0x71 (selected)
1223        // (The earlier provisional green 0x28/0x24 was the degenerate "scroller
1224        // directly on the program, no window remap" resolution — never the case in
1225        // practice, and it made a live editor render as a flat green field.)
1226        set(&mut styles, Role::ScrollerNormal, 0xE, 0x1); // yellow on blue (0x1E)
1227        set(&mut styles, Role::ScrollerSelected, 0x1, 0x7); // blue on lightgray (0x71)
1228
1229        // Menu family. Derivation: a menu bar/box is owned directly by the program,
1230        // so cpMenuView resolves in ONE hop into cpAppColor — no window/dialog
1231        // remap.
1232        set(&mut styles, Role::MenuNormal, 0x0, 0x7); // black on lightgray (chain: cpMenuView[1]=0x02 → cpAppColor[2]=0x70)
1233        set(&mut styles, Role::MenuNormalShortcut, 0x4, 0x7); // red on lightgray (chain: cpMenuView[3]=0x04 → cpAppColor[4]=0x74)
1234        set(&mut styles, Role::MenuSelected, 0x0, 0x2); // black on green (chain: cpMenuView[4]=0x05 → cpAppColor[5]=0x20)
1235        set(&mut styles, Role::MenuSelectedShortcut, 0x4, 0x2); // red on green (chain: cpMenuView[6]=0x07 → cpAppColor[7]=0x24)
1236        set(&mut styles, Role::MenuDisabled, 0x8, 0x7); // darkgray on lightgray (chain: cpMenuView[2]=0x03 → cpAppColor[3]=0x78)
1237        set(&mut styles, Role::MenuSelectedDisabled, 0x8, 0x2); // darkgray on green (chain: cpMenuView[5]=0x06 → cpAppColor[6]=0x28)
1238
1239        // Status-line family. Derivation: the status line is owned directly by the
1240        // program, so cpStatusLine resolves in ONE hop into cpAppColor — identical
1241        // bytes to the menu family.
1242        set(&mut styles, Role::StatusNormal, 0x0, 0x7); // black on lightgray (chain: cpStatusLine[1]=0x02 → cpAppColor[2]=0x70)
1243        set(&mut styles, Role::StatusShortcut, 0x4, 0x7); // red on lightgray (chain: cpStatusLine[3]=0x04 → cpAppColor[4]=0x74)
1244        set(&mut styles, Role::StatusSelect, 0x0, 0x2); // black on green (chain: cpStatusLine[4]=0x05 → cpAppColor[5]=0x20)
1245        set(&mut styles, Role::StatusShortcutSelect, 0x4, 0x2); // red on green (chain: cpStatusLine[6]=0x07 → cpAppColor[7]=0x24)
1246        set(&mut styles, Role::StatusDisabled, 0x8, 0x7); // darkgray on lightgray (chain: cpStatusLine[2]=0x03 → cpAppColor[3]=0x78)
1247        set(&mut styles, Role::StatusSelDisabled, 0x8, 0x2); // darkgray on green (chain: cpStatusLine[5]=0x06 → cpAppColor[6]=0x28)
1248
1249        // File-info pane. Derivation: cpInfoPane idx 1 → cpGrayDialog[0x1E]=0x3D →
1250        // cpAppColor[0x3D]=0x13 = BIOS attr (bg<<4)|fg with fg=cyan(3), bg=blue(1).
1251        set(&mut styles, Role::InfoPane, 0x3, 0x1); // cyan on blue (0x13)
1252
1253        // Outline viewer. Derivation: an outline viewer inside a (blue) window — the
1254        // realistic owner (same owner pick as the ScrollerNormal precedent above):
1255        // cpOutlineViewer → cpBlueWindow → cpAppColor.
1256        set(&mut styles, Role::OutlineNormal, 0xE, 0x1); // yellow on blue (chain: cpOutlineViewer[1]=0x06 → cpBlueWindow[6]=0x0D → cpAppColor[13]=0x1E)
1257        set(&mut styles, Role::OutlineInactive, 0xE, 0x1); // == OutlineNormal; deviation so themes can dim unfocused outlines
1258        set(&mut styles, Role::OutlineSurface, 0xE, 0x1); // == OutlineNormal; middle content surface (three-surface rule), themes may restyle to the pane surface
1259        set(&mut styles, Role::OutlineFocused, 0x1, 0x7); // blue on lightgray (chain: cpOutlineViewer[2]=0x07 → cpBlueWindow[7]=0x0E → cpAppColor[14]=0x71)
1260        set(&mut styles, Role::OutlineSelected, 0xA, 0x1); // lightgreen on blue (chain: cpOutlineViewer[3]=0x03 → cpBlueWindow[3]=0x0A → cpAppColor[10]=0x1A)
1261        set(&mut styles, Role::OutlineNotExpanded, 0xF, 0x1); // white on blue (chain: cpOutlineViewer[4]=0x08 → cpBlueWindow[8]=0x0F → cpAppColor[15]=0x1F)
1262
1263        // Window/menu drop shadow — the global shadow attribute 0x08.
1264        set(&mut styles, Role::Shadow, 0x8, 0x0); // darkgray on black
1265
1266        Theme {
1267            styles,
1268            glyphs: Glyphs::default(),
1269        }
1270    }
1271
1272    /// The [`Style`] for `role`. Total — never panics.
1273    pub fn style(&self, role: Role) -> Style {
1274        self.styles[role.index()]
1275    }
1276
1277    /// Replace the style for `role` in this theme. Used by the theme editor.
1278    pub fn set_style(&mut self, role: Role, style: Style) {
1279        self.styles[role.index()] = style;
1280    }
1281
1282    /// The theme's glyph holder.
1283    pub fn glyphs(&self) -> &Glyphs {
1284        &self.glyphs
1285    }
1286}
1287
1288impl Default for Theme {
1289    fn default() -> Self {
1290        Self::classic_blue()
1291    }
1292}
1293
1294#[cfg(test)]
1295mod tests {
1296    use super::*;
1297
1298    /// Every variant — alias the pub(crate) ALL so tests don't duplicate the list.
1299    const ALL_ROLES: [Role; ROLE_COUNT] = super::ALL;
1300
1301    #[test]
1302    fn index_is_total_and_distinct() {
1303        let mut seen = [false; ROLE_COUNT];
1304        for role in ALL_ROLES {
1305            let i = role.index();
1306            assert!(i < ROLE_COUNT);
1307            assert!(!seen[i], "duplicate index {i} for {role:?}");
1308            seen[i] = true;
1309        }
1310        assert!(seen.iter().all(|&b| b), "every index must be covered");
1311    }
1312
1313    #[test]
1314    fn style_is_total_over_all_variants() {
1315        let t = Theme::classic_blue();
1316        // Must not panic for any variant.
1317        for role in ALL_ROLES {
1318            let _ = t.style(role);
1319        }
1320    }
1321
1322    /// `InputSurface`, `ListSurface`, and `OutlineSurface` are each the
1323    /// three-surface rule's middle content surface for their widget (active
1324    /// pane, non-focused selectable sibling). In `classic_blue` each must
1325    /// equal its widget's `*Normal` role (as `*Inactive` already does) so the
1326    /// rule collapses to the classic per-window look unthemed — the
1327    /// classic_blue-frozen guarantee of the focus-surface generalization.
1328    #[test]
1329    fn input_surface_matches_input_normal_in_classic_blue() {
1330        let t = Theme::classic_blue();
1331        assert_eq!(t.style(Role::InputSurface), t.style(Role::InputNormal));
1332        assert_eq!(t.style(Role::ListSurface), t.style(Role::ListNormal));
1333        assert_eq!(t.style(Role::OutlineSurface), t.style(Role::OutlineNormal));
1334    }
1335
1336    #[test]
1337    fn each_role_returns_its_seeded_style() {
1338        let t = Theme::classic_blue();
1339        assert_eq!(
1340            t.style(Role::Background),
1341            Style::new(Color::bios_rgb(0x7), Color::bios_rgb(0x1))
1342        );
1343        assert_eq!(
1344            t.style(Role::FrameActive),
1345            Style::new(Color::bios_rgb(0xF), Color::bios_rgb(0x1))
1346        );
1347        assert_eq!(
1348            t.style(Role::Disabled),
1349            Style::new(Color::bios_rgb(0x8), Color::bios_rgb(0x1))
1350        );
1351        assert_eq!(
1352            t.style(Role::ListSelected),
1353            Style::new(Color::bios_rgb(0xE), Color::bios_rgb(0x3))
1354        );
1355        assert_eq!(
1356            t.style(Role::Error),
1357            Style::new(Color::bios_rgb(0xF), Color::bios_rgb(0x4))
1358        );
1359        assert_eq!(
1360            t.style(Role::Success),
1361            Style::new(Color::bios_rgb(0xF), Color::bios_rgb(0x2))
1362        );
1363    }
1364
1365    #[test]
1366    fn default_equals_classic_blue() {
1367        assert_eq!(Theme::default(), Theme::classic_blue());
1368    }
1369
1370    #[test]
1371    fn glyphs_accessor_returns_default() {
1372        let t = Theme::classic_blue();
1373        assert_eq!(*t.glyphs(), Glyphs::default());
1374        // Spot-check the scrollbar glyphs.
1375        assert_eq!(t.glyphs().sb_page, '\u{2592}');
1376        assert_eq!(t.glyphs().sb_thumb, '\u{25A0}');
1377        // Spot-check the frame glyphs.
1378        assert_eq!(t.glyphs().frame_tl, '\u{250C}'); // ┌
1379        assert_eq!(t.glyphs().frame_br, '\u{2518}'); // ┘
1380        assert_eq!(t.glyphs().frame_tl_d, '\u{2554}'); // ╔
1381        assert_eq!(t.glyphs().frame_h_d, '\u{2550}'); // ═
1382        assert_eq!(t.glyphs().close_icon, "[~\u{25A0}~]"); // [~■~]
1383        assert_eq!(t.glyphs().zoom_icon, "[~\u{2191}~]"); // [~↑~]
1384        assert_eq!(t.glyphs().unzoom_icon, "[~\u{2195}~]"); // [~↕~]
1385        assert_eq!(t.glyphs().drag_icon, "~\u{2500}\u{2518}~"); // ~─┘~
1386        assert_eq!(t.glyphs().drag_left_icon, "~\u{2514}\u{2500}~"); // ~└─~
1387    }
1388
1389    #[test]
1390    fn junction_glyphs_seeded() {
1391        let t = Theme::classic_blue();
1392        let g = t.glyphs();
1393        // double
1394        assert_eq!(g.frame_tee_t_d, '╦');
1395        assert_eq!(g.frame_tee_b_d, '╩');
1396        assert_eq!(g.frame_tee_l_d, '╠');
1397        assert_eq!(g.frame_tee_r_d, '╣');
1398        assert_eq!(g.frame_cross_d, '╬');
1399        // mixed: double bar / single stem
1400        assert_eq!(g.frame_tee_t_dh, '╤');
1401        assert_eq!(g.frame_tee_b_dh, '╧');
1402        assert_eq!(g.frame_tee_l_dv, '╟'); // U+255F — double bar + single right stem
1403        assert_eq!(g.frame_tee_r_dv, '╢'); // U+2562 — double bar + single left stem
1404        // mixed: single bar / double stem
1405        assert_eq!(g.frame_tee_t_sh, '╥');
1406        assert_eq!(g.frame_tee_b_sh, '╨');
1407        assert_eq!(g.frame_tee_l_sv, '╞'); // U+255E — single bar + double right stem
1408        assert_eq!(g.frame_tee_r_sv, '╡'); // U+2561 — single bar + double left stem
1409    }
1410}