aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJoris2022-11-21 14:47:36 +0100
committerJoris2022-11-21 14:47:36 +0100
commitae8aafed5bad8edd594556bce079b1545aea9bec (patch)
tree88cff38eff55c9da1fc44d99dae2e72bd5a8d2eb /src/main.rs
parent3fbdc20859a7f795ab9396ead363ab7a9581405d (diff)
downloadflashcards-ae8aafed5bad8edd594556bce079b1545aea9bec.tar.gz
flashcards-ae8aafed5bad8edd594556bce079b1545aea9bec.tar.bz2
flashcards-ae8aafed5bad8edd594556bce079b1545aea9bec.zip
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.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs22
1 files changed, 20 insertions, 2 deletions
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 {