From ae8aafed5bad8edd594556bce079b1545aea9bec Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 21 Nov 2022 14:47:36 +0100 Subject: Show errors in TUI instead of nothing Once the terminal was setup, errors were not shown in case the application stopped because of an error. So, show errors explicitely in TUI to be able to debug easily the deck for example. --- src/main.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index bed2ce1..c2373f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ mod util; use crate::util::event::Events; use anyhow::Result; +use rusqlite::Connection; use std::path::PathBuf; use structopt::StructOpt; @@ -23,8 +24,25 @@ fn main() -> Result<()> { let deck_name = deck::pp_from_path(&deck_path).unwrap_or_else(|| "Deck".to_string()); let mut term = gui::terminal()?; let events = Events::new(); - gui::synchronize(&conn, &mut term, &events, &deck_path, &deck_name)?; - gui::start(&conn, &mut term, &events, &deck_name) + match run_tui(conn, &deck_path, &deck_name, &mut term, &events) { + Ok(()) => Ok(()), + Err(msg) => { + // Show errors in TUI, otherwise they are hidden + gui::message::show(&mut term, &events, &deck_name, &format!("{}", msg), true)?; + Err(msg) + } + } +} + +fn run_tui( + conn: Connection, + deck_path: &str, + deck_name: &str, + term: &mut gui::Term, + events: &Events, +) -> Result<()> { + gui::synchronize(&conn, term, &events, &deck_path, &deck_name)?; + gui::start(&conn, term, &events, &deck_name) } fn db_path(deck_path: &str) -> String { -- cgit v1.2.3