Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 101 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@ name = "tdf"
name = "tdf"

[dependencies]
poppler-rs = { version = "0.24.1", default-features = false, features = ["v23_7"] }
poppler-rs = { version = "0.24.1", default-features = false, features = [
"v23_7",
] }
cairo-rs = { version = "0.20.0", default-features = false, features = ["png"] }
# we're using this branch because it has significant performance fixes that I'm waiting on responses from the upstream devs to get upstreamed. See https://github.com/ratatui-org/ratatui/issues/1116
ratatui = { git = "https://github.com/itsjunetime/ratatui.git" }
# ratatui = { git = "https://github.com/itsjunetime/ratatui.git" }
ratatui = { version = "0.29.0" }
# ratatui = { path = "./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 = ["rustix", "vb64"], default-features = false }
# ratatui-image = { path = "./ratatui-image", features = ["rustix", "vb64"], default-features = false }
# ratatui-image = { git = "https://github.com/itsjunetime/ratatui-image.git", branch = "vb64_on_personal", features = ["rustix", "vb64"], default-features = false }
ratatui-image = { version = "3.0", features = [
# "rustix",
# "vb64",
], default-features = false }
crossterm = { version = "0.28.1", features = ["event-stream"] }
image = { version = "0.25.1", features = ["png", "rayon"], default-features = false }
image = { version = "0.25.1", features = [
"png",
"rayon",
], default-features = false }
notify = { version = "7.0.0", features = ["crossbeam-channel"] }
tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] }
futures-util = { version = "0.3.30", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions benches/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ pub fn start_converting_loop(
let (to_converter_tx, from_main_rx) = unbounded();
let (to_main_tx, from_converter_rx) = unbounded();

let mut picker = Picker::new(FONT_SIZE);
picker.protocol_type = ProtocolType::Kitty;
let mut picker = Picker::from_fontsize(FONT_SIZE);
picker.set_protocol_type(ProtocolType::Kitty);

tokio::spawn(run_conversion_loop(
to_main_tx,
Expand Down
4 changes: 2 additions & 2 deletions src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ratatui_image::{picker::Picker, protocol::Protocol, Resize};
use crate::renderer::{fill_default, PageInfo, RenderError};

pub struct ConvertedPage {
pub page: Box<dyn Protocol>,
pub page: Protocol,
pub num: usize,
pub num_results: usize
}
Expand Down Expand Up @@ -67,7 +67,7 @@ pub async fn run_conversion_loop(
// size for the area given, so to save ratatui the work of having to
// resize it, we tell them to crop it to fit.
let txt_img = picker
.new_protocol(dyn_img, img_area, Resize::None)
.new_protocol(dyn_img, img_area, Resize::Fit(None))
.map_err(|e| {
RenderError::Render(format!(
"Couldn't convert DynamicImage to ratatui image: {e}"
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// We need to create `picker` on this thread because if we create it on the `renderer` thread,
// it messes up something with user input. Input never makes it to the crossterm thing
let mut picker = Picker::new((
let picker = Picker::from_fontsize((
window_size.width / window_size.columns,
window_size.height / window_size.rows
));
picker.guess_protocol();
// picker.protocol_type(); // TODO: Had to get rid of this

// then we want to spawn off the rendering task
// We need to use the thread::spawn API so that this exists in a thread not owned by tokio,
Expand All @@ -153,7 +153,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let backend = CrosstermBackend::new(std::io::stdout());
let mut term = Terminal::new(backend)?;
term.skip_diff(true);
// term.skip_diff(true); // TODO: Had to get rid of this

// poppler has some annoying logging (e.g. if you request a page index out-of-bounds of a
// document's pages, then it will return `None`, but still log to stderr with CRITICAL level),
Expand Down
30 changes: 15 additions & 15 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct PageConstraints {
#[derive(Default)]
struct RenderedInfo {
// The image, if it has been rendered by `Converter` to that struct
img: Option<Box<dyn Protocol>>,
img: Option<Protocol>,
// The number of results for the current search term that have been found on this page. None if
// we haven't checked this page yet
// Also this isn't the most efficient representation of this value, but it's accurate, so like
Expand Down Expand Up @@ -217,7 +217,7 @@ impl Tui {
take
})
// and map it to their width (in cells on the terminal, not pixels)
.filter_map(|(idx, page)| page.img.as_ref().map(|img| (idx, img.rect().width)))
.filter_map(|(idx, page)| page.img.as_ref().map(|img| (idx, img_area.width)))
// and then take them as long as they won't overflow the available area.
.take_while(|(_, width)| match test_area_w.checked_sub(*width) {
Some(new_val) => {
Expand Down Expand Up @@ -269,7 +269,7 @@ impl Tui {

fn render_single_page(&mut self, frame: &mut Frame<'_>, page_idx: usize, img_area: Rect) {
match self.rendered[page_idx].img {
Some(ref page_img) => frame.render_widget(Image::new(&**page_img), img_area),
Some(ref page_img) => frame.render_widget(Image::new(page_img), img_area),
None => Self::render_loading_in(frame, img_area)
};
}
Expand Down Expand Up @@ -321,22 +321,22 @@ impl Tui {
self.page = self.page.min(n_pages - 1);
}

pub fn page_ready(&mut self, img: Box<dyn Protocol>, page_num: usize, num_results: usize) {
pub fn page_ready(&mut self, img: Protocol, page_num: usize, num_results: usize) {
// If this new image woulda fit within the available space on the last render AND it's
// within the range where it might've been rendered with the last shown pages, then reset
// the last rect marker so that all images are forced to redraw on next render and this one
// is drawn with them
if page_num >= self.page && page_num <= self.page + self.last_render.pages_shown {
self.last_render.rect = Rect::default();
} else {
let img_w = img.rect().width;
if img_w <= self.last_render.unused_width {
let num_fit = self.last_render.unused_width / img_w;
if page_num >= self.page && (self.page + num_fit as usize) >= page_num {
self.last_render.rect = Rect::default();
}
}
}
// if page_num >= self.page && page_num <= self.page + self.last_render.pages_shown {
// self.last_render.rect = Rect::default();
// } else {
// let img_w = img.
// if img_w <= self.last_render.unused_width {
// let num_fit = self.last_render.unused_width / img_w;
// if page_num >= self.page && (self.page + num_fit as usize) >= page_num {
// self.last_render.rect = Rect::default();
// }
// }
// }

// We always just set this here because we handle reloading in the `set_n_pages` function.
// If the document was reloaded, then It'll have the `set_n_pages` called to set the new
Expand Down