@@ -248,9 +248,56 @@ pub fn set_modes() -> Result<()> {
248248 let _ = execute ! ( stdout( ) , EnableFocusChange ) ;
249249 #[ cfg( windows) ]
250250 let _ = execute ! ( stdout( ) , DisableFocusChange ) ;
251+ // Ask the terminal to report dark/light switches (DEC private mode 2031) so the palette
252+ // and adaptive syntax theme can follow the OS appearance without a restart. Terminals
253+ // that do not implement the mode ignore the request.
254+ #[ cfg( not( windows) ) ]
255+ let _ = execute ! ( stdout( ) , EnableColorSchemeReport ) ;
251256 Ok ( ( ) )
252257}
253258
259+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
260+ struct EnableColorSchemeReport ;
261+
262+ impl Command for EnableColorSchemeReport {
263+ fn write_ansi ( & self , f : & mut impl fmt:: Write ) -> fmt:: Result {
264+ write ! ( f, "\x1b [?2031h" )
265+ }
266+
267+ #[ cfg( windows) ]
268+ fn execute_winapi ( & self ) -> Result < ( ) > {
269+ Err ( std:: io:: Error :: other (
270+ "tried to execute EnableColorSchemeReport using WinAPI; use ANSI instead" ,
271+ ) )
272+ }
273+
274+ #[ cfg( windows) ]
275+ fn is_ansi_code_supported ( & self ) -> bool {
276+ true
277+ }
278+ }
279+
280+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
281+ struct DisableColorSchemeReport ;
282+
283+ impl Command for DisableColorSchemeReport {
284+ fn write_ansi ( & self , f : & mut impl fmt:: Write ) -> fmt:: Result {
285+ write ! ( f, "\x1b [?2031l" )
286+ }
287+
288+ #[ cfg( windows) ]
289+ fn execute_winapi ( & self ) -> Result < ( ) > {
290+ Err ( std:: io:: Error :: other (
291+ "tried to execute DisableColorSchemeReport using WinAPI; use ANSI instead" ,
292+ ) )
293+ }
294+
295+ #[ cfg( windows) ]
296+ fn is_ansi_code_supported ( & self ) -> bool {
297+ true
298+ }
299+ }
300+
254301#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
255302struct EnableAlternateScroll ;
256303
@@ -320,6 +367,8 @@ fn restore_common(
320367 first_error. get_or_insert ( err) ;
321368 }
322369 let _ = execute ! ( stdout( ) , DisableFocusChange ) ;
370+ #[ cfg( not( windows) ) ]
371+ let _ = execute ! ( stdout( ) , DisableColorSchemeReport ) ;
323372 if matches ! ( raw_mode_restore, RawModeRestore :: Disable )
324373 && let Err ( err) = disable_raw_mode ( )
325374 {
0 commit comments