mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-02 08:01:47 -04:00
Compare commits
9 Commits
v0.5.0
...
update_deps
| Author | SHA1 | Date | |
|---|---|---|---|
| d8e789627c | |||
| 51120a16fe | |||
| 2d40444273 | |||
| 580af3668f | |||
| 577141e201 | |||
| 828db8aed3 | |||
| 39a4bdafb6 | |||
| 19030f7fd4 | |||
| d5d62c81a3 |
@@ -1,2 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
debug.log
|
debug.log
|
||||||
|
/.envrc
|
||||||
|
/.direnv/
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- Added keybindings (`0`/`$`) to scroll to left or right side of zoomed-in image ([#131](https://github.com/itsjunetime/tdf/pull/131), thank you [@IshDeshpa](https://github.com/IshDeshpa)!)
|
||||||
|
|
||||||
# v0.5.0
|
# v0.5.0
|
||||||
|
|
||||||
- Switched simd base64 crate for one that works on stable (from `vb64` to `base64_simd`)
|
- Switched simd base64 crate for one that works on stable (from `vb64` to `base64_simd`)
|
||||||
|
|||||||
Generated
+383
-739
File diff suppressed because it is too large
Load Diff
+6
-6
@@ -23,10 +23,10 @@ name = "tdf"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# 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
|
# 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", rev = "4209a4e7e8bff298d8f18c220eb29423c293177b", default-features = false, features = [ "crossterm", "layout-cache" ] }
|
||||||
# ratatui = { path = "./ratatui/ratatui/" }
|
# 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 `Protocol`. It also just includes a few more features that I'm waiting on main to upstream
|
# 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 `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", default-features = false }
|
ratatui-image = { git = "https://github.com/itsjunetime/ratatui-image.git", rev = "cd865215737d18980379b69d20918d22f6357dda", default-features = false }
|
||||||
# ratatui-image = { path = "./ratatui-image", default-features = false }
|
# ratatui-image = { path = "./ratatui-image", default-features = false }
|
||||||
crossterm = { version = "0.29.0", features = ["event-stream"] }
|
crossterm = { version = "0.29.0", features = ["event-stream"] }
|
||||||
# crossterm = { path = "../crossterm", features = ["event-stream"] }
|
# crossterm = { path = "../crossterm", features = ["event-stream"] }
|
||||||
@@ -34,16 +34,17 @@ image = { version = "0.25.1", features = ["pnm", "rayon", "png"], default-featur
|
|||||||
notify = { version = "8.0.0", features = ["crossbeam-channel"] }
|
notify = { version = "8.0.0", features = ["crossbeam-channel"] }
|
||||||
tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] }
|
||||||
futures-util = { version = "0.3.30", default-features = false }
|
futures-util = { version = "0.3.30", default-features = false }
|
||||||
flume = { version = "0.11.0", default-features = false, features = ["async"] }
|
flume = { version = "0.12.0", default-features = false, features = ["async"] }
|
||||||
xflags = "0.4.0-pre.2"
|
xflags = "0.4.0-pre.2"
|
||||||
mimalloc = "0.1.43"
|
mimalloc = "0.1.43"
|
||||||
nix = { version = "0.30.0", features = ["signal"] }
|
nix = { version = "0.31.0", features = ["signal"] }
|
||||||
mupdf = { git = "https://github.com/messense/mupdf-rs.git", rev = "2e0fae910fac8048c7008211fc4d3b9f5d227a07", default-features = false, features = ["svg", "system-fonts", "img"] }
|
mupdf = { git = "https://github.com/messense/mupdf-rs.git", rev = "2e0fae910fac8048c7008211fc4d3b9f5d227a07", default-features = false, features = ["svg", "system-fonts", "img"] }
|
||||||
rayon = { version = "1", default-features = false }
|
rayon = { version = "1", default-features = false }
|
||||||
# kittage = { path = "../kittage/", features = ["crossterm-tokio", "image-crate", "log"] }
|
# kittage = { path = "../kittage/", features = ["crossterm-tokio", "image-crate", "log"] }
|
||||||
kittage = { version = "0.1.1", features = ["crossterm-tokio", "image-crate", "log"] }
|
kittage = { version = "0.1.1", features = ["crossterm-tokio", "image-crate", "log"] }
|
||||||
memmap2 = "0"
|
memmap2 = "0"
|
||||||
csscolorparser = { version = "0.8.0", default-features = false }
|
csscolorparser = { version = "0.8.0", default-features = false }
|
||||||
|
debounce = "0.2.2"
|
||||||
|
|
||||||
# logging
|
# logging
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
@@ -51,7 +52,6 @@ flexi_logger = "0.31"
|
|||||||
|
|
||||||
# for tracing with tokio-console
|
# for tracing with tokio-console
|
||||||
console-subscriber = { version = "0.5.0", optional = true }
|
console-subscriber = { version = "0.5.0", optional = true }
|
||||||
debounce = "0.2.2"
|
|
||||||
|
|
||||||
[profile.production]
|
[profile.production]
|
||||||
inherits = "release"
|
inherits = "release"
|
||||||
@@ -64,7 +64,7 @@ epub = ["mupdf/epub"]
|
|||||||
cbz = ["mupdf/cbz"]
|
cbz = ["mupdf/cbz"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = { version = "0.7.0", features = ["async_tokio"] }
|
criterion = { version = "0.8.0", features = ["async_tokio"] }
|
||||||
cpuprofiler = "0.0.4"
|
cpuprofiler = "0.0.4"
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
|
|||||||
+2
-2
@@ -65,7 +65,6 @@ pub fn start_rendering_loop(
|
|||||||
Sender<RenderNotif>
|
Sender<RenderNotif>
|
||||||
) {
|
) {
|
||||||
let pathbuf = path.as_ref().canonicalize().unwrap();
|
let pathbuf = path.as_ref().canonicalize().unwrap();
|
||||||
let str_path = pathbuf.into_os_string().to_string_lossy().to_string();
|
|
||||||
|
|
||||||
let (to_render_tx, from_main_rx) = unbounded();
|
let (to_render_tx, from_main_rx) = unbounded();
|
||||||
let (to_main_tx, from_render_rx) = unbounded();
|
let (to_main_tx, from_render_rx) = unbounded();
|
||||||
@@ -91,7 +90,7 @@ pub fn start_rendering_loop(
|
|||||||
let cell_width_px = size.width / size.columns;
|
let cell_width_px = size.width / size.columns;
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
start_rendering(
|
start_rendering(
|
||||||
&str_path,
|
&pathbuf,
|
||||||
to_main_tx,
|
to_main_tx,
|
||||||
from_main_rx,
|
from_main_rx,
|
||||||
cell_height_px,
|
cell_height_px,
|
||||||
@@ -117,6 +116,7 @@ pub fn start_converting_loop(
|
|||||||
let (to_converter_tx, from_main_rx) = unbounded();
|
let (to_converter_tx, from_main_rx) = unbounded();
|
||||||
let (to_main_tx, from_converter_rx) = unbounded();
|
let (to_main_tx, from_converter_rx) = unbounded();
|
||||||
|
|
||||||
|
#[expect(deprecated)]
|
||||||
let mut picker = Picker::from_fontsize(FONT_SIZE);
|
let mut picker = Picker::from_fontsize(FONT_SIZE);
|
||||||
picker.set_protocol_type(proto);
|
picker.set_protocol_type(proto);
|
||||||
|
|
||||||
|
|||||||
+1
-1
Submodule ratatui updated: 6a0b8ddf76...4209a4e7e8
+1
-1
Submodule ratatui-image updated: 9564ae6466...cd86521573
@@ -5,10 +5,7 @@ pkgs.mkShell {
|
|||||||
nativeBuildInputs = [ pkgs.pkg-config ];
|
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
pkgs.cargo
|
|
||||||
pkgs.rustc
|
|
||||||
pkgs.rustPlatform.bindgenHook
|
pkgs.rustPlatform.bindgenHook
|
||||||
pkgs.cairo
|
pkgs.cairo
|
||||||
pkgs.rust-analyzer
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-19
@@ -39,7 +39,7 @@ use tdf::{
|
|||||||
PrerenderLimit,
|
PrerenderLimit,
|
||||||
converter::{ConvertedPage, ConverterMsg, run_conversion_loop},
|
converter::{ConvertedPage, ConverterMsg, run_conversion_loop},
|
||||||
kitty::{KittyDisplay, display_kitty_images, do_shms_work, run_action},
|
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}
|
tui::{BottomMessage, InputAction, MessageSetting, Tui}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -128,21 +128,37 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
|||||||
.canonicalize()
|
.canonicalize()
|
||||||
.map_err(|e| WrappedErr(format!("Cannot canonicalize provided file: {e}").into()))?;
|
.map_err(|e| WrappedErr(format!("Cannot canonicalize provided file: {e}").into()))?;
|
||||||
|
|
||||||
let black =
|
let black = flags
|
||||||
parse_color_to_i32(flags.black_color.as_deref().unwrap_or("000000")).map_err(|e| {
|
.black_color
|
||||||
WrappedErr(
|
.as_deref()
|
||||||
format!("Couldn't parse black color: {e} - is it formatted like a CSS color?")
|
.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()
|
.into()
|
||||||
)
|
)
|
||||||
})?;
|
})
|
||||||
|
})
|
||||||
|
.transpose()?
|
||||||
|
.unwrap_or(MUPDF_BLACK);
|
||||||
|
|
||||||
let white =
|
let white = flags
|
||||||
parse_color_to_i32(flags.white_color.as_deref().unwrap_or("FFFFFF")).map_err(|e| {
|
.white_color
|
||||||
WrappedErr(
|
.as_deref()
|
||||||
format!("Couldn't parse white color: {e} - is it formatted like a CSS color?")
|
.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()
|
.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.
|
// 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.
|
// Just need to make sure it doesn't get dropped yet.
|
||||||
@@ -193,10 +209,6 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
|||||||
)
|
)
|
||||||
.map_err(|e| WrappedErr(format!("Can't watch the provided file: {e}").into()))?;
|
.map_err(|e| WrappedErr(format!("Can't watch the provided file: {e}").into()))?;
|
||||||
|
|
||||||
// TODO: Handle non-utf8 file names? Maybe by constructing a CString and passing that in to the
|
|
||||||
// mupdf stuff instead of a rust string?
|
|
||||||
let file_path = path.clone().into_os_string().to_string_lossy().to_string();
|
|
||||||
|
|
||||||
let mut window_size = window_size().map_err(|e| {
|
let mut window_size = window_size().map_err(|e| {
|
||||||
WrappedErr(format!("Can't get your current terminal window size: {e}").into())
|
WrappedErr(format!("Can't get your current terminal window size: {e}").into())
|
||||||
})?;
|
})?;
|
||||||
@@ -234,8 +246,13 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
|||||||
window_size.width != 0
|
window_size.width != 0
|
||||||
&& window_size.height != 0
|
&& window_size.height != 0
|
||||||
&& window_size.columns != 0
|
&& window_size.columns != 0
|
||||||
&& window_size.rows != 0
|
&& window_size.rows != 0 =>
|
||||||
=> Ok(Picker::from_fontsize((cell_width_px, cell_height_px))),
|
{
|
||||||
|
// the 'equivalent' that is suggested instead is not the same. We need to keep
|
||||||
|
// calling this.
|
||||||
|
#[expect(deprecated)]
|
||||||
|
Ok(Picker::from_fontsize((cell_width_px, cell_height_px)))
|
||||||
|
},
|
||||||
ratatui_image::errors::Errors::NoFontSize => Err(WrappedErr(
|
ratatui_image::errors::Errors::NoFontSize => Err(WrappedErr(
|
||||||
"Unable to detect your terminal's font size; this is an issue with your terminal emulator.\nPlease use a different terminal emulator or report this bug to tdf.".into()
|
"Unable to detect your terminal's font size; this is an issue with your terminal emulator.\nPlease use a different terminal emulator or report this bug to tdf.".into()
|
||||||
)),
|
)),
|
||||||
@@ -250,6 +267,7 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
|||||||
.and_then(NonZeroUsize::new)
|
.and_then(NonZeroUsize::new)
|
||||||
.map_or(PrerenderLimit::All, PrerenderLimit::Limited);
|
.map_or(PrerenderLimit::All, PrerenderLimit::Limited);
|
||||||
|
|
||||||
|
let file_path = path.clone();
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
renderer::start_rendering(
|
renderer::start_rendering(
|
||||||
&file_path,
|
&file_path,
|
||||||
|
|||||||
+18
-7
@@ -1,4 +1,4 @@
|
|||||||
use std::{collections::VecDeque, num::NonZeroUsize, thread::sleep, time::Duration};
|
use std::{collections::VecDeque, num::NonZeroUsize, path::Path, thread::sleep, time::Duration};
|
||||||
|
|
||||||
use flume::{Receiver, SendError, Sender, TryRecvError};
|
use flume::{Receiver, SendError, Sender, TryRecvError};
|
||||||
use mupdf::{
|
use mupdf::{
|
||||||
@@ -57,8 +57,8 @@ struct PrevRender {
|
|||||||
num_search_found: Option<usize>
|
num_search_found: Option<usize>
|
||||||
}
|
}
|
||||||
|
|
||||||
const MUPDF_BLACK: i32 = 0;
|
pub const MUPDF_BLACK: i32 = 0;
|
||||||
const MUPDF_WHITE: i32 = i32::from_be_bytes([0, 0xff, 0xff, 0xff]);
|
pub const MUPDF_WHITE: i32 = i32::from_be_bytes([0, 0xff, 0xff, 0xff]);
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn fill_default<T: Default>(vec: &mut Vec<T>, size: usize) {
|
pub fn fill_default<T: Default>(vec: &mut Vec<T>, size: usize) {
|
||||||
@@ -80,7 +80,7 @@ pub fn fill_default<T: Default>(vec: &mut Vec<T>, size: usize) {
|
|||||||
// probably be more performant if accessed by-value instead of through a reference. Probably.
|
// probably be more performant if accessed by-value instead of through a reference. Probably.
|
||||||
#[expect(clippy::needless_pass_by_value, clippy::too_many_arguments)]
|
#[expect(clippy::needless_pass_by_value, clippy::too_many_arguments)]
|
||||||
pub fn start_rendering(
|
pub fn start_rendering(
|
||||||
path: &str,
|
path: &Path,
|
||||||
sender: Sender<Result<RenderInfo, RenderError>>,
|
sender: Sender<Result<RenderInfo, RenderError>>,
|
||||||
receiver: Receiver<RenderNotif>,
|
receiver: Receiver<RenderNotif>,
|
||||||
col_h: u16,
|
col_h: u16,
|
||||||
@@ -152,8 +152,8 @@ pub fn start_rendering(
|
|||||||
|
|
||||||
sender.send(Ok(RenderInfo::NumPages(n_pages.get())))?;
|
sender.send(Ok(RenderInfo::NumPages(n_pages.get())))?;
|
||||||
|
|
||||||
// We're using this vec of bools to indicate which page numbers have already been rendered,
|
// We're using this vec to indicate which page numbers have already been rendered, to
|
||||||
// to support people jumping to specific pages and having quick rendering results. We
|
// support people jumping to specific pages and having quick rendering results. We
|
||||||
// `split_at_mut` at 0 initially (which bascially makes `right == rendered && left == []`),
|
// `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,
|
// 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
|
// 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:
|
// we only want to continue if one of the following is met:
|
||||||
// 1. It failed to render last time (we want to retry)
|
// 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
|
// 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() {
|
if rendered.successful && rendered.num_search_found.is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -570,4 +570,15 @@ impl Iterator for PopOnNext<'_> {
|
|||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
self.inner.pop_front()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+107
-42
@@ -102,6 +102,70 @@ impl Zoom {
|
|||||||
ZOOM_RATE_GRANULAR.powi(self.level.into())
|
ZOOM_RATE_GRANULAR.powi(self.level.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn step_in(&mut self) {
|
||||||
|
self.level = self.level.saturating_add(1);
|
||||||
|
}
|
||||||
|
fn step_out(&mut self) {
|
||||||
|
self.level = self.level.saturating_sub(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Make this configurable, maybe allow fractional steps?
|
||||||
|
// With fractional steps, it might also be a good idea to have these
|
||||||
|
// have the same ratio as the font aspect ratio.
|
||||||
|
const PAN_STEP_X: i16 = 2;
|
||||||
|
const PAN_STEP_Y: i16 = 1;
|
||||||
|
|
||||||
|
fn pan(&mut self, direction: Direction) {
|
||||||
|
let (target, sign) = match direction {
|
||||||
|
Direction::Up => (&mut self.cell_pan_from_top, -1),
|
||||||
|
Direction::Down => (&mut self.cell_pan_from_top, 1),
|
||||||
|
Direction::Left => (&mut self.cell_pan_from_left, -1),
|
||||||
|
Direction::Right => (&mut self.cell_pan_from_left, 1)
|
||||||
|
};
|
||||||
|
let step = if direction.is_vertical() {
|
||||||
|
Self::PAN_STEP_Y
|
||||||
|
} else {
|
||||||
|
Self::PAN_STEP_X
|
||||||
|
};
|
||||||
|
*target = target.saturating_add_signed(sign * step);
|
||||||
|
}
|
||||||
|
fn pan_bottom(&mut self) {
|
||||||
|
self.cell_pan_from_top = 0;
|
||||||
|
}
|
||||||
|
fn pan_top(&mut self) {
|
||||||
|
self.cell_pan_from_top = u16::MAX;
|
||||||
|
}
|
||||||
|
fn pan_left(&mut self) {
|
||||||
|
self.cell_pan_from_left = 0;
|
||||||
|
}
|
||||||
|
fn pan_right(&mut self) {
|
||||||
|
self.cell_pan_from_left = u16::MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
enum Direction {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right
|
||||||
|
}
|
||||||
|
impl Direction {
|
||||||
|
/// Flips the directions for vertical and horizonal panning.
|
||||||
|
fn flip_mouse_xy(self) -> Self {
|
||||||
|
match self {
|
||||||
|
Self::Up => Self::Left,
|
||||||
|
Self::Left => Self::Up,
|
||||||
|
Self::Down => Self::Right,
|
||||||
|
Self::Right => Self::Down
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn is_vertical(self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Up | Self::Down => true,
|
||||||
|
Self::Left | Self::Right => false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This seems like a kinda weird struct because it holds two optionals but any representation
|
// This seems like a kinda weird struct because it holds two optionals but any representation
|
||||||
@@ -288,7 +352,6 @@ impl Tui {
|
|||||||
}])
|
}])
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make a way to fill the width of the screen with one page and scroll down to view it
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn render<'s>(
|
pub fn render<'s>(
|
||||||
&'s mut self,
|
&'s mut self,
|
||||||
@@ -637,6 +700,8 @@ impl Tui {
|
|||||||
InputAction::JumpingToPage(new_page)
|
InputAction::JumpingToPage(new_page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let can_zoom = self.is_kitty && self.zoom.is_some();
|
||||||
|
|
||||||
match ev {
|
match ev {
|
||||||
Event::Key(key) => {
|
Event::Key(key) => {
|
||||||
match key.code {
|
match key.code {
|
||||||
@@ -653,7 +718,7 @@ impl Tui {
|
|||||||
self.bottom_msg
|
self.bottom_msg
|
||||||
{
|
{
|
||||||
if c == 'g' && self.is_kitty {
|
if c == 'g' && self.is_kitty {
|
||||||
self.update_zoom(|z| z.cell_pan_from_top = 0);
|
self.update_zoom(Zoom::pan_bottom);
|
||||||
self.set_msg(MessageSetting::Pop);
|
self.set_msg(MessageSetting::Pop);
|
||||||
return Some(InputAction::Redraw);
|
return Some(InputAction::Redraw);
|
||||||
}
|
}
|
||||||
@@ -762,24 +827,15 @@ impl Tui {
|
|||||||
self.last_render.rect = Rect::default();
|
self.last_render.rect = Rect::default();
|
||||||
Some(InputAction::SwitchRenderZoom(f_or_f))
|
Some(InputAction::SwitchRenderZoom(f_or_f))
|
||||||
}
|
}
|
||||||
'o' if self.is_kitty =>
|
'o' if can_zoom => self.update_zoom(Zoom::step_in),
|
||||||
self.update_zoom(|z| z.level = z.level.saturating_add(1)),
|
'O' if can_zoom => self.update_zoom(Zoom::step_out),
|
||||||
'O' if self.is_kitty =>
|
'L' if can_zoom => self.update_zoom(|z| z.pan(Direction::Right)),
|
||||||
self.update_zoom(|z| z.level = z.level.saturating_sub(1)),
|
'H' if can_zoom => self.update_zoom(|z| z.pan(Direction::Left)),
|
||||||
'L' if self.is_kitty => self.update_zoom(|z| {
|
'J' if can_zoom => self.update_zoom(|z| z.pan(Direction::Down)),
|
||||||
z.cell_pan_from_left = z.cell_pan_from_left.saturating_add(1);
|
'K' if can_zoom => self.update_zoom(|z| z.pan(Direction::Up)),
|
||||||
}),
|
'G' if can_zoom => self.update_zoom(Zoom::pan_top),
|
||||||
'H' if self.is_kitty => self.update_zoom(|z| {
|
'0' if can_zoom => self.update_zoom(Zoom::pan_left),
|
||||||
z.cell_pan_from_left = z.cell_pan_from_left.saturating_sub(1);
|
'$' if can_zoom => self.update_zoom(Zoom::pan_right),
|
||||||
}),
|
|
||||||
'J' if self.is_kitty => self.update_zoom(|z| {
|
|
||||||
z.cell_pan_from_top = z.cell_pan_from_top.saturating_add(1);
|
|
||||||
}),
|
|
||||||
'K' if self.is_kitty => self.update_zoom(|z| {
|
|
||||||
z.cell_pan_from_top = z.cell_pan_from_top.saturating_sub(1);
|
|
||||||
}),
|
|
||||||
'G' if self.is_kitty =>
|
|
||||||
self.update_zoom(|z| z.cell_pan_from_top = u16::MAX),
|
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -866,29 +922,36 @@ impl Tui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Mouse(mouse) => {
|
Event::Mouse(mouse) => {
|
||||||
if mouse.modifiers.contains(KeyModifiers::CONTROL)
|
let mut handle_scroll = |mut direction: Direction| {
|
||||||
&& self.is_kitty
|
if can_zoom {
|
||||||
&& self.zoom.is_some()
|
if mouse.modifiers.contains(KeyModifiers::CONTROL) {
|
||||||
{
|
match direction {
|
||||||
match mouse.kind {
|
Direction::Up => self.update_zoom(Zoom::step_in),
|
||||||
MouseEventKind::ScrollUp =>
|
Direction::Down => self.update_zoom(Zoom::step_out),
|
||||||
self.update_zoom(|z| z.level = z.level.saturating_add(1).min(0)),
|
_ => None
|
||||||
MouseEventKind::ScrollDown =>
|
}
|
||||||
self.update_zoom(|z| z.level = z.level.saturating_sub(1)),
|
} else {
|
||||||
_ => None
|
if mouse.modifiers.contains(KeyModifiers::SHIFT) {
|
||||||
}
|
direction = direction.flip_mouse_xy();
|
||||||
} else {
|
}
|
||||||
match mouse.kind {
|
self.update_zoom(|z| z.pan(direction))
|
||||||
MouseEventKind::ScrollRight =>
|
}
|
||||||
self.change_page(PageChange::Next, ChangeAmount::Single),
|
} else {
|
||||||
MouseEventKind::ScrollDown =>
|
let (change, amount) = match direction {
|
||||||
self.change_page(PageChange::Next, ChangeAmount::WholeScreen),
|
Direction::Right => (PageChange::Next, ChangeAmount::Single),
|
||||||
MouseEventKind::ScrollLeft =>
|
Direction::Down => (PageChange::Next, ChangeAmount::WholeScreen),
|
||||||
self.change_page(PageChange::Prev, ChangeAmount::Single),
|
Direction::Left => (PageChange::Prev, ChangeAmount::Single),
|
||||||
MouseEventKind::ScrollUp =>
|
Direction::Up => (PageChange::Prev, ChangeAmount::WholeScreen)
|
||||||
self.change_page(PageChange::Prev, ChangeAmount::WholeScreen),
|
};
|
||||||
_ => None
|
self.change_page(change, amount)
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
match mouse.kind {
|
||||||
|
MouseEventKind::ScrollRight => handle_scroll(Direction::Right),
|
||||||
|
MouseEventKind::ScrollDown => handle_scroll(Direction::Down),
|
||||||
|
MouseEventKind::ScrollLeft => handle_scroll(Direction::Left),
|
||||||
|
MouseEventKind::ScrollUp => handle_scroll(Direction::Up),
|
||||||
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Resize(_, _) => Some(InputAction::Redraw),
|
Event::Resize(_, _) => Some(InputAction::Redraw),
|
||||||
@@ -1042,6 +1105,8 @@ gg/G (when on fill-screen):
|
|||||||
Scroll to top/bottom of page
|
Scroll to top/bottom of page
|
||||||
H, J, K, L (when zoomed in):
|
H, J, K, L (when zoomed in):
|
||||||
Pan direction around page
|
Pan direction around page
|
||||||
|
0/$ (when on fill-screen):
|
||||||
|
Scroll to left/right side of page
|
||||||
";
|
";
|
||||||
|
|
||||||
pub enum InputAction {
|
pub enum InputAction {
|
||||||
|
|||||||
Reference in New Issue
Block a user