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
use std::fmt;
/// Error type for palette lookup and color conversion.
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
/// The requested palette family does not exist.
UnknownFamily {
/// Requested family name.
family: String,
},
/// The requested variant does not exist within a known family.
UnknownVariant {
/// Requested family name.
family: String,
/// Requested variant name.
variant: String,
},
/// The requested iTerm palette does not exist.
UnknownItermPalette {
/// Requested iTerm theme name.
palette: String,
},
/// The requested Gephi palette does not exist.
UnknownGephiPalette {
/// Requested Gephi palette name.
palette: String,
},
/// A Gephi palette could not be generated.
GephiGenerationFailed {
/// Canonical Gephi palette name.
palette: &'static str,
/// Description of the generation failure.
reason: String,
},
/// The requested iTerm variant does not exist.
UnknownItermVariant {
/// Requested iTerm variant name.
variant: String,
},
/// A palette specification was not written as `family:variant`.
InvalidPaletteSpec {
/// Requested palette specification.
spec: String,
},
/// A hex color string was malformed.
InvalidHexColor {
/// Requested hex color.
input: String,
},
/// A floating-point alpha value was outside its operation's valid range.
InvalidAlpha {
/// Requested alpha value.
alpha: f32,
},
/// More colors were requested than a discrete palette contains.
TooManyColorsRequested {
/// Palette family.
family: &'static str,
/// Palette variant.
variant: &'static str,
/// Requested number of colors.
requested: usize,
/// Available number of colors.
available: usize,
},
/// More colors were requested than an iTerm variant contains.
TooManyItermColorsRequested {
/// Canonical iTerm theme name.
palette: &'static str,
/// Canonical iTerm variant name.
variant: &'static str,
/// Requested number of colors.
requested: usize,
/// Available number of colors.
available: usize,
},
/// A discrete-only operation was requested for a continuous palette.
NotDiscretePalette {
/// Palette family.
family: &'static str,
/// Palette variant.
variant: &'static str,
},
/// A continuous-only operation was requested for a discrete palette.
NotContinuousPalette {
/// Palette family.
family: &'static str,
/// Palette variant.
variant: &'static str,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownFamily { family } => {
write!(f, "unknown ggsci palette family `{family}`")
}
Self::UnknownVariant { family, variant } => {
write!(f, "unknown ggsci palette variant `{variant}` for family `{family}`")
}
Self::UnknownItermPalette { palette } => {
write!(f, "unknown ggsci iTerm palette `{palette}`")
}
Self::UnknownGephiPalette { palette } => {
write!(f, "unknown ggsci Gephi palette `{palette}`")
}
Self::GephiGenerationFailed { palette, reason } => {
write!(f, "could not generate Gephi palette `{palette}`: {reason}")
}
Self::UnknownItermVariant { variant } => {
write!(f, "unknown ggsci iTerm variant `{variant}`")
}
Self::InvalidPaletteSpec { spec } => {
write!(f, "invalid palette spec `{spec}`; expected `family:variant`")
}
Self::InvalidHexColor { input } => {
write!(f, "invalid hex color `{input}`; expected `#RRGGBB`")
}
Self::InvalidAlpha { alpha } => {
write!(
f,
"invalid alpha `{alpha}`; expected a finite value in 0.0..=1.0 (continuous, iTerm, and Gephi palette operations require alpha > 0.0)"
)
}
Self::TooManyColorsRequested {
family,
variant,
requested,
available,
} => write!(
f,
"requested {requested} colors from discrete palette `{family}:{variant}`, but only {available} category colors are available"
),
Self::TooManyItermColorsRequested {
palette,
variant,
requested,
available,
} => write!(
f,
"requested {requested} colors from iTerm palette `{palette}` ({variant}), but only {available} terminal colors are available"
),
Self::NotDiscretePalette { family, variant } => write!(
f,
"`{family}:{variant}` is a continuous palette; this operation requires a discrete palette"
),
Self::NotContinuousPalette { family, variant } => write!(
f,
"`{family}:{variant}` is a discrete palette; this operation requires a continuous palette"
),
}
}
}
impl std::error::Error for Error {}