1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//! App color palette and border glyph set — passed explicitly to
//! `Block`/`SmashBorder`; other widgets take plain color params
//! instead of a whole `Theme`.
use crate::buffer::CellStyle;
use crossterm::style::Color;
/// The glyphs a bordered widget draws its edges/corners with.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct BorderSet {
/// Top/bottom edge glyph.
pub horizontal: char,
/// Left/right edge glyph.
pub vertical: char,
/// Top-left corner glyph.
pub top_left: char,
/// Top-right corner glyph.
pub top_right: char,
/// Bottom-left corner glyph.
pub bottom_left: char,
/// Bottom-right corner glyph.
pub bottom_right: char,
}
impl BorderSet {
/// Real box-drawing glyphs (`┌┐└┘─│`) — the default border look.
pub const fn single_line() -> Self {
BorderSet {
horizontal: '─',
vertical: '│',
top_left: '┌',
top_right: '┐',
bottom_left: '└',
bottom_right: '┘',
}
}
/// Plain ASCII (`-|+`), the same `+` at every corner — for apps
/// that want the pre-1.0 look.
pub const fn ascii() -> Self {
BorderSet {
horizontal: '-',
vertical: '|',
top_left: '+',
top_right: '+',
bottom_left: '+',
bottom_right: '+',
}
}
}
impl Default for BorderSet {
fn default() -> Self {
Self::single_line()
}
}
/// An app's color palette and border style, passed to `Block`/
/// `SmashBorder` renders.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Theme {
/// Base background color.
pub background: Color,
/// Main accent/brand color.
pub primary: Color,
/// Secondary accent color.
pub secondary: Color,
/// Tertiary accent color.
pub tertiary: Color,
/// Highlight/selection color.
pub accent: Color,
/// When set, `Block` ramps the border ring's color from `primary`
/// toward this along a top-left-to-bottom-right diagonal across
/// the border's bounding box, clamping to this color past the
/// diagonal — NOT a true perimeter/arc-length gradient, so
/// roughly the bottom-right half of a typical ring renders as a
/// flat `primary_end` rather than a visible ramp. Both `primary`
/// and this color must be `Color::Rgb` for the lerp to actually
/// interpolate; `easing::lerp_color`'s existing fallback returns
/// the target color outright for any other color type, so a
/// non-`Rgb` `primary`/`primary_end` pair renders as a flat
/// `primary_end` color, not a gradient.
pub primary_end: Option<Color>,
/// Border glyph set.
pub border: BorderSet,
/// Style applied to every border cell (not title cells — see
/// `Block::render`). Reuses `Cell`'s own style type rather than a
/// narrower bool, so future border attributes (underline, etc.)
/// need no further `Theme` field growth.
pub border_style: CellStyle,
/// Whether `Block` draws an outward second border ring.
pub border_thick: bool,
}
impl Default for Theme {
fn default() -> Self {
Theme {
background: Color::Reset,
primary: Color::Reset,
secondary: Color::Reset,
tertiary: Color::Reset,
accent: Color::Reset,
primary_end: None,
border: BorderSet::default(),
border_style: CellStyle::default(),
border_thick: false,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn single_line_uses_real_box_drawing_glyphs() {
let b = BorderSet::single_line();
assert_eq!(b.horizontal, '─');
assert_eq!(b.vertical, '│');
assert_eq!(b.top_left, '┌');
assert_eq!(b.top_right, '┐');
assert_eq!(b.bottom_left, '└');
assert_eq!(b.bottom_right, '┘');
}
#[test]
fn ascii_uses_a_plus_at_every_corner() {
let b = BorderSet::ascii();
assert_eq!(b.horizontal, '-');
assert_eq!(b.vertical, '|');
assert_eq!(b.top_left, '+');
assert_eq!(b.top_right, '+');
assert_eq!(b.bottom_left, '+');
assert_eq!(b.bottom_right, '+');
}
#[test]
fn default_matches_single_line() {
assert_eq!(BorderSet::default(), BorderSet::single_line());
}
#[test]
fn default_theme_uses_reset_colors_and_default_border() {
let t = Theme::default();
assert_eq!(t.background, Color::Reset);
assert_eq!(t.primary, Color::Reset);
assert_eq!(t.secondary, Color::Reset);
assert_eq!(t.tertiary, Color::Reset);
assert_eq!(t.accent, Color::Reset);
assert_eq!(t.border, BorderSet::default());
}
#[test]
fn default_theme_border_style_is_default() {
assert_eq!(Theme::default().border_style, CellStyle::default());
}
#[test]
fn default_theme_border_thick_is_false() {
assert!(!Theme::default().border_thick);
}
#[test]
fn default_theme_primary_end_is_none() {
assert_eq!(Theme::default().primary_end, None);
}
}