Skip to content

Commit c6745d3

Browse files
committed
Merge branch '1.0-2025'
2 parents e32c54b + 659d8d5 commit c6745d3

File tree

22 files changed

+181
-147
lines changed

22 files changed

+181
-147
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,3 @@ jobs:
9595
tool: just
9696
- run: just test-package xterm-color
9797
- run: just test-package terminal-colorsaurus
98-
- run: just test-package termtheme

Cargo.lock

Lines changed: 19 additions & 19 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.4.8"
7-
8-
[workspace.dependencies]
9-
terminal-colorsaurus = { path = "crates/terminal-colorsaurus", version = "0.4.7" }
6+
version = "1.0.0"
107

118
[workspace.lints.rust]
129
missing_debug_implementations = "warn"

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
# Changelog
2+
## 1.0.0
3+
### Breaking
4+
* Renamed color scheme to theme mode.
5+
* Marked `Color` as `#[non_exhaustive]` to allow extension.
6+
* Future-proofed `Error::UnsupportedTerminal` by introducing an empty struct.
7+
* Changed the return type of `perceived_lightness` to be a float.
8+
* Removed the `Default` impl from `ColorScheme` (now theme mode).
9+
* Raised the minimum supported rust version (MSRV) to 1.74.0.
10+
11+
### Features
12+
* All structs implement `Hash` now.
13+
214
## 0.4.8
315
* 🐛 Fixed an error on windows where the query would not
416
succeed when the standard input was redirected.

crates/benchmark/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ publish = false
88
clap = { version = "4.4", features = ["derive"] }
99
anstyle = "1.0.8"
1010
indicatif = "0.17.7"
11-
terminal-colorsaurus.workspace = true
11+
terminal-colorsaurus.path = "../terminal-colorsaurus"

crates/benchmark/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn main() -> Result<()> {
4242

4343
let supported = match color_palette(QueryOptions::default()) {
4444
Ok(_) => true,
45-
Err(Error::UnsupportedTerminal) => false,
45+
Err(Error::UnsupportedTerminal(_)) => false,
4646
Err(e) => return Err(e),
4747
};
4848

@@ -54,7 +54,7 @@ fn main() -> Result<()> {
5454
fn bench() -> Result<Duration> {
5555
let start = Instant::now();
5656
match black_box(color_palette(QueryOptions::default())) {
57-
Ok(_) | Err(Error::UnsupportedTerminal) => Ok(start.elapsed()),
57+
Ok(_) | Err(Error::UnsupportedTerminal(_)) => Ok(start.elapsed()),
5858
Err(err) => Err(err),
5959
}
6060
}

crates/pycolorsaurus/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ crate-type = ["cdylib"]
1111

1212
[dependencies]
1313
pyo3 = "0.25.0"
14-
terminal-colorsaurus.workspace = true
14+
terminal-colorsaurus.path = "../terminal-colorsaurus"

crates/pycolorsaurus/src/lib.rs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// Useless conversion is in code generated by PYO3
2-
// FIXME(msrv): Use `#[allow(..., reason = "...")]`
3-
#![allow(clippy::useless_conversion)]
4-
51
use pyo3::{
62
create_exception,
73
exceptions::{PyException, PyIndexError, PyValueError},
@@ -18,12 +14,12 @@ use terminal_colorsaurus as imp;
1814
/// This package helps answer the question "Is this terminal dark or light?".
1915
#[pymodule]
2016
fn colorsaurus(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
21-
m.add_function(wrap_pyfunction!(color_scheme, m)?)?;
17+
m.add_function(wrap_pyfunction!(theme_mode, m)?)?;
2218
m.add_function(wrap_pyfunction!(foreground_color, m)?)?;
2319
m.add_function(wrap_pyfunction!(background_color, m)?)?;
2420
m.add_function(wrap_pyfunction!(color_palette, m)?)?;
2521
m.add("ColorsaurusError", py.get_type::<ColorsaurusError>())?;
26-
m.add("ColorScheme", py.get_type::<ColorScheme>())?;
22+
m.add("ColorScheme", py.get_type::<ThemeMode>())?;
2723
m.add("ColorPalette", py.get_type::<ColorPalette>())?;
2824
m.add("Color", py.get_type::<Color>())?;
2925
Ok(())
@@ -34,9 +30,9 @@ create_exception!(colorsaurus, ColorsaurusError, PyException);
3430
/// Detects if the terminal is dark or light.
3531
#[pyfunction]
3632
#[pyo3(signature = (*, timeout=None))]
37-
fn color_scheme(timeout: Option<Timeout>) -> PyResult<ColorScheme> {
38-
imp::color_scheme(query_options(timeout))
39-
.map(ColorScheme::from)
33+
fn theme_mode(timeout: Option<Timeout>) -> PyResult<ThemeMode> {
34+
imp::theme_mode(query_options(timeout))
35+
.map(ThemeMode::from)
4036
.map_err(to_py_error)
4137
}
4238

@@ -92,7 +88,7 @@ impl<'py> FromPyObject<'py> for Timeout {
9288
}
9389
}
9490

95-
/// The color scheme of the terminal.
91+
/// The terminal's theme mode (i.e. dark or light).
9692
/// This can be retrieved by calling the color_scheme function.
9793
#[pyclass(
9894
eq,
@@ -103,18 +99,18 @@ impl<'py> FromPyObject<'py> for Timeout {
10399
rename_all = "SCREAMING_SNAKE_CASE"
104100
)]
105101
#[derive(PartialEq, Eq, Hash)]
106-
enum ColorScheme {
102+
enum ThemeMode {
107103
/// The terminal uses a dark background with light text.
108104
Dark,
109105
/// The terminal uses a light background with dark text.
110106
Light,
111107
}
112108

113-
impl From<imp::ColorScheme> for ColorScheme {
114-
fn from(value: imp::ColorScheme) -> Self {
109+
impl From<imp::ThemeMode> for ThemeMode {
110+
fn from(value: imp::ThemeMode) -> Self {
115111
match value {
116-
imp::ColorScheme::Dark => Self::Dark,
117-
imp::ColorScheme::Light => Self::Light,
112+
imp::ThemeMode::Dark => Self::Dark,
113+
imp::ThemeMode::Light => Self::Light,
118114
}
119115
}
120116
}
@@ -138,8 +134,8 @@ impl ColorPalette {
138134
}
139135

140136
#[getter]
141-
fn color_scheme(&self) -> ColorScheme {
142-
self.0.color_scheme().into()
137+
fn theme_mode(&self) -> ThemeMode {
138+
self.0.theme_mode().into()
143139
}
144140

145141
#[pyo3(name = "__repr__")]
@@ -168,11 +164,11 @@ impl Color {
168164

169165
#[new]
170166
fn new(red: u8, green: u8, blue: u8) -> Self {
171-
Self(imp::Color {
172-
r: scale_to_u16(red),
173-
g: scale_to_u16(green),
174-
b: scale_to_u16(blue),
175-
})
167+
Self(imp::Color::rgb(
168+
scale_to_u16(red),
169+
scale_to_u16(green),
170+
scale_to_u16(blue),
171+
))
176172
}
177173

178174
#[getter]
@@ -190,10 +186,7 @@ impl Color {
190186
self.0.scale_to_8bit().2
191187
}
192188

193-
/// The perceived lightness of the color
194-
/// as a value between 0 (black) and 100 (white)
195-
/// where 50 is the perceptual "middle grey".
196-
fn perceived_lightness(&self) -> u8 {
189+
fn perceived_lightness(&self) -> f32 {
197190
self.0.perceived_lightness()
198191
}
199192

crates/pycolorsaurus/uv.lock

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

crates/terminal-colorsaurus/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords = ["terminal", "light", "dark", "color-scheme", "cli"]
88
license = "MIT OR Apache-2.0"
99
version.workspace = true
1010
edition = "2021"
11-
rust-version = "1.70.0" # Search for `FIXME(msrv)` when bumping.
11+
rust-version = "1.74.0" # Search for `FIXME(msrv)` when bumping.
1212
exclude = [".github", ".gitignore", "*.sh", "benchmark/**/*", "doc/issues.md", "deny.toml"]
1313

1414
[dependencies]

0 commit comments

Comments
 (0)