Skip to main content

max / alloy_tui

1.7 KB · 45 lines History Blame Raw
1 //! Themed span helpers.
2 //!
3 //! sysop-tui's `style.rs` offered the same set (`fg`, `dim`, `bold`, `ok`,
4 //! `warn`, `fault`) against a const palette. Alloy's palette is loaded at
5 //! runtime, so each helper takes the `&Theme` instead. The status-colored
6 //! variants are gone: they collapse into [`Severity`](crate::Severity), which
7 //! already owns the mapping from intent to `status.*` color.
8
9 use ratatui::style::{Modifier, Style};
10 use ratatui::text::Span;
11
12 use crate::theme::Theme;
13
14 /// Body text in the primary content color.
15 pub fn primary(theme: &Theme, s: impl Into<String>) -> Span<'static> {
16 Span::styled(s.into(), Style::default().fg(theme.content_primary))
17 }
18
19 /// De-emphasized text — labels, units, inactive rows.
20 pub fn muted(theme: &Theme, s: impl Into<String>) -> Span<'static> {
21 Span::styled(s.into(), Style::default().fg(theme.content_muted))
22 }
23
24 /// Supporting text: dimmer than primary, louder than muted.
25 pub fn secondary(theme: &Theme, s: impl Into<String>) -> Span<'static> {
26 Span::styled(s.into(), Style::default().fg(theme.content_secondary))
27 }
28
29 /// Emphasized body text.
30 pub fn bold(theme: &Theme, s: impl Into<String>) -> Span<'static> {
31 Span::styled(
32 s.into(),
33 Style::default()
34 .fg(theme.content_primary)
35 .add_modifier(Modifier::BOLD),
36 )
37 }
38
39 /// A key hint or other interactive affordance. The one accent-on-text use that
40 /// is not a `Severity` — DESIGN-LANGUAGE.md allows the action color here
41 /// because a key hint *is* the actionable element, not decoration.
42 pub fn action(theme: &Theme, s: impl Into<String>) -> Span<'static> {
43 Span::styled(s.into(), Style::default().fg(theme.action_primary))
44 }
45