aboutsummaryrefslogtreecommitdiff
path: root/src/frontend
diff options
context:
space:
mode:
authorlukeflo2024-10-14 22:04:26 +0200
committerlukeflo2024-10-14 22:04:26 +0200
commitc555c8666268efdff4d7107d5a527b899679559e (patch)
treecf63b48c6034e8952a35197716338bfe73f84ee8 /src/frontend
parent5114820b9733bfb4daeedaef4f892ba9f5f023a0 (diff)
downloadbibiman-c555c8666268efdff4d7107d5a527b899679559e.tar.gz
bibiman-c555c8666268efdff4d7107d5a527b899679559e.zip
check file format, use new keys() method of biblatex crate
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/tui.rs71
1 files changed, 7 insertions, 64 deletions
diff --git a/src/frontend/tui.rs b/src/frontend/tui.rs
index 698407d..e3c9c1a 100644
--- a/src/frontend/tui.rs
+++ b/src/frontend/tui.rs
@@ -24,6 +24,8 @@ use crossterm::{
terminal::{EnterAlternateScreen, LeaveAlternateScreen},
};
// use ratatui::backend::{Backend, CrosstermBackend};
+use color_eyre::eyre::{OptionExt, Result};
+use futures::{FutureExt, StreamExt};
use ratatui::backend::CrosstermBackend as Backend;
use std::io::{stdout, Stdout};
use std::panic;
@@ -31,10 +33,6 @@ use std::{
ops::{Deref, DerefMut},
time::Duration,
};
-
-use color_eyre::config::HookBuilder;
-use color_eyre::eyre::{OptionExt, Result};
-use futures::{FutureExt, StreamExt};
use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken;
@@ -51,14 +49,6 @@ pub enum Event {
Resize(u16, u16),
}
-// pub type IO = std::io::{{crossterm_io | title_case}};
-// pub fn io() -> IO {
-// std::io::{{crossterm_io}}()
-// }
-/// Representation of a terminal user interface.
-///
-/// It is responsible for setting up the terminal,
-/// initializing the interface and handling the draw events.
#[derive(Debug)]
pub struct Tui {
/// Interface to the Terminal.
@@ -73,7 +63,7 @@ pub struct Tui {
}
impl Tui {
- /// Constructs a new instance of [`Tui`].
+ // Constructs a new instance of [`Tui`].
pub fn new() -> Result<Self> {
let terminal = ratatui::Terminal::new(Backend::new(stdout()))?;
let (sender, receiver) = mpsc::unbounded_channel();
@@ -150,26 +140,6 @@ impl Tui {
cancellation_token.cancel();
}
- /// Initializes the terminal interface.
- ///
- /// It enables the raw mode and sets terminal properties.
- // pub fn init(&mut self) -> Result<()> {
- // terminal::enable_raw_mode()?;
- // crossterm::execute!(io::stdout(), EnterAlternateScreen, EnableMouseCapture)?;
-
- // // Define a custom panic hook to reset the terminal properties.
- // // This way, you won't have your terminal messed up if an unexpected error happens.
- // let panic_hook = panic::take_hook();
- // panic::set_hook(Box::new(move |panic| {
- // Self::reset().expect("failed to reset the terminal");
- // panic_hook(panic);
- // }));
-
- // self.terminal.hide_cursor()?;
- // self.terminal.clear()?;
- // Ok(())
- // }
-
pub fn enter(&mut self) -> Result<()> {
crossterm::terminal::enable_raw_mode()?;
crossterm::execute!(stdout(), EnterAlternateScreen, cursor::Hide)?;
@@ -216,10 +186,10 @@ impl Tui {
Ok(())
}
- /// [`Draw`] the terminal interface by [`rendering`] the widgets.
- ///
- /// [`Draw`]: ratatui::Terminal::draw
- /// [`rendering`]: crate::ui::render
+ // [`Draw`] the terminal interface by [`rendering`] the widgets.
+ //
+ // [`Draw`]: ratatui::Terminal::draw
+ // [`rendering`]: crate::ui::render
pub fn draw(&mut self, app: &mut App) -> Result<()> {
// self.terminal.draw(|frame| ui::render(app, frame))?;
self.terminal
@@ -230,33 +200,6 @@ impl Tui {
pub async fn next(&mut self) -> Result<Event> {
self.receiver.recv().await.ok_or_eyre("This is an IO error")
}
-
- 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(())
- }
}
impl Deref for Tui {