Skip to content

Commit c56ceef

Browse files
unhappychoiceclaude
andcommitted
fix: resolve forced termination after loading completion
- Add proper cleanup tracking to prevent duplicate terminal cleanup - Remove duplicate Ctrl+C handler in StageManager to avoid MultipleHandlers error - Improve error handling with helpful WSL/SSH environment hints - Ensure loading screen completes before game startup attempt 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5353ca3 commit c56ceef

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/game/stage_manager.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ impl StageManager {
4444
}
4545

4646
pub fn run_session(&mut self) -> Result<()> {
47-
// Set up signal handler for Ctrl+C
48-
ctrlc::set_handler(move || {
49-
terminal::disable_raw_mode().ok();
50-
std::process::exit(0);
51-
}).expect("Error setting Ctrl-C handler");
52-
5347
// Enable raw mode for entire application session
5448
match terminal::enable_raw_mode() {
5549
Ok(_) => {},

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ enum Commands {
6868
fn main() -> anyhow::Result<()> {
6969
// Set up Ctrl+C handler
7070
ctrlc::set_handler(move || {
71+
// Clean up terminal state if needed
72+
let _ = crossterm::terminal::disable_raw_mode();
7173
println!("\n\nInterrupted by user");
7274
std::process::exit(0);
7375
}).expect("Error setting Ctrl-C handler");
@@ -158,6 +160,10 @@ fn main() -> anyhow::Result<()> {
158160
},
159161
Err(e) => {
160162
eprintln!("Error during game session: {}", e);
163+
if e.to_string().contains("No such device or address") {
164+
eprintln!("\nHint: This error often occurs in WSL or SSH environments where terminal features are limited.");
165+
eprintln!("Try running GitType in a native terminal or GUI terminal emulator.");
166+
}
161167
}
162168
}
163169
} else {

src/ui/centered_loading.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct CenteredLoadingDisplay {
2727
files_processed: Mutex<usize>,
2828
total_files: Mutex<usize>,
2929
last_render: Mutex<Instant>,
30+
cleaned_up: Mutex<bool>,
3031
}
3132

3233
impl CenteredLoadingDisplay {
@@ -48,6 +49,7 @@ impl CenteredLoadingDisplay {
4849
files_processed: Mutex::new(0),
4950
total_files: Mutex::new(0),
5051
last_render: Mutex::new(Instant::now()),
52+
cleaned_up: Mutex::new(false),
5153
})
5254
}
5355

@@ -120,6 +122,9 @@ impl CenteredLoadingDisplay {
120122
// Wait a moment to show the completion
121123
std::thread::sleep(std::time::Duration::from_millis(800));
122124

125+
// Clean up terminal state before returning
126+
self.cleanup()?;
127+
123128
Ok(())
124129
}
125130

@@ -293,9 +298,15 @@ impl CenteredLoadingDisplay {
293298
}
294299

295300
pub fn cleanup(&self) -> Result<()> {
301+
let mut cleaned_up = self.cleaned_up.lock().unwrap();
302+
if *cleaned_up {
303+
return Ok(());
304+
}
305+
296306
disable_raw_mode()?;
297307
let mut stdout = stdout();
298308
stdout.execute(LeaveAlternateScreen)?;
309+
*cleaned_up = true;
299310
Ok(())
300311
}
301312
}

0 commit comments

Comments
 (0)