mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-24 23:46:41 +02:00
Add panic hook that shows stacktrace
This commit is contained in:
parent
cf918a53ff
commit
79f1b9c1e6
4 changed files with 83 additions and 6 deletions
68
Cargo.lock
generated
68
Cargo.lock
generated
|
@ -61,6 +61,16 @@ dependencies = [
|
|||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "better-panic"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d12a680cc74d8c4a44ee08be4a00dedf671b089c2440b2e3fdaa776cd468476"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"console",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
|
@ -119,6 +129,18 @@ dependencies = [
|
|||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clicolors-control"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cloudabi"
|
||||
version = "0.0.3"
|
||||
|
@ -128,6 +150,21 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45e0f3986890b3acbc782009e2629dfe2baa430ac091519ce3be26164a2ae6c0"
|
||||
dependencies = [
|
||||
"clicolors-control",
|
||||
"encode_unicode",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"regex",
|
||||
"termios",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossterm"
|
||||
version = "0.17.7"
|
||||
|
@ -240,6 +277,12 @@ version = "1.6.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
|
||||
[[package]]
|
||||
name = "encode_unicode"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
|
||||
|
||||
[[package]]
|
||||
name = "failure"
|
||||
version = "0.1.8"
|
||||
|
@ -535,6 +578,21 @@ dependencies = [
|
|||
"redox_syscall",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
|
||||
dependencies = [
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.18"
|
||||
|
@ -702,6 +760,7 @@ dependencies = [
|
|||
name = "taskwarrior-tui"
|
||||
version = "0.9.9"
|
||||
dependencies = [
|
||||
"better-panic",
|
||||
"cassowary",
|
||||
"chrono",
|
||||
"clap",
|
||||
|
@ -719,6 +778,15 @@ dependencies = [
|
|||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termios"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "411c5bf740737c7918b8b1fe232dca4dc9f8e754b8ad5e20966814001ed0ac6b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
|
|
|
@ -33,6 +33,7 @@ tui = { version = "0.12", optional = true, default-features = false }
|
|||
crossterm = { version = "0.17", optional = true, default-features = false }
|
||||
rustyline = "6.3.0"
|
||||
uuid = { version = "0.8.1", features = ["serde", "v4"] }
|
||||
better-panic = "0.2.0"
|
||||
|
||||
[package.metadata.rpm]
|
||||
package = "taskwarrior-tui"
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -17,6 +17,7 @@ use std::env;
|
|||
use std::error::Error;
|
||||
use std::io::Write;
|
||||
use std::time::Duration;
|
||||
use std::panic;
|
||||
|
||||
use crate::util::Key;
|
||||
use app::{AppMode, TTApp};
|
||||
|
@ -25,6 +26,7 @@ const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
|||
const APP_NAME: &str = env!("CARGO_PKG_NAME");
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
better_panic::install();
|
||||
let matches = App::new(APP_NAME)
|
||||
.version(APP_VERSION)
|
||||
.author("Dheepak Krishnamurthy <@kdheepak>")
|
||||
|
@ -65,6 +67,11 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
|||
let mut terminal = setup_terminal();
|
||||
terminal.clear()?;
|
||||
|
||||
panic::set_hook(Box::new(|panic_info| {
|
||||
destruct_terminal();
|
||||
better_panic::Settings::auto().create_panic_handler()(panic_info);
|
||||
}));
|
||||
|
||||
// Setup event handlers
|
||||
let events = Events::with_config(EventConfig {
|
||||
tick_rate: Duration::from_millis(1000),
|
||||
|
@ -84,21 +91,21 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
|||
Event::Input(input) => {
|
||||
let r = app.handle_input(input, &mut terminal, &events);
|
||||
if r.is_err() {
|
||||
destruct_terminal(terminal);
|
||||
destruct_terminal();
|
||||
return r;
|
||||
}
|
||||
}
|
||||
Event::Tick => {
|
||||
let r = app.update();
|
||||
if r.is_err() {
|
||||
destruct_terminal(terminal);
|
||||
destruct_terminal();
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if app.should_quit {
|
||||
destruct_terminal(terminal);
|
||||
destruct_terminal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +113,7 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
|||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
destruct_terminal(terminal);
|
||||
destruct_terminal();
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ use crossterm::{
|
|||
event::{self, DisableMouseCapture, EnableMouseCapture},
|
||||
execute,
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
cursor,
|
||||
};
|
||||
use tui::{backend::CrosstermBackend, Terminal};
|
||||
|
||||
|
@ -50,10 +51,10 @@ pub fn setup_terminal() -> Terminal<CrosstermBackend<io::Stdout>> {
|
|||
Terminal::new(backend).unwrap()
|
||||
}
|
||||
|
||||
pub fn destruct_terminal(mut terminal: Terminal<CrosstermBackend<io::Stdout>>) {
|
||||
pub fn destruct_terminal() {
|
||||
disable_raw_mode().unwrap();
|
||||
execute!(io::stdout(), LeaveAlternateScreen, DisableMouseCapture).unwrap();
|
||||
terminal.show_cursor().unwrap();
|
||||
execute!(io::stdout(), cursor::Show).unwrap();
|
||||
}
|
||||
|
||||
pub struct Events {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue