1- // Useless conversion is in code generated by PYO3
2- // FIXME(msrv): Use `#[allow(..., reason = "...")]`
3- #![ allow( clippy:: useless_conversion) ]
4-
51use 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]
2016fn 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
0 commit comments