Make tdf run on stable with --no-default-features

This commit is contained in:
itsjunetime
2024-11-15 14:14:54 -07:00
parent 927a9cb587
commit 40d46f1e2d
5 changed files with 76 additions and 73 deletions
+2
View File
@@ -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
+3 -2
View File
@@ -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<dyn ratatui_image::Protocol>. 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]
-2
View File
@@ -1,5 +1,3 @@
#![feature(if_let_guard)]
pub mod converter;
pub mod renderer;
pub mod skip;
-2
View File
@@ -1,5 +1,3 @@
#![feature(if_let_guard)]
use std::{
io::{stdout, Read, Write},
num::NonZeroUsize,
+71 -67
View File
@@ -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;