mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 23:10:30 +00:00
Restore the terminal after an error in the list
This commit is contained in:
parent
b678bd8ed2
commit
3eaccbb61a
1 changed files with 18 additions and 12 deletions
30
src/list.rs
30
src/list.rs
|
@ -8,7 +8,7 @@ use ratatui::{
|
||||||
},
|
},
|
||||||
Terminal,
|
Terminal,
|
||||||
};
|
};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, StdoutLock, Write};
|
||||||
|
|
||||||
use crate::app_state::AppState;
|
use crate::app_state::AppState;
|
||||||
|
|
||||||
|
@ -16,15 +16,8 @@ use self::state::{Filter, UiState};
|
||||||
|
|
||||||
mod state;
|
mod state;
|
||||||
|
|
||||||
pub fn list(app_state: &mut AppState) -> Result<()> {
|
fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()> {
|
||||||
let mut stdout = io::stdout().lock();
|
let mut terminal = Terminal::new(CrosstermBackend::new(stdout))?;
|
||||||
stdout
|
|
||||||
.queue(EnterAlternateScreen)?
|
|
||||||
.queue(EnableMouseCapture)?
|
|
||||||
.flush()?;
|
|
||||||
enable_raw_mode()?;
|
|
||||||
|
|
||||||
let mut terminal = Terminal::new(CrosstermBackend::new(&mut stdout))?;
|
|
||||||
terminal.clear()?;
|
terminal.clear()?;
|
||||||
|
|
||||||
let mut ui_state = UiState::new(app_state);
|
let mut ui_state = UiState::new(app_state);
|
||||||
|
@ -88,12 +81,25 @@ pub fn list(app_state: &mut AppState) -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop(terminal);
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list(app_state: &mut AppState) -> Result<()> {
|
||||||
|
let mut stdout = io::stdout().lock();
|
||||||
|
stdout
|
||||||
|
.queue(EnterAlternateScreen)?
|
||||||
|
.queue(EnableMouseCapture)?
|
||||||
|
.flush()?;
|
||||||
|
enable_raw_mode()?;
|
||||||
|
|
||||||
|
let res = handle_list(app_state, &mut stdout);
|
||||||
|
|
||||||
|
// Restore the terminal even if we got an error.
|
||||||
stdout
|
stdout
|
||||||
.queue(LeaveAlternateScreen)?
|
.queue(LeaveAlternateScreen)?
|
||||||
.queue(DisableMouseCapture)?
|
.queue(DisableMouseCapture)?
|
||||||
.flush()?;
|
.flush()?;
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
|
|
||||||
Ok(())
|
res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue