diff options
| author | lukeflo | 2024-10-11 14:27:21 +0200 |
|---|---|---|
| committer | lukeflo | 2024-10-12 22:41:38 +0200 |
| commit | 2fa5f8193c2cf3b75f54a37f0f7c4b5ae9d7d665 (patch) | |
| tree | 483b113616c9a750f618c45ca332858d63758a9f /src/errorsetup.rs | |
| parent | 8e4bcaada27a50a83dba35deea8ad804d4bb226a (diff) | |
| parent | d9ed8fc8eaab1aa04aac031cc629d7018d513ab7 (diff) | |
| download | bibiman-2fa5f8193c2cf3b75f54a37f0f7c4b5ae9d7d665.tar.gz bibiman-2fa5f8193c2cf3b75f54a37f0f7c4b5ae9d7d665.zip | |
Merge branch 'scrollbar'
Diffstat (limited to 'src/errorsetup.rs')
| -rw-r--r-- | src/errorsetup.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/errorsetup.rs b/src/errorsetup.rs new file mode 100644 index 0000000..eaaba0f --- /dev/null +++ b/src/errorsetup.rs @@ -0,0 +1,51 @@ +// bibiman - a TUI for managing BibLaTeX databases +// Copyright (C) 2024 lukeflo +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. +///// + +use color_eyre::config::HookBuilder; +use color_eyre::eyre::Result; +use crossterm::cursor; +use crossterm::event::DisableMouseCapture; +use crossterm::terminal::LeaveAlternateScreen; +use std::io::stdout; + +// Define error hooks to restore the terminal after panic +pub fn init_error_hooks() -> Result<()> { + let (panic, error) = HookBuilder::default().into_hooks(); + let panic = panic.into_panic_hook(); + let error = error.into_eyre_hook(); + color_eyre::eyre::set_hook(Box::new(move |e| { + let _ = crossterm::execute!( + stdout(), + DisableMouseCapture, + LeaveAlternateScreen, + cursor::Show + ); + let _ = crossterm::terminal::disable_raw_mode(); + error(e) + }))?; + std::panic::set_hook(Box::new(move |info| { + let _ = crossterm::execute!( + stdout(), + DisableMouseCapture, + LeaveAlternateScreen, + cursor::Show + ); + let _ = crossterm::terminal::disable_raw_mode(); + panic(info) + })); + Ok(()) +} |
