@@ -33,42 +33,49 @@ create_exception!(colorsaurus, ColorsaurusError, PyException);
3333
3434/// Detects if the terminal is dark or light.
3535#[ pyfunction]
36- #[ pyo3( signature = ( * , timeout=None ) ) ]
37- fn color_scheme ( timeout : Option < Timeout > ) -> PyResult < ColorScheme > {
38- imp:: color_scheme ( query_options ( timeout) )
36+ #[ pyo3( signature = ( * , timeout=None , require_terminal_on_stdout=false ) ) ]
37+ fn color_scheme (
38+ timeout : Option < Timeout > ,
39+ require_terminal_on_stdout : bool ,
40+ ) -> PyResult < ColorScheme > {
41+ imp:: color_scheme ( query_options ( timeout, require_terminal_on_stdout) )
3942 . map ( ColorScheme :: from)
4043 . map_err ( to_py_error)
4144}
4245
4346/// Queries the terminal for it's foreground and background color.
4447#[ pyfunction]
45- #[ pyo3( signature = ( * , timeout=None ) ) ]
46- fn color_palette ( timeout : Option < Timeout > ) -> PyResult < ColorPalette > {
47- imp:: color_palette ( query_options ( timeout) )
48+ #[ pyo3( signature = ( * , timeout=None , require_terminal_on_stdout=false ) ) ]
49+ fn color_palette (
50+ timeout : Option < Timeout > ,
51+ require_terminal_on_stdout : bool ,
52+ ) -> PyResult < ColorPalette > {
53+ imp:: color_palette ( query_options ( timeout, require_terminal_on_stdout) )
4854 . map ( ColorPalette )
4955 . map_err ( to_py_error)
5056}
5157
5258/// Queries the terminal for it's foreground color.
5359#[ pyfunction]
54- #[ pyo3( signature = ( * , timeout=None ) ) ]
55- fn foreground_color ( timeout : Option < Timeout > ) -> PyResult < Color > {
56- imp:: foreground_color ( query_options ( timeout) )
60+ #[ pyo3( signature = ( * , timeout=None , require_terminal_on_stdout= false ) ) ]
61+ fn foreground_color ( timeout : Option < Timeout > , require_terminal_on_stdout : bool ) -> PyResult < Color > {
62+ imp:: foreground_color ( query_options ( timeout, require_terminal_on_stdout ) )
5763 . map ( Color )
5864 . map_err ( to_py_error)
5965}
6066
6167/// Queries the terminal for it's background color.
6268#[ pyfunction]
63- #[ pyo3( signature = ( * , timeout=None ) ) ]
64- fn background_color ( timeout : Option < Timeout > ) -> PyResult < Color > {
65- imp:: background_color ( query_options ( timeout) )
69+ #[ pyo3( signature = ( * , timeout=None , require_terminal_on_stdout= false ) ) ]
70+ fn background_color ( timeout : Option < Timeout > , require_terminal_on_stdout : bool ) -> PyResult < Color > {
71+ imp:: background_color ( query_options ( timeout, require_terminal_on_stdout ) )
6672 . map ( Color )
6773 . map_err ( to_py_error)
6874}
6975
70- fn query_options ( timeout : Option < Timeout > ) -> imp:: QueryOptions {
71- let mut options = imp:: QueryOptions :: default ( ) ;
76+ fn query_options ( timeout : Option < Timeout > , require_terminal_on_stdout : bool ) -> imp:: QueryOptions {
77+ let mut options =
78+ imp:: QueryOptions :: default ( ) . with_require_terminal_on_stdout ( require_terminal_on_stdout) ;
7279 options. timeout = timeout. map ( |t| t. 0 ) . unwrap_or ( options. timeout ) ;
7380 options
7481}
0 commit comments