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
use super::{Color, ColorPair, Palette, PaletteColor};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct ColorStyle {
pub front: ColorType,
pub back: ColorType,
}
impl ColorStyle {
pub fn new<F, B>(front: F, back: B) -> Self
where
F: Into<ColorType>,
B: Into<ColorType>,
{
let front = front.into();
let back = back.into();
Self { front, back }
}
pub fn terminal_default() -> Self {
Self::new(Color::TerminalDefault, Color::TerminalDefault)
}
pub fn background() -> Self {
Self::new(PaletteColor::Background, PaletteColor::Background)
}
pub fn shadow() -> Self {
Self::new(PaletteColor::Shadow, PaletteColor::Shadow)
}
pub fn primary() -> Self {
Self::new(PaletteColor::Primary, PaletteColor::View)
}
pub fn secondary() -> Self {
Self::new(PaletteColor::Secondary, PaletteColor::View)
}
pub fn tertiary() -> Self {
Self::new(PaletteColor::Tertiary, PaletteColor::View)
}
pub fn title_primary() -> Self {
Self::new(PaletteColor::TitlePrimary, PaletteColor::View)
}
pub fn title_secondary() -> Self {
Self::new(PaletteColor::TitleSecondary, PaletteColor::View)
}
pub fn highlight() -> Self {
Self::new(PaletteColor::View, PaletteColor::Highlight)
}
pub fn highlight_inactive() -> Self {
Self::new(PaletteColor::View, PaletteColor::HighlightInactive)
}
pub fn resolve(&self, palette: &Palette) -> ColorPair {
ColorPair {
front: self.front.resolve(palette),
back: self.back.resolve(palette),
}
}
}
impl From<Color> for ColorStyle {
fn from(color: Color) -> Self {
Self::new(color, PaletteColor::View)
}
}
impl From<PaletteColor> for ColorStyle {
fn from(color: PaletteColor) -> Self {
Self::new(color, PaletteColor::View)
}
}
impl From<ColorType> for ColorStyle {
fn from(color: ColorType) -> Self {
Self::new(color, PaletteColor::View)
}
}
impl<F, B> From<(F, B)> for ColorStyle
where
F: Into<ColorType>,
B: Into<ColorType>,
{
fn from((front, back): (F, B)) -> Self {
Self::new(front, back)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ColorType {
Palette(PaletteColor),
Color(Color),
}
impl ColorType {
pub fn resolve(self, palette: &Palette) -> Color {
match self {
ColorType::Color(color) => color,
ColorType::Palette(color) => color.resolve(palette),
}
}
}
impl From<Color> for ColorType {
fn from(color: Color) -> Self {
ColorType::Color(color)
}
}
impl From<PaletteColor> for ColorType {
fn from(color: PaletteColor) -> Self {
ColorType::Palette(color)
}
}