aboutsummaryrefslogtreecommitdiff
path: root/src/errorsetup.rs
diff options
context:
space:
mode:
authorlukeflo-work2024-10-10 15:12:31 +0200
committerlukeflo2024-10-12 22:41:38 +0200
commit1ad9a97e9a25622a9946cb9c55705922c42d9149 (patch)
tree363a30504d6a44f09aeb1023d7aefc280b3f0365 /src/errorsetup.rs
parentd52b16993285f6fd98d7241689e1bd950739bb88 (diff)
downloadbibiman-1ad9a97e9a25622a9946cb9c55705922c42d9149.tar.gz
bibiman-1ad9a97e9a25622a9946cb9c55705922c42d9149.zip
scrollbar for keyword and entry area
Diffstat (limited to 'src/errorsetup.rs')
-rw-r--r--src/errorsetup.rs51
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(())
+}