From 40d46f1e2df19c2b93ab5b4c17ba4ee3d6d30670 Mon Sep 17 00:00:00 2001 From: itsjunetime Date: Fri, 15 Nov 2024 14:14:54 -0700 Subject: [PATCH] Make tdf run on stable with --no-default-features --- CHANGELOG.md | 2 + Cargo.toml | 5 +- src/lib.rs | 2 - src/main.rs | 2 - src/tui.rs | 138 ++++++++++++++++++++++++++------------------------- 5 files changed, 76 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc4ad12..5a3c8a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ - Add `--r-to-l` flag to support displaying pdfs that read from right to left - Add `--max-wide` flag to restrict amount of pages that can appear on the screen at a time - Small internal changes to accomodate a few more clippy lints +- Update `ratatui` and `ratatui-image` git dependencies to latest upstream +- Move `ratatui-image/vb64` support under `nightly` feature, enabled by default # v0.1.0 diff --git a/Cargo.toml b/Cargo.toml index 216f955..24e6628 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ cairo-rs = { version = "0.20.0", default-features = false, features = ["png"] } ratatui = { git = "https://github.com/itsjunetime/ratatui.git" } # ratatui = { path = "./ratatui/ratatui" } # We're using this to have the vb64 feature (for faster base64 encoding, since that does take up a good bit of time when converting images to the Box. It also just includes a few more features that I'm waiting on main to upstream -ratatui-image = { git = "https://github.com/itsjunetime/ratatui-image.git", branch = "vb64_on_personal", features = ["vb64"], default-features = false } +ratatui-image = { git = "https://github.com/itsjunetime/ratatui-image.git", branch = "vb64_on_personal", default-features = false } # ratatui-image = { path = "./ratatui-image", features = ["vb64"], default-features = false } crossterm = { version = "0.28.1", features = ["event-stream"] } image = { version = "0.25.1", features = ["png", "rayon"], default-features = false } @@ -46,7 +46,8 @@ inherits = "release" lto = "fat" [features] -default = [] +default = ["nightly"] +nightly = ["ratatui-image/vb64"] tracing = ["tokio/tracing", "dep:console-subscriber"] [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index a9f3c82..18baad9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(if_let_guard)] - pub mod converter; pub mod renderer; pub mod skip; diff --git a/src/main.rs b/src/main.rs index 59f6234..b5ccc11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -#![feature(if_let_guard)] - use std::{ io::{stdout, Read, Write}, num::NonZeroUsize, diff --git a/src/tui.rs b/src/tui.rs index f2c4016..e742ec4 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -368,35 +368,77 @@ impl Tui { match ev { Event::Key(key) => { match key.code { - KeyCode::Char(c) - if let BottomMessage::Input(InputCommand::Search(ref mut term)) = - self.bottom_msg => - { - term.push(c); - Some(InputAction::Redraw) - } - KeyCode::Backspace - if let BottomMessage::Input(InputCommand::Search(ref mut term)) = - self.bottom_msg => - { - term.pop(); - Some(InputAction::Redraw) - } - KeyCode::Char(c) - if let BottomMessage::Input(InputCommand::GoToPage(ref mut page)) = - self.bottom_msg => - c.to_digit(10).map(|input_num| { - *page = (*page * 10) + input_num as usize; - InputAction::Redraw - }), - KeyCode::Right | KeyCode::Char('l') => - self.change_page(PageChange::Next, ChangeAmount::Single), - KeyCode::Down | KeyCode::Char('j') => - self.change_page(PageChange::Next, ChangeAmount::WholeScreen), - KeyCode::Left | KeyCode::Char('h') => - self.change_page(PageChange::Prev, ChangeAmount::Single), - KeyCode::Up | KeyCode::Char('k') => - self.change_page(PageChange::Prev, ChangeAmount::WholeScreen), + KeyCode::Char(c) => { + // TODO: refactor back to `if let` arm guards when those are stabilized + if let BottomMessage::Input(InputCommand::Search(ref mut term)) = self.bottom_msg { + term.push(c); + return Some(InputAction::Redraw); + } + + if let BottomMessage::Input(InputCommand::GoToPage(ref mut page)) = self.bottom_msg { + return c.to_digit(10).map(|input_num| { + *page = (*page * 10) + input_num as usize; + InputAction::Redraw + }); + } + + match c { + 'l' => self.change_page(PageChange::Next, ChangeAmount::Single), + 'j' => self.change_page(PageChange::Next, ChangeAmount::WholeScreen), + 'h' => self.change_page(PageChange::Prev, ChangeAmount::Single), + 'k' => self.change_page(PageChange::Prev, ChangeAmount::WholeScreen), + 'q' => Some(InputAction::QuitApp), + 'g' => { + self.set_bottom_msg(Some(BottomMessage::Input(InputCommand::GoToPage(0)))); + Some(InputAction::Redraw) + } + '/' => { + self.set_bottom_msg(Some(BottomMessage::Input(InputCommand::Search( + String::new() + )))); + Some(InputAction::Redraw) + } + 'n' if self.page < self.rendered.len() - 1 => { + // TODO: If we can't find one, then maybe like block until we've verified + // all the pages have been checked? + let next_page = self.rendered[(self.page + 1)..] + .iter() + .enumerate() + .find_map(|(idx, p)| { + p.num_results + .is_some_and(|num| num > 0) + .then_some(self.page + 1 + idx) + }); + + jump_to_page(&mut self.page, &mut self.last_render.rect, next_page) + } + 'N' if self.page > 0 => { + let prev_page = self.rendered[..(self.page)] + .iter() + .rev() + .enumerate() + .find_map(|(idx, p)| { + p.num_results + .is_some_and(|num| num > 0) + .then_some(self.page - (idx + 1)) + }); + + jump_to_page(&mut self.page, &mut self.last_render.rect, prev_page) + }, + _ => None + } + }, + KeyCode::Backspace => { + if let BottomMessage::Input(InputCommand::Search(ref mut term)) = self.bottom_msg { + term.pop(); + return Some(InputAction::Redraw); + } + None + }, + KeyCode::Right => self.change_page(PageChange::Next, ChangeAmount::Single), + KeyCode::Down => self.change_page(PageChange::Next, ChangeAmount::WholeScreen), + KeyCode::Left => self.change_page(PageChange::Prev, ChangeAmount::Single), + KeyCode::Up => self.change_page(PageChange::Prev, ChangeAmount::WholeScreen), KeyCode::Esc => match self.bottom_msg { BottomMessage::Input(_) => { self.set_bottom_msg(None); @@ -404,44 +446,6 @@ impl Tui { } _ => Some(InputAction::QuitApp) }, - KeyCode::Char('q') => Some(InputAction::QuitApp), - KeyCode::Char('g') => { - self.set_bottom_msg(Some(BottomMessage::Input(InputCommand::GoToPage(0)))); - Some(InputAction::Redraw) - } - KeyCode::Char('/') => { - self.set_bottom_msg(Some(BottomMessage::Input(InputCommand::Search( - String::new() - )))); - Some(InputAction::Redraw) - } - KeyCode::Char('n') if self.page < self.rendered.len() - 1 => { - // TODO: If we can't find one, then maybe like block until we've verified - // all the pages have been checked? - let next_page = self.rendered[(self.page + 1)..] - .iter() - .enumerate() - .find_map(|(idx, p)| { - p.num_results - .is_some_and(|num| num > 0) - .then_some(self.page + 1 + idx) - }); - - jump_to_page(&mut self.page, &mut self.last_render.rect, next_page) - } - KeyCode::Char('N') if self.page > 0 => { - let prev_page = self.rendered[..(self.page)] - .iter() - .rev() - .enumerate() - .find_map(|(idx, p)| { - p.num_results - .is_some_and(|num| num > 0) - .then_some(self.page - (idx + 1)) - }); - - jump_to_page(&mut self.page, &mut self.last_render.rect, prev_page) - } KeyCode::Enter => { let BottomMessage::Input(_) = self.bottom_msg else { return None;