From 16c0aed9a3bebdd04e008a2a34c6d0e3ead9350c Mon Sep 17 00:00:00 2001 From: itsjunetime Date: Fri, 9 Jan 2026 20:06:10 -0500 Subject: [PATCH 1/2] - don't parse color strings for defaults - fix comment misstating type of vec - impl size_hint and ExactSizeIterator for PopOnNext --- src/main.rs | 44 ++++++++++++++++++++++++++++---------------- src/renderer.rs | 21 ++++++++++++++++----- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index b125cd9..9317a18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ use tdf::{ PrerenderLimit, converter::{ConvertedPage, ConverterMsg, run_conversion_loop}, kitty::{KittyDisplay, display_kitty_images, do_shms_work, run_action}, - renderer::{self, RenderError, RenderInfo, RenderNotif}, + renderer::{self, MUPDF_BLACK, MUPDF_WHITE, RenderError, RenderInfo, RenderNotif}, tui::{BottomMessage, InputAction, MessageSetting, Tui} }; @@ -128,21 +128,33 @@ async fn inner_main() -> Result<(), WrappedErr> { .canonicalize() .map_err(|e| WrappedErr(format!("Cannot canonicalize provided file: {e}").into()))?; - let black = - parse_color_to_i32(flags.black_color.as_deref().unwrap_or("000000")).map_err(|e| { - WrappedErr( - format!("Couldn't parse black color: {e} - is it formatted like a CSS color?") - .into() - ) - })?; - - let white = - parse_color_to_i32(flags.white_color.as_deref().unwrap_or("FFFFFF")).map_err(|e| { - WrappedErr( - format!("Couldn't parse white color: {e} - is it formatted like a CSS color?") - .into() - ) - })?; + let black = flags + .black_color + .as_deref() + .map(|color| parse_color_to_i32(color) + .map_err(|e| { + WrappedErr( + format!("Couldn't parse black color {color:?}: {e} - is it formatted like a CSS color?") + .into() + ) + }) + ) + .transpose()? + .unwrap_or(MUPDF_BLACK); + + let white = flags + .white_color + .as_deref() + .map(|color| parse_color_to_i32(color) + .map_err(|e| { + WrappedErr( + format!("Couldn't parse white color {color:?}: {e} - is it formatted like a CSS color?") + .into() + ) + }) + ) + .transpose()? + .unwrap_or(MUPDF_WHITE); // need to keep it around throughout the lifetime of the program, but don't rly need to use it. // Just need to make sure it doesn't get dropped yet. diff --git a/src/renderer.rs b/src/renderer.rs index 879132d..0a32b7a 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -57,8 +57,8 @@ struct PrevRender { num_search_found: Option } -const MUPDF_BLACK: i32 = 0; -const MUPDF_WHITE: i32 = i32::from_be_bytes([0, 0xff, 0xff, 0xff]); +pub const MUPDF_BLACK: i32 = 0; +pub const MUPDF_WHITE: i32 = i32::from_be_bytes([0, 0xff, 0xff, 0xff]); #[inline] pub fn fill_default(vec: &mut Vec, size: usize) { @@ -152,8 +152,8 @@ pub fn start_rendering( sender.send(Ok(RenderInfo::NumPages(n_pages.get())))?; - // We're using this vec of bools to indicate which page numbers have already been rendered, - // to support people jumping to specific pages and having quick rendering results. We + // We're using this vec to indicate which page numbers have already been rendered, to + // support people jumping to specific pages and having quick rendering results. We // `split_at_mut` at 0 initially (which bascially makes `right == rendered && left == []`), // doing basically nothing, but if we get a notification that something has been jumped to, // then we can split at that page and render at both sides of it @@ -277,7 +277,7 @@ pub fn start_rendering( // we only want to continue if one of the following is met: // 1. It failed to render last time (we want to retry) // 2. The `contained_term` is set to Unknown, meaning that we need to at least - // check if it contains the current term to see if it needs a re-render + // check if it contains the current term to see if it needs a re-render if rendered.successful && rendered.num_search_found.is_some() { continue; } @@ -570,4 +570,15 @@ impl Iterator for PopOnNext<'_> { fn next(&mut self) -> Option { self.inner.pop_front() } + + fn size_hint(&self) -> (usize, Option) { + let l = self.len(); + (l, Some(l)) + } +} + +impl ExactSizeIterator for PopOnNext<'_> { + fn len(&self) -> usize { + self.inner.len() + } } From e2a9c90b348180a3670dea255e5b15f4534236c1 Mon Sep 17 00:00:00 2001 From: itsjunetime Date: Fri, 9 Jan 2026 20:15:57 -0500 Subject: [PATCH 2/2] thought i formatted this --- src/main.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9317a18..8804610 100644 --- a/src/main.rs +++ b/src/main.rs @@ -131,28 +131,32 @@ async fn inner_main() -> Result<(), WrappedErr> { let black = flags .black_color .as_deref() - .map(|color| parse_color_to_i32(color) - .map_err(|e| { + .map(|color| { + parse_color_to_i32(color).map_err(|e| { WrappedErr( - format!("Couldn't parse black color {color:?}: {e} - is it formatted like a CSS color?") - .into() + format!( + "Couldn't parse black color {color:?}: {e} - is it formatted like a CSS color?" + ) + .into() ) }) - ) + }) .transpose()? .unwrap_or(MUPDF_BLACK); let white = flags .white_color .as_deref() - .map(|color| parse_color_to_i32(color) - .map_err(|e| { + .map(|color| { + parse_color_to_i32(color).map_err(|e| { WrappedErr( - format!("Couldn't parse white color {color:?}: {e} - is it formatted like a CSS color?") - .into() + format!( + "Couldn't parse white color {color:?}: {e} - is it formatted like a CSS color?" + ) + .into() ) }) - ) + }) .transpose()? .unwrap_or(MUPDF_WHITE);