From 69d5f963759486a96d14c5a570ad66b46e43b8c7 Mon Sep 17 00:00:00 2001 From: itsjunetime Date: Sun, 23 Mar 2025 12:57:38 -0600 Subject: [PATCH] Update deps and do some code simplifications --- Cargo.lock | 107 ++++++++++++++++++++++------------------------------- Cargo.toml | 2 +- src/tui.rs | 40 +++++++------------- 3 files changed, 60 insertions(+), 89 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1f68b4..42d8308 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,9 +349,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.16" +version = "1.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c" +checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a" dependencies = [ "jobserver", "libc", @@ -383,12 +383,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "cfg_aliases" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" - [[package]] name = "cfg_aliases" version = "0.2.1" @@ -759,9 +753,9 @@ checksum = "5729f5117e208430e437df2f4843f5e5952997175992d1414f94c57d61e270b4" [[package]] name = "deranged" -version = "0.3.11" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" dependencies = [ "powerfmt", ] @@ -1108,14 +1102,14 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" +checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" dependencies = [ "cfg-if", "libc", - "wasi 0.13.3+wasi-0.2.2", - "windows-targets 0.52.6", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", ] [[package]] @@ -1548,9 +1542,9 @@ dependencies = [ [[package]] name = "libmimalloc-sys" -version = "0.1.39" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44" +checksum = "07d0e07885d6a754b9c7993f2625187ad694ee985d60f23355ff0e7077261502" dependencies = [ "cc", "libc", @@ -1622,7 +1616,7 @@ version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0aeb26bf5e836cc1c341c8106051b573f1766dfa05aa87f0b98be5e51b02303" dependencies = [ - "nix 0.29.0", + "nix", "winapi", ] @@ -1674,9 +1668,9 @@ dependencies = [ [[package]] name = "mimalloc" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68914350ae34959d83f732418d51e2427a794055d0b9529f48259ac07af65633" +checksum = "99585191385958383e13f6b822e6b6d8d9cf928e7d286ceb092da92b43c87bc1" dependencies = [ "libmimalloc-sys", ] @@ -1718,7 +1712,7 @@ dependencies = [ [[package]] name = "mupdf" version = "0.4.4" -source = "git+https://github.com/itsjunetime/mupdf-rs?branch=june%2Fmupdf_1_25#9dab2e5deff2a018fe2bc001e7d97b8ace08c4d7" +source = "git+https://github.com/itsjunetime/mupdf-rs?branch=june%2Fmupdf_1_25#4a1d0740da26db0036cce5dd170e1274a92fd0e8" dependencies = [ "bitflags 2.9.0", "font-kit", @@ -1731,7 +1725,7 @@ dependencies = [ [[package]] name = "mupdf-sys" version = "0.4.4" -source = "git+https://github.com/itsjunetime/mupdf-rs?branch=june%2Fmupdf_1_25#9dab2e5deff2a018fe2bc001e7d97b8ace08c4d7" +source = "git+https://github.com/itsjunetime/mupdf-rs?branch=june%2Fmupdf_1_25#4a1d0740da26db0036cce5dd170e1274a92fd0e8" dependencies = [ "bindgen", "cc", @@ -1746,18 +1740,6 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" -[[package]] -name = "nix" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" -dependencies = [ - "bitflags 2.9.0", - "cfg-if", - "cfg_aliases 0.1.1", - "libc", -] - [[package]] name = "nix" version = "0.29.0" @@ -1766,7 +1748,7 @@ checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ "bitflags 2.9.0", "cfg-if", - "cfg_aliases 0.2.1", + "cfg_aliases", "libc", "memoffset", ] @@ -1977,7 +1959,7 @@ dependencies = [ [[package]] name = "pathfinder_simd" version = "0.5.4" -source = "git+https://github.com/itsjunetime/pathfinder.git#7fd835fabc1192ed9c83c31a61f5bb89af24238d" +source = "git+https://github.com/servo/pathfinder.git#8ccf6f7c2dd91f8e143998f91e55d1d24a4709bd" dependencies = [ "rustc_version", ] @@ -2082,7 +2064,7 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" dependencies = [ - "siphasher 1.0.1", + "siphasher", ] [[package]] @@ -2263,6 +2245,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + [[package]] name = "rand" version = "0.8.5" @@ -2705,12 +2693,6 @@ dependencies = [ "quote", ] -[[package]] -name = "siphasher" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" - [[package]] name = "siphasher" version = "1.0.1" @@ -2846,7 +2828,7 @@ dependencies = [ "itertools 0.14.0", "mimalloc", "mupdf", - "nix 0.29.0", + "nix", "notify", "ratatui", "ratatui-image", @@ -2878,12 +2860,12 @@ dependencies = [ [[package]] name = "termwiz" -version = "0.23.0" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed32af792ae81937cb8640b03eaef737408e5c8feee47b35e8b80c49bcb64524" +checksum = "4676b37242ccbd1aabf56edb093a4827dc49086c0ffd764a5705899e0f35f8f7" dependencies = [ "anyhow", - "base64 0.21.7", + "base64 0.22.1", "bitflags 2.9.0", "fancy-regex", "filedescriptor", @@ -2894,7 +2876,7 @@ dependencies = [ "libc", "log", "memmem", - "nix 0.28.0", + "nix", "num-derive", "num-traits", "ordered-float", @@ -2903,7 +2885,7 @@ dependencies = [ "phf", "sha2", "signal-hook", - "siphasher 0.3.11", + "siphasher", "terminfo", "termios", "thiserror 1.0.69", @@ -2970,9 +2952,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.39" +version = "0.3.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad298b01a40a23aac4580b67e3dbedb7cc8402f3592d7f49469de2ea4aecdd8" +checksum = "9d9c75b47bdff86fa3334a3db91356b8d7d86a9b839dab7d0bdc5c3d3a077618" dependencies = [ "deranged", "libc", @@ -2985,9 +2967,9 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "765c97a5b985b7c11d7bc27fa927dc4fe6af3a6dfb021d28deb60d3bf51e76ef" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" [[package]] name = "tinytemplate" @@ -3268,7 +3250,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "458f7a779bf54acc9f347480ac654f68407d3aab21269a6e3c9f922acd9e2da9" dependencies = [ "atomic", - "getrandom 0.3.1", + "getrandom 0.3.2", ] [[package]] @@ -3341,9 +3323,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasi" -version = "0.13.3+wasi-0.2.2" +version = "0.14.2+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" dependencies = [ "wit-bindgen-rt", ] @@ -3432,7 +3414,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692daff6d93d94e29e4114544ef6d5c942a7ed998b37abdc19b17136ea428eb7" dependencies = [ - "getrandom 0.3.1", + "getrandom 0.3.2", "mac_address", "sha2", "thiserror 1.0.69", @@ -3484,6 +3466,7 @@ dependencies = [ "bitflags 1.3.2", "euclid", "lazy_static", + "serde", "wezterm-dynamic", ] @@ -3750,9 +3733,9 @@ dependencies = [ [[package]] name = "wit-bindgen-rt" -version = "0.33.0" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" dependencies = [ "bitflags 2.9.0", ] @@ -3785,18 +3768,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.23" +version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd97444d05a4328b90e75e503a34bad781f14e28a823ad3557f0750df1ebcbc6" +checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.23" +version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6352c01d0edd5db859a63e2605f4ea3183ddbd15e2c4a9e7d32184df75e4f154" +checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index babe7af..f7c944f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -158,4 +158,4 @@ used_underscore_items = "warn" zero_sized_map_values = "warn" [patch.crates-io] -pathfinder_simd = { git = "https://github.com/itsjunetime/pathfinder.git" } +pathfinder_simd = { git = "https://github.com/servo/pathfinder.git" } diff --git a/src/tui.rs b/src/tui.rs index 4f2c8e9..9667e04 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -22,7 +22,10 @@ use ratatui::{ }; use ratatui_image::{Image, protocol::Protocol}; -use crate::{renderer::RenderError, skip::Skip}; +use crate::{ + renderer::{RenderError, fill_default}, + skip::Skip +}; pub struct Tui { name: String, @@ -239,9 +242,8 @@ impl Tui { let mut test_area_w = img_area.width; // go through our pages, starting at the first one we want to view let mut page_widths = self.rendered[self.page..] - .iter() - // and get their indices (I know it's offset, we fix it down below when we actually - // render each page) + .iter_mut() + // and get this to represent a count of how many we're looking at so far to render .enumerate() // and only take as many as are ready to be rendered .take_while(|(idx, page)| { @@ -252,9 +254,9 @@ 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(|(_, page)| page.img.as_mut().map(|img| (img.rect().width, img))) // and then take them as long as they won't overflow the available area. - .take_while(|(_, width)| match test_area_w.checked_sub(*width) { + .take_while(|(width, _)| match test_area_w.checked_sub(*width) { Some(new_val) => { test_area_w = new_val; true @@ -273,7 +275,7 @@ impl Tui { } else { execute!(stdout(), BeginSynchronizedUpdate).unwrap(); - let total_width = page_widths.iter().map(|(_, w)| w).sum::(); + let total_width = page_widths.iter().map(|(w, _)| w).sum::(); self.last_render.pages_shown = page_widths.len(); @@ -281,17 +283,8 @@ impl Tui { self.last_render.unused_width = unused_width; img_area.x += unused_width / 2; - for (page_idx, width) in page_widths { - // now, theoretically, when we call this, this page should *not* be None, but we do - // have to account for that possibility since we can't `borrow` the image from self - // when passing it in to `render_single_page` since that would be a mutable - // reference + an immutable reference (and also we need to potentially temporarily - // remove it from the array of rendered pages to replace it with a text-rendered - // image) - self.render_single_page(frame, page_idx + self.page, Rect { - width, - ..img_area - }); + for (width, img) in page_widths { + Self::render_single_page(frame, img, Rect { width, ..img_area }); img_area.x += width; } @@ -302,11 +295,8 @@ 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 mut page_img) => frame.render_widget(Image::new(page_img), img_area), - None => Self::render_loading_in(frame, img_area) - }; + fn render_single_page(frame: &mut Frame<'_>, page_img: &mut Protocol, img_area: Rect) { + frame.render_widget(Image::new(page_img), img_area); } fn render_loading_in(frame: &mut Frame<'_>, area: Rect) { @@ -350,9 +340,7 @@ impl Tui { } pub fn set_n_pages(&mut self, n_pages: usize) { - self.rendered = std::iter::from_fn(|| Some(RenderedInfo::default())) - .take(n_pages) - .collect(); + fill_default(&mut self.rendered, n_pages); self.page = self.page.min(n_pages - 1); }