From 1ad9a97e9a25622a9946cb9c55705922c42d9149 Mon Sep 17 00:00:00 2001 From: lukeflo-work Date: Thu, 10 Oct 2024 15:12:31 +0200 Subject: scrollbar for keyword and entry area --- src/errorsetup.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/errorsetup.rs (limited to 'src/errorsetup.rs') 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 . +///// + +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(()) +} -- cgit v1.2.3