Skip to content

Commit d5dd055

Browse files
authored
fix: restore terminal state after video prompt timeout (#303)
## Summary Fixes terminal being left in a broken state after t-rec completes when the video generation prompt times out. ### Problem When the video generation prompt times out (after 15 seconds of no input), the dialoguer thread is abandoned while still waiting for input. This leaves the terminal in a modified state (hidden cursor, raw mode), requiring users to run `reset` to restore normal terminal behavior. ### Solution Use `dialoguer::console::Term` to explicitly restore the terminal state by calling `show_cursor()` after timeout. This ensures the cursor is visible and the terminal behaves normally after t-rec exits. ## Test plan - [x] Run `t-rec`, let the video prompt timeout (wait 15s) → terminal should work normally after - [x] Run `t-rec`, press `y` at video prompt → terminal should work normally - [x] Run `t-rec`, press `n` at video prompt → terminal should work normally
1 parent 0e0e1b0 commit d5dd055

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/prompt.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use dialoguer::console::Term;
12
use dialoguer::Confirm;
23
use std::io::{self, Write};
34
use std::sync::mpsc::{self, Receiver, Sender};
@@ -70,6 +71,8 @@ fn run_prompt(question: &str, timeout_secs: u64) -> PromptResult {
7071
io::stdout().flush().unwrap();
7172

7273
if remaining == 0 {
74+
// Restore terminal state before returning
75+
restore_terminal();
7376
// Move down and print timeout message
7477
println!("\n\nSkipping video generation (timeout)");
7578
return PromptResult::Timeout;
@@ -101,6 +104,18 @@ fn run_prompt(question: &str, timeout_secs: u64) -> PromptResult {
101104
PromptResult::Timeout
102105
}
103106

107+
/// Restore terminal to normal state.
108+
///
109+
/// This ensures the cursor is visible and terminal modes are reset
110+
/// after dialoguer's prompt, especially important when timeout occurs
111+
/// and the prompt thread is abandoned.
112+
fn restore_terminal() {
113+
let term = Term::stdout();
114+
let _ = term.show_cursor();
115+
// Clear any remaining input state by flushing
116+
let _ = io::stdout().flush();
117+
}
118+
104119
/// Check if stdin is connected to an interactive terminal.
105120
///
106121
/// Returns false if input is piped or redirected.

0 commit comments

Comments
 (0)