Add error message when unable to get terminal size

This commit is contained in:
mo8it 2024-09-05 17:37:34 +02:00
parent dcad002057
commit bcc2a136c8
2 changed files with 3 additions and 3 deletions

View file

@ -20,7 +20,7 @@ mod scroll_state;
mod state; mod state;
fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()> { fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()> {
let mut list_state = ListState::new(app_state, stdout)?; let mut list_state = ListState::build(app_state, stdout)?;
let mut is_searching = false; let mut is_searching = false;
loop { loop {

View file

@ -48,7 +48,7 @@ pub struct ListState<'a> {
} }
impl<'a> ListState<'a> { impl<'a> ListState<'a> {
pub fn new(app_state: &'a mut AppState, stdout: &mut StdoutLock) -> io::Result<Self> { pub fn build(app_state: &'a mut AppState, stdout: &mut StdoutLock) -> Result<Self> {
stdout.queue(Clear(ClearType::All))?; stdout.queue(Clear(ClearType::All))?;
let name_col_title_len = 4; let name_col_title_len = 4;
@ -64,7 +64,7 @@ impl<'a> ListState<'a> {
let n_rows_with_filter = app_state.exercises().len(); let n_rows_with_filter = app_state.exercises().len();
let selected = app_state.current_exercise_ind(); let selected = app_state.current_exercise_ind();
let (width, height) = terminal::size()?; let (width, height) = terminal::size().context("Failed to get the terminal size")?;
let scroll_state = ScrollState::new(n_rows_with_filter, Some(selected), 5); let scroll_state = ScrollState::new(n_rows_with_filter, Some(selected), 5);
let mut slf = Self { let mut slf = Self {