small cleanups (#129)

- don't parse color strings for defaults
- fix comment misstating type of vec
- impl size_hint and ExactSizeIterator for PopOnNext
This commit is contained in:
June
2026-01-09 20:53:25 -05:00
committed by GitHub
parent 19030f7fd4
commit 39a4bdafb6
2 changed files with 45 additions and 18 deletions
+25 -9
View File
@@ -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,37 @@ 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| {
let black = flags
.black_color
.as_deref()
.map(|color| {
parse_color_to_i32(color).map_err(|e| {
WrappedErr(
format!("Couldn't parse black color: {e} - is it formatted like a CSS color?")
format!(
"Couldn't parse black color {color:?}: {e} - is it formatted like a CSS color?"
)
.into()
)
})?;
})
})
.transpose()?
.unwrap_or(MUPDF_BLACK);
let white =
parse_color_to_i32(flags.white_color.as_deref().unwrap_or("FFFFFF")).map_err(|e| {
let white = flags
.white_color
.as_deref()
.map(|color| {
parse_color_to_i32(color).map_err(|e| {
WrappedErr(
format!("Couldn't parse white color: {e} - is it formatted like a CSS color?")
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.
+15 -4
View File
@@ -57,8 +57,8 @@ struct PrevRender {
num_search_found: Option<usize>
}
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<T: Default>(vec: &mut Vec<T>, 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
@@ -570,4 +570,15 @@ impl Iterator for PopOnNext<'_> {
fn next(&mut self) -> Option<Self::Item> {
self.inner.pop_front()
}
fn size_hint(&self) -> (usize, Option<usize>) {
let l = self.len();
(l, Some(l))
}
}
impl ExactSizeIterator for PopOnNext<'_> {
fn len(&self) -> usize {
self.inner.len()
}
}