Skip to content

Commit 523783d

Browse files
committed
fix: restore screen state on setup failure
1 parent 3dcdb77 commit 523783d

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

src/screen_runner.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub const SCREEN_RANDOM_STYLES: &[&str] = &[
3535
"game_of_life_bloom",
3636
];
3737

38-
#[derive(Clone, Copy)]
3938
enum ScreenStyle {
4039
Static,
4140
Logo,
@@ -50,7 +49,6 @@ enum AnimationStyle {
5049
Mandelbrot,
5150
}
5251

53-
#[derive(Debug, Clone, PartialEq, Eq)]
5452
struct ScreenArgs {
5553
style: String,
5654
cell_style: GameOfLifeCellStyle,
@@ -649,12 +647,6 @@ mod tests {
649647
assert!(!frame.contains("just"));
650648
}
651649

652-
// Regression: the deleted image-backed magician style must not return through random selection.
653-
#[test]
654-
fn random_style_skips_magician() {
655-
assert!(!SCREEN_RANDOM_STYLES.contains(&"magician"));
656-
}
657-
658650
// Defends: Game of Life keeps the same minimum-width sizing contract as the integrated screen renderer.
659651
#[test]
660652
fn game_of_life_context_preserves_inner_width_floor() {

src/terminal_control.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crossterm::{
77
LeaveAlternateScreen,
88
},
99
};
10-
use std::io::{self, Write};
10+
use std::io;
1111

1212
fn command_string(write_commands: impl FnOnce(&mut Vec<u8>) -> io::Result<()>) -> String {
1313
crossterm::style::force_color_output(true);
@@ -78,13 +78,14 @@ pub(crate) fn enter_screen_mode() -> io::Result<()> {
7878
DisableLineWrap,
7979
Clear(ClearType::All),
8080
MoveTo(0, 0)
81-
)?;
82-
stdout.flush()
81+
)
82+
.inspect_err(|_| {
83+
let _ = leave_screen_mode();
84+
})
8385
}
8486

8587
pub(crate) fn leave_screen_mode() -> io::Result<()> {
8688
crossterm::style::force_color_output(true);
8789
let mut stdout = io::stdout();
88-
execute!(stdout, EnableLineWrap, Show, LeaveAlternateScreen)?;
89-
stdout.flush()
90+
execute!(stdout, EnableLineWrap, Show, LeaveAlternateScreen)
9091
}

0 commit comments

Comments
 (0)