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
// This file is part of o2.
//
// Copyright (c) 2026 René Coignard <contact@renecoignard.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Colour palette and style-type definitions.
//!
//! The nine base colours are declared as constants and a [`StyleType`] enum
//! maps each semantic rendering category to a foreground/background pair.
//! Both the constants and the enum correspond to the nine-slot theme format
//! used throughout the application.
use Color;
/// Pure white; used for high-contrast foreground elements.
pub const F_HIGH: Color = Rgb;
/// Medium grey; used for secondary foreground text (status bar labels, etc.).
pub const F_MED: Color = Rgb;
/// Dark grey; the default foreground colour for most grid glyphs.
pub const F_LOW: Color = Rgb;
/// Black; foreground on inverted or selected cells.
pub const F_INV: Color = Rgb;
/// Near-white; the primary output and highlighted text colour.
pub const B_HIGH: Color = Rgb;
/// Teal / cyan; operator and haste port accent colour.
pub const B_MED: Color = Rgb;
/// Dark grey; used sparingly for background accents.
pub const B_LOW: Color = Rgb;
/// Amber / orange; selection highlight and reader accent colour.
pub const B_INV: Color = Rgb;
/// True black; the canvas background colour.
pub const BG: Color = Rgb;
/// Semantic rendering categories used by the grid and status-bar renderer.
///
/// Each variant corresponds to a distinct visual role. The [`StyleType::colors`]
/// method resolves a variant to its `(foreground, background)` colour pair,
/// where `None` means "inherit from context" (i.e. use the canvas background).
/// Scales the brightness of an RGB colour to the specified percentage.
///
/// The `percent` argument determines the remaining brightness of the colour:
/// a value of `100` leaves the colour completely unchanged, `50` reduces its
/// channel values by half, and `0` yields pure black. Values above `100` will
/// brighten the colour (clamping at 255 due to `u8` conversion limits).
///
/// Note that this function only operates on [`Color::Rgb`] variants. If any
/// other [`Color`] variant is passed (such as named or ANSI indexed colours),
/// it is returned unmodified.
///
/// # Examples
///
/// ```
/// use ratatui::style::Color;
/// use o2_rs::ui::theme::darken;
///
/// let base = Color::Rgb(100, 200, 50);
/// let dark = darken(base, 60); // 60% of original brightness
/// assert_eq!(dark, Color::Rgb(60, 120, 30));
/// ```
pub const