fix: suppress verbose CLI logging on Windows alt-screen to prevent TUI leak, restore on cleanup
On Windows, stderr cannot be redirected to the log file (no dup2). Suppress verbose CLI logging once the alt-screen is active so eprintln! calls from crate::logging don't leak into the TUI buffer. Also restores verbose logging on all cleanup paths after leaving alt-screen.
This commit is contained in:
committed by
Hunter Bown
parent
57625af4f8
commit
007140ec9e
@@ -289,6 +289,11 @@ pub async fn run_tui(config: &Config, options: TuiOptions) -> Result<()> {
|
||||
if use_alt_screen {
|
||||
execute!(stdout, EnterAlternateScreen)?;
|
||||
}
|
||||
// On Windows, stderr cannot be redirected to the log file (no dup2).
|
||||
// Suppress verbose CLI logging once the alt-screen is active so
|
||||
// eprintln! calls from crate::logging don't leak into the TUI buffer.
|
||||
#[cfg(windows)]
|
||||
crate::logging::set_verbose(false);
|
||||
// Initialize the file-backed TUI log and (on Unix) redirect raw stderr
|
||||
// away from the alt-screen for the lifetime of this guard. Any
|
||||
// `eprintln!`, panic message, or third-party stderr write that would
|
||||
@@ -561,6 +566,8 @@ pub async fn run_tui(config: &Config, options: TuiOptions) -> Result<()> {
|
||||
disable_raw_mode()?;
|
||||
if use_alt_screen {
|
||||
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
|
||||
#[cfg(windows)]
|
||||
crate::logging::set_verbose(crate::logging::env_requests_verbose_logging());
|
||||
}
|
||||
if use_mouse_capture {
|
||||
execute!(terminal.backend_mut(), DisableMouseCapture)?;
|
||||
@@ -623,6 +630,8 @@ impl Drop for TerminalCleanupGuard {
|
||||
let _ = disable_raw_mode();
|
||||
if self.use_alt_screen {
|
||||
let _ = execute!(stdout, LeaveAlternateScreen);
|
||||
#[cfg(windows)]
|
||||
crate::logging::set_verbose(crate::logging::env_requests_verbose_logging());
|
||||
}
|
||||
if self.use_mouse_capture {
|
||||
let _ = execute!(stdout, DisableMouseCapture);
|
||||
@@ -7026,6 +7035,8 @@ fn pause_terminal(
|
||||
disable_raw_mode()?;
|
||||
if use_alt_screen {
|
||||
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
|
||||
#[cfg(windows)]
|
||||
crate::logging::set_verbose(crate::logging::env_requests_verbose_logging());
|
||||
}
|
||||
if use_mouse_capture {
|
||||
execute!(terminal.backend_mut(), DisableMouseCapture)?;
|
||||
@@ -7047,6 +7058,10 @@ fn resume_terminal(
|
||||
if use_alt_screen {
|
||||
execute!(terminal.backend_mut(), EnterAlternateScreen)?;
|
||||
}
|
||||
// Re-entering alt-screen after mode recovery — suppress verbose
|
||||
// CLI logging again so eprintln! doesn't leak into the TUI.
|
||||
#[cfg(windows)]
|
||||
crate::logging::set_verbose(false);
|
||||
recover_terminal_modes(
|
||||
terminal.backend_mut(),
|
||||
use_mouse_capture,
|
||||
@@ -7159,6 +7174,8 @@ pub fn emergency_restore_terminal() {
|
||||
let _ = execute!(stdout, DisableMouseCapture);
|
||||
let _ = disable_raw_mode();
|
||||
let _ = execute!(stdout, LeaveAlternateScreen);
|
||||
#[cfg(windows)]
|
||||
crate::logging::set_verbose(crate::logging::env_requests_verbose_logging());
|
||||
}
|
||||
|
||||
/// On Windows, ensure the console input handle has `ENABLE_WINDOW_INPUT`
|
||||
|
||||
Reference in New Issue
Block a user