Skip to content

Commit 6a209e5

Browse files
authored
Update color API (#619)
This is a breaking change because it removes and renames some methods. It also makes the `rgb()` method public.
2 parents d583a4d + 610b448 commit 6a209e5

File tree

9 files changed

+26
-50
lines changed

9 files changed

+26
-50
lines changed

Cargo.lock

Lines changed: 3 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ members = ["gengo", "gengo-bin", "samples-test"]
33
resolver = "2"
44

55
[workspace.dependencies]
6-
chromaterm = "0.1.1"
76
indexmap = "2"
8-
owo-colors = ">=3, <=4"
97
serde_json = "1"
108

119
[workspace.package]
1210
description = "Get the language distribution stats of your repository"
13-
version = "0.13.3"
11+
version = "0.14.0"
1412
edition = "2024"
1513
repository = "https://github.com/spenserblack/gengo"
1614
readme = "README.md"

gengo-bin/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ name = "gengo"
1818

1919
[features]
2020
default = ["color", "gengo/max-performance"]
21-
color = ["chromaterm", "gengo/chromaterm", "relative-luminance"]
21+
color = ["dep:chromaterm", "dep:relative-luminance"]
2222

2323
[dependencies]
24-
chromaterm = { workspace = true, optional = true }
24+
chromaterm = { version = "0.1.1", optional = true }
2525
clap = { version = "4", features = ["derive", "wrap_help"] }
26-
gengo = { path = "../gengo", version = "0.13", default-features = false, features = [
26+
gengo = { path = "../gengo", version = "0.14", default-features = false, features = [
2727
"directory",
2828
"git",
2929
] }

gengo-bin/src/cli.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ impl CLI {
136136
for (language, size) in summary.iter() {
137137
let percentage = (*size * 100) as f64 / total;
138138
#[cfg(feature = "color")]
139-
let color = language.chromaterm_color();
139+
let color = {
140+
let (r, g, b) = language.rgb();
141+
chromaterm::colors::True::from_rgb(r, g, b)
142+
};
140143
#[cfg(not(feature = "color"))]
141144
let color = ();
142145

@@ -198,7 +201,10 @@ impl CLI {
198201

199202
for (language, files) in files_per_language.into_iter() {
200203
#[cfg(feature = "color")]
201-
let color = language.chromaterm_color();
204+
let color = {
205+
let (r, g, b) = language.rgb();
206+
chromaterm::colors::True::from_rgb(r, g, b)
207+
};
202208
#[cfg(not(feature = "color"))]
203209
let color = ();
204210

gengo-bin/tests/snapshots/test_cli__json_output_on_javascript_repo.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ expression: json
99
"generated": false,
1010
"language": {
1111
"category": "programming",
12-
"color": "#F0DC4E",
12+
"hex": "#F0DC4E",
1313
"name": "JavaScript",
1414
"nerd_font_glyph": ""
1515
},
@@ -22,7 +22,7 @@ expression: json
2222
"generated": true,
2323
"language": {
2424
"category": "prose",
25-
"color": "#000000",
25+
"hex": "#000000",
2626
"name": "Plain Text",
2727
"nerd_font_glyph": null
2828
},
@@ -35,7 +35,7 @@ expression: json
3535
"generated": false,
3636
"language": {
3737
"category": "markup",
38-
"color": "#E96228",
38+
"hex": "#E96228",
3939
"name": "HTML",
4040
"nerd_font_glyph": ""
4141
},
@@ -48,7 +48,7 @@ expression: json
4848
"generated": false,
4949
"language": {
5050
"category": "programming",
51-
"color": "#F0DC4E",
51+
"hex": "#F0DC4E",
5252
"name": "JavaScript",
5353
"nerd_font_glyph": ""
5454
},
@@ -61,7 +61,7 @@ expression: json
6161
"generated": false,
6262
"language": {
6363
"category": "programming",
64-
"color": "#2F74C0",
64+
"hex": "#2F74C0",
6565
"name": "TypeScript",
6666
"nerd_font_glyph": ""
6767
},

gengo/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ max-performance = ["dep:gix", "gix/max-performance"]
2626
max-performance-safe = ["dep:gix", "gix/max-performance-safe"]
2727

2828
[dependencies]
29-
chromaterm = { workspace = true, optional = true }
3029
gix = { version = ">= 0.56, <= 0.72", optional = true, default-features = false, features = [
3130
"attributes",
3231
"index",
@@ -36,7 +35,6 @@ gix = { version = ">= 0.56, <= 0.72", optional = true, default-features = false,
3635
glob = "0.3"
3736
ignore = { version = "0.4", optional = true }
3837
indexmap = { workspace = true, features = ["rayon", "serde"] }
39-
owo-colors = { workspace = true, optional = true }
4038
rayon = "1"
4139
regex = "1"
4240
serde = { version = "1", features = ["derive"] }

gengo/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ fn main() -> Result<(), Box<dyn Error>> {
308308
);
309309
let color_hex_mixin = quote! {
310310
impl Language {
311-
/// Gets the color associated with the language.
312-
pub const fn color(&self) -> &'static str {
311+
/// Gets the hex code associated with the language.
312+
pub const fn hex(&self) -> &'static str {
313313
match self {
314314
#(#color_hex_mappings ,)*
315315
}
@@ -335,7 +335,7 @@ fn main() -> Result<(), Box<dyn Error>> {
335335
let color_rgb_mixin = quote! {
336336
impl Language {
337337
/// Gets the RGB color associated with the language.
338-
const fn color_rgb(&self) -> (u8, u8, u8) {
338+
pub const fn rgb(&self) -> (u8, u8, u8) {
339339
match self {
340340
#(#color_rgb_mappings ,)*
341341
}

gengo/src/language/mod.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl Language {
198198
Serialize {
199199
name: self.name(),
200200
category: self.category(),
201-
color: self.color(),
201+
hex: self.hex(),
202202
nerd_font_glyph: self.nerd_font_glyph(),
203203
}
204204
}
@@ -228,24 +228,6 @@ impl serde::Serialize for Language {
228228
}
229229
}
230230

231-
#[cfg(feature = "chromaterm")]
232-
impl Language {
233-
/// Converts the color to RGB true color.
234-
pub const fn chromaterm_color(&self) -> chromaterm::colors::True {
235-
let (r, g, b) = self.color_rgb();
236-
chromaterm::colors::True::from_rgb(r, g, b)
237-
}
238-
}
239-
240-
#[cfg(feature = "owo-colors")]
241-
impl Language {
242-
/// Converts the color to RGB.
243-
pub const fn owo_color(&self) -> owo_colors::Rgb {
244-
let (r, g, b) = self.color_rgb();
245-
owo_colors::Rgb(r, g, b)
246-
}
247-
}
248-
249231
/// A category for a language.
250232
#[non_exhaustive]
251233
#[derive(Clone, Debug, serde::Deserialize, Eq, Hash, PartialEq, serde::Serialize)]
@@ -270,7 +252,7 @@ pub enum Category {
270252
struct Serialize {
271253
name: &'static str,
272254
category: Category,
273-
color: &'static str,
255+
hex: &'static str,
274256
nerd_font_glyph: Option<&'static str>,
275257
}
276258

samples-test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ license.workspace = true
1010
keywords.workspace = true
1111

1212
[dependencies]
13-
gengo = { path = "../gengo", version = "0.13", default-features = false }
13+
gengo = { path = "../gengo", version = "0.14", default-features = false }

0 commit comments

Comments
 (0)