mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-01 23:51:46 -04:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e2a9c90b34 | |||
| 16c0aed9a3 |
+29
-132
@@ -2,144 +2,41 @@ name: Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
tags: ["v*.*.*"]
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
workflow_dispatch:
|
||||
workflow_call:
|
||||
branches: [ "main" ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
tip_release_path: RELEASE.md
|
||||
|
||||
jobs:
|
||||
test-build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { os: "macos-latest", target: "aarch64-apple-darwin" }
|
||||
- { os: "ubuntu-latest", target: "x86_64-unknown-linux-gnu" }
|
||||
- {
|
||||
os: "windows-latest",
|
||||
target: "x86_64-pc-windows-msvc",
|
||||
ext: ".exe",
|
||||
}
|
||||
- { os: "ubuntu-24.04-arm", target: "aarch64-unknown-linux-gnu" }
|
||||
build:
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Setup sccache
|
||||
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
||||
uses: mozilla-actions/sccache-action@v0.0.8
|
||||
- name: Configure sccache
|
||||
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
||||
run: |
|
||||
echo "SCCACHE_GHA_ENABLED=true" >> "$GITHUB_ENV"
|
||||
echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Setup rust cache action
|
||||
uses: swatinem/rust-cache@v2
|
||||
with:
|
||||
cache-on-failure: true
|
||||
|
||||
- name: install build dependencies on ubuntu and cache
|
||||
if: contains(matrix.os, 'ubuntu')
|
||||
uses: awalsh128/cache-apt-pkgs-action@latest
|
||||
with:
|
||||
packages: libfontconfig1-dev libgoogle-perftools-dev google-perftools
|
||||
version: latest # could be anything
|
||||
|
||||
- name: Install clippy and fmt
|
||||
run: rustup component add clippy rustfmt
|
||||
- name: Clippy
|
||||
run: cargo clippy --locked -- -D warnings
|
||||
- name: Tests
|
||||
run: cargo test --locked
|
||||
- name: Check fmt
|
||||
run: cargo fmt -- --check
|
||||
- name: Run benchmarks as tests
|
||||
run: cargo test --locked --benches -- adobe_example
|
||||
|
||||
- name: Set build mode
|
||||
shell: bash
|
||||
run: if [ "${{github.ref_type}}" == "tag" ] || [ ${{ github.event_name == 'push' && github.ref_name == 'main' }} ]; then echo "BMODE=production">>"$GITHUB_ENV"; fi
|
||||
|
||||
- name: Build in ${{env.BMODE || 'debug'}} mode
|
||||
run: cargo build --verbose --locked --profile ${{env.BMODE || 'dev'}}
|
||||
|
||||
- name: Prepare artifact
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p dist
|
||||
cp "target/${{env.BMODE || 'debug'}}/tdf${{ matrix.ext }}" dist/tdf-${{ matrix.target }}${{ matrix.ext }}
|
||||
tree dist || ls -la dist
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: tdf-${{ matrix.target }}
|
||||
path: dist/tdf*
|
||||
|
||||
tag-release:
|
||||
name: Release on tag push
|
||||
runs-on: ubuntu-slim
|
||||
if: github.ref_type == 'tag'
|
||||
needs: test-build
|
||||
steps:
|
||||
- uses: actions/download-artifact@v6
|
||||
with:
|
||||
pattern: "**/tdf-*"
|
||||
path: release-artifacts
|
||||
merge-multiple: true
|
||||
|
||||
- name: What's up?
|
||||
run: tree release-artifacts # beautiful!
|
||||
|
||||
- name: Create a GitHub release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
draft: true
|
||||
generate_release_notes: true
|
||||
files: release-artifacts/*
|
||||
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
|
||||
|
||||
tip-release:
|
||||
name: Release tip on push to main
|
||||
runs-on: ubuntu-slim
|
||||
if: github.event_name == 'push' && github.ref_name == 'main'
|
||||
needs: test-build
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Download prebuilt artifacts
|
||||
uses: actions/download-artifact@v7
|
||||
with:
|
||||
path: release-artifacts
|
||||
merge-multiple: true
|
||||
|
||||
- name: Generate release notes
|
||||
run: |
|
||||
tree release-artifacts/
|
||||
echo "From commit: $(git rev-parse --short HEAD)" > ${{ env.tip_release_path }}
|
||||
echo "Generated on: $(date -u +"%Y-%m-%d %H:%M") UTC" >> ${{ env.tip_release_path }}
|
||||
cat ${{ env.tip_release_path }}
|
||||
|
||||
- name: Update the tip tag
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag --force tip && git push --force origin tag tip
|
||||
|
||||
- name: Update the draft tip release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
prerelease: true
|
||||
files: release-artifacts/*
|
||||
tag_name: tip
|
||||
name: Tip Build
|
||||
body_path: ${{ env.tip_release_path }}
|
||||
- name: Setup sccache
|
||||
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
||||
uses: mozilla-actions/sccache-action@v0.0.8
|
||||
- name: Configure sccache
|
||||
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
||||
run: |
|
||||
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
|
||||
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
|
||||
- name: Install build dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libfontconfig1-dev libgoogle-perftools-dev google-perftools
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install clippy and fmt
|
||||
run: rustup component add clippy rustfmt
|
||||
- name: Clippy
|
||||
run: cargo clippy --locked -- -D warnings
|
||||
- name: Tests
|
||||
run: cargo test --locked
|
||||
- name: Check fmt
|
||||
run: cargo fmt -- --check
|
||||
- name: Run benchmarks as tests
|
||||
run: cargo test --locked --benches -- adobe_example
|
||||
- name: Build
|
||||
run: cargo build --locked
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
/target
|
||||
debug.log
|
||||
/.envrc
|
||||
/.direnv/
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
# Unreleased
|
||||
|
||||
- Added windows support! (thank you to [@jarjk](https://github.com/jarjk) for helping out!)
|
||||
- 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)!)
|
||||
- (Internal) decreased runtime footprint of tokio runtime
|
||||
|
||||
# v0.5.0
|
||||
|
||||
- Switched simd base64 crate for one that works on stable (from `vb64` to `base64_simd`)
|
||||
|
||||
Generated
+780
-423
File diff suppressed because it is too large
Load Diff
+8
-8
@@ -23,10 +23,10 @@ name = "tdf"
|
||||
|
||||
[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
|
||||
ratatui = { git = "https://github.com/itsjunetime/ratatui.git", rev = "720ac2d0cad1ac6424364fea74856fec9c100cb1", default-features = false, features = [ "crossterm", "layout-cache" ] }
|
||||
ratatui = { git = "https://github.com/itsjunetime/ratatui.git" }
|
||||
# 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
|
||||
ratatui-image = { git = "https://github.com/itsjunetime/ratatui-image.git", rev = "a276a87cb8e2976442c6cc59db831db81551da89", default-features = false }
|
||||
ratatui-image = { git = "https://github.com/itsjunetime/ratatui-image.git", branch = "vb64_on_personal", default-features = false }
|
||||
# ratatui-image = { path = "./ratatui-image", default-features = false }
|
||||
crossterm = { version = "0.29.0", features = ["event-stream"] }
|
||||
# crossterm = { path = "../crossterm", features = ["event-stream"] }
|
||||
@@ -34,17 +34,16 @@ image = { version = "0.25.1", features = ["pnm", "rayon", "png"], default-featur
|
||||
notify = { version = "8.0.0", features = ["crossbeam-channel"] }
|
||||
tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] }
|
||||
futures-util = { version = "0.3.30", default-features = false }
|
||||
flume = { version = "0.12.0", default-features = false, features = ["async"] }
|
||||
flume = { version = "0.11.0", default-features = false, features = ["async"] }
|
||||
xflags = "0.4.0-pre.2"
|
||||
mimalloc = "0.1.43"
|
||||
nix = { version = "0.31.0", features = ["signal"] }
|
||||
mupdf = { git = "https://github.com/messense/mupdf-rs.git", rev = "d7441b9998c92135e329559c0aa71d9dc92cf4de", default-features = false, features = ["svg", "system-fonts", "img"] }
|
||||
nix = { version = "0.30.0", features = ["signal"] }
|
||||
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 }
|
||||
# kittage = { path = "../kittage/", features = ["crossterm-tokio", "image-crate", "log"] }
|
||||
kittage = { version = "0.3.4", features = ["crossterm-tokio", "image-crate", "log"] }
|
||||
kittage = { version = "0.1.1", features = ["crossterm-tokio", "image-crate", "log"] }
|
||||
memmap2 = "0"
|
||||
csscolorparser = { version = "0.8.0", default-features = false }
|
||||
debounce = "0.2.2"
|
||||
|
||||
# logging
|
||||
log = "0.4.27"
|
||||
@@ -52,6 +51,7 @@ flexi_logger = "0.31"
|
||||
|
||||
# for tracing with tokio-console
|
||||
console-subscriber = { version = "0.5.0", optional = true }
|
||||
debounce = "0.2.2"
|
||||
|
||||
[profile.production]
|
||||
inherits = "release"
|
||||
@@ -64,7 +64,7 @@ epub = ["mupdf/epub"]
|
||||
cbz = ["mupdf/cbz"]
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.8.0", features = ["async_tokio"] }
|
||||
criterion = { version = "0.7.0", features = ["async_tokio"] }
|
||||
cpuprofiler = "0.0.4"
|
||||
|
||||
[[bench]]
|
||||
|
||||
@@ -34,12 +34,7 @@ fn for_all_combos(
|
||||
name: &'static str,
|
||||
mut f: impl FnMut(&Runtime, BenchmarkId, &'static str, ProtocolType)
|
||||
) {
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(3)
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
for proto in PROTOS {
|
||||
for file in FILES {
|
||||
f(
|
||||
|
||||
+2
-2
@@ -65,6 +65,7 @@ pub fn start_rendering_loop(
|
||||
Sender<RenderNotif>
|
||||
) {
|
||||
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_main_tx, from_render_rx) = unbounded();
|
||||
@@ -90,7 +91,7 @@ pub fn start_rendering_loop(
|
||||
let cell_width_px = size.width / size.columns;
|
||||
std::thread::spawn(move || {
|
||||
start_rendering(
|
||||
&pathbuf,
|
||||
&str_path,
|
||||
to_main_tx,
|
||||
from_main_rx,
|
||||
cell_height_px,
|
||||
@@ -116,7 +117,6 @@ pub fn start_converting_loop(
|
||||
let (to_converter_tx, from_main_rx) = unbounded();
|
||||
let (to_main_tx, from_converter_rx) = unbounded();
|
||||
|
||||
#[expect(deprecated)]
|
||||
let mut picker = Picker::from_fontsize(FONT_SIZE);
|
||||
picker.set_protocol_type(proto);
|
||||
|
||||
|
||||
+1
-1
Submodule ratatui updated: 720ac2d0ca...6a0b8ddf76
+1
-1
Submodule ratatui-image updated: a276a87cb8...9564ae6466
+4
-8
@@ -144,14 +144,10 @@ pub async fn run_conversion_loop(
|
||||
.as_nanos() % 1_000_000;
|
||||
|
||||
let mut img = if shms_work {
|
||||
let shm_name = format!("/tdf_{pid}_{rn}_{page_num}");
|
||||
|
||||
#[cfg(unix)]
|
||||
let shm_name = &*shm_name;
|
||||
|
||||
kittage::image::Image::shm_from(dyn_img, shm_name).map_err(|e| {
|
||||
RenderError::Converting(format!("Couldn't create shm: {e:?}"))
|
||||
})?
|
||||
kittage::image::Image::shm_from(dyn_img, &format!("/tdf_{pid}_{rn}_{page_num}"))
|
||||
.map_err(|e| {
|
||||
RenderError::Converting(format!("Couldn't write to shm: {e:?}"))
|
||||
})?
|
||||
} else {
|
||||
kittage::image::Image::from(dyn_img)
|
||||
};
|
||||
|
||||
+1
-6
@@ -78,12 +78,7 @@ pub async fn run_action<'es>(
|
||||
pub async fn do_shms_work(ev_stream: &mut EventStream) -> bool {
|
||||
let img = DynamicImage::new_rgb8(1, 1);
|
||||
let pid = std::process::id();
|
||||
let shm_name = format!("tdf_test_{pid}");
|
||||
|
||||
#[cfg(unix)]
|
||||
let shm_name = &*shm_name;
|
||||
|
||||
let Ok(mut k_img) = kittage::image::Image::shm_from(img, shm_name) else {
|
||||
let Ok(mut k_img) = kittage::image::Image::shm_from(img, &format!("tdf_test_{pid}")) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ pub fn scale_img_for_area(
|
||||
|
||||
// and get the ratio that this page would have to be scaled by to fit perfectly within the
|
||||
// area provided to us.
|
||||
// we do this first by comparing the aspect ratio of the page with the aspect ratio of the
|
||||
// we do this first by comparing the aspec ratio of the page with the aspect ratio of the
|
||||
// area to fit it within. If the aspect ratio of the page is larger, then we need to scale
|
||||
// the width of the page to fill perfectly within the height of the area. Otherwise, we
|
||||
// scale the height to fit perfectly. The dimension that _is not_ scaled to fit perfectly
|
||||
|
||||
+11
-21
@@ -70,18 +70,11 @@ fn reset_term() {
|
||||
);
|
||||
}
|
||||
|
||||
fn main() -> Result<(), WrappedErr> {
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(3)
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
rt.block_on(async move {
|
||||
let result = inner_main().await;
|
||||
reset_term();
|
||||
result
|
||||
})
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), WrappedErr> {
|
||||
let result = inner_main().await;
|
||||
reset_term();
|
||||
result
|
||||
}
|
||||
|
||||
async fn inner_main() -> Result<(), WrappedErr> {
|
||||
@@ -216,6 +209,10 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
)
|
||||
.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| {
|
||||
WrappedErr(format!("Can't get your current terminal window size: {e}").into())
|
||||
})?;
|
||||
@@ -253,13 +250,8 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
window_size.width != 0
|
||||
&& window_size.height != 0
|
||||
&& window_size.columns != 0
|
||||
&& window_size.rows != 0 =>
|
||||
{
|
||||
// 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)))
|
||||
},
|
||||
&& window_size.rows != 0
|
||||
=> Ok(Picker::from_fontsize((cell_width_px, cell_height_px))),
|
||||
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()
|
||||
)),
|
||||
@@ -274,7 +266,6 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
.and_then(NonZeroUsize::new)
|
||||
.map_or(PrerenderLimit::All, PrerenderLimit::Limited);
|
||||
|
||||
let file_path = path.clone();
|
||||
std::thread::spawn(move || {
|
||||
renderer::start_rendering(
|
||||
&file_path,
|
||||
@@ -408,7 +399,6 @@ async fn enter_redraw_loop(
|
||||
},
|
||||
InputAction::Search(term) => to_renderer.send(RenderNotif::Search(term))?,
|
||||
InputAction::Invert => to_renderer.send(RenderNotif::Invert)?,
|
||||
InputAction::Rotate => to_renderer.send(RenderNotif::Rotate)?,
|
||||
InputAction::Fullscreen => fullscreen = !fullscreen,
|
||||
InputAction::SwitchRenderZoom(f_or_f) => {
|
||||
to_renderer.send(RenderNotif::SwitchFitOrFill(f_or_f)).unwrap();
|
||||
|
||||
+6
-49
@@ -1,4 +1,4 @@
|
||||
use std::{collections::VecDeque, num::NonZeroUsize, path::Path, thread::sleep, time::Duration};
|
||||
use std::{collections::VecDeque, num::NonZeroUsize, thread::sleep, time::Duration};
|
||||
|
||||
use flume::{Receiver, SendError, Sender, TryRecvError};
|
||||
use mupdf::{
|
||||
@@ -20,8 +20,7 @@ pub enum RenderNotif {
|
||||
Search(String),
|
||||
SwitchFitOrFill(FitOrFill),
|
||||
Reload,
|
||||
Invert,
|
||||
Rotate
|
||||
Invert
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -38,14 +37,6 @@ pub enum RenderInfo {
|
||||
Reloaded
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum RotateDirection {
|
||||
Deg0,
|
||||
Deg90,
|
||||
Deg180,
|
||||
Deg270
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PageInfo {
|
||||
pub img_data: ImageData,
|
||||
@@ -89,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.
|
||||
#[expect(clippy::needless_pass_by_value, clippy::too_many_arguments)]
|
||||
pub fn start_rendering(
|
||||
path: &Path,
|
||||
path: &str,
|
||||
sender: Sender<Result<RenderInfo, RenderError>>,
|
||||
receiver: Receiver<RenderNotif>,
|
||||
col_h: u16,
|
||||
@@ -107,21 +98,13 @@ pub fn start_rendering(
|
||||
|
||||
let mut stored_doc = None;
|
||||
let mut invert = false;
|
||||
let mut rotate = RotateDirection::Deg0;
|
||||
let mut preserved_area = None;
|
||||
let mut fit_or_fill = FitOrFill::Fit;
|
||||
|
||||
let mut need_rerender = VecDeque::new();
|
||||
|
||||
#[cfg(windows)]
|
||||
let path = path.to_string_lossy();
|
||||
|
||||
'reload: loop {
|
||||
// Need to do this weird borrow thing so that we convert `Cow<'_, str>` -> `&str` on windows
|
||||
// and keep unix a `&Path` -> `&Path` 'cause there are different requirements within mupdf
|
||||
// about file paths per-platform
|
||||
#[cfg_attr(unix, expect(clippy::borrow_deref_ref))]
|
||||
let doc = match Document::open(&*path) {
|
||||
let doc = match Document::open(path) {
|
||||
Err(e) => {
|
||||
// if there's an error, tell the main loop
|
||||
sender.send(Err(RenderError::Doc(e)))?;
|
||||
@@ -255,18 +238,6 @@ pub fn start_rendering(
|
||||
}
|
||||
continue 'render_pages;
|
||||
}
|
||||
RenderNotif::Rotate => {
|
||||
rotate = match rotate {
|
||||
RotateDirection::Deg0 => RotateDirection::Deg90,
|
||||
RotateDirection::Deg90 => RotateDirection::Deg180,
|
||||
RotateDirection::Deg180 => RotateDirection::Deg270,
|
||||
RotateDirection::Deg270 => RotateDirection::Deg0
|
||||
};
|
||||
for page in &mut rendered {
|
||||
page.successful = false;
|
||||
}
|
||||
continue 'render_pages;
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
@@ -330,7 +301,6 @@ pub fn start_rendering(
|
||||
black,
|
||||
white,
|
||||
fit_or_fill,
|
||||
rotate,
|
||||
(area_w, area_h)
|
||||
) {
|
||||
// If that fn returned Some, that means it needed to be re-rendered for some
|
||||
@@ -485,7 +455,6 @@ fn render_single_page_to_ctx(
|
||||
black: i32,
|
||||
white: i32,
|
||||
fit_or_fill: FitOrFill,
|
||||
rotate: RotateDirection,
|
||||
(area_w, area_h): (f32, f32)
|
||||
) -> Result<RenderedContext, mupdf::error::Error> {
|
||||
let result_rects = match prev_render.num_search_found {
|
||||
@@ -496,12 +465,7 @@ fn render_single_page_to_ctx(
|
||||
|
||||
// then, get the size of the page
|
||||
let bounds = page.bounds()?;
|
||||
let page_dim = match rotate {
|
||||
RotateDirection::Deg0 | RotateDirection::Deg180 =>
|
||||
(bounds.x1 - bounds.x0, bounds.y1 - bounds.y0),
|
||||
RotateDirection::Deg90 | RotateDirection::Deg270 =>
|
||||
(bounds.y1 - bounds.y0, bounds.x1 - bounds.x0),
|
||||
};
|
||||
let page_dim = (bounds.x1 - bounds.x0, bounds.y1 - bounds.y0);
|
||||
|
||||
let scaled = scale_img_for_area(page_dim, (area_w, area_h), fit_or_fill);
|
||||
let ScaledResult {
|
||||
@@ -518,13 +482,7 @@ fn render_single_page_to_ctx(
|
||||
}
|
||||
|
||||
let colorspace = Colorspace::device_rgb();
|
||||
let mut matrix = Matrix::new_scale(scale_factor, scale_factor);
|
||||
match rotate {
|
||||
RotateDirection::Deg0 => matrix.rotate(0.0),
|
||||
RotateDirection::Deg90 => matrix.rotate(90.0),
|
||||
RotateDirection::Deg180 => matrix.rotate(180.0),
|
||||
RotateDirection::Deg270 => matrix.rotate(270.0)
|
||||
};
|
||||
let matrix = Matrix::new_scale(scale_factor, scale_factor);
|
||||
|
||||
let mut pixmap = page.to_pixmap(&matrix, &colorspace, false, false)?;
|
||||
if invert {
|
||||
@@ -536,7 +494,6 @@ fn render_single_page_to_ctx(
|
||||
let (x_res, y_res) = pixmap.resolution();
|
||||
let new_x = (x_res as f32 * scale_factor) as i32;
|
||||
let new_y = (y_res as f32 * scale_factor) as i32;
|
||||
|
||||
pixmap.set_resolution(new_x, new_y);
|
||||
|
||||
let result_rects = result_rects
|
||||
|
||||
+9
-25
@@ -9,6 +9,10 @@ use crossterm::{
|
||||
}
|
||||
};
|
||||
use kittage::display::DisplayLocation;
|
||||
use nix::{
|
||||
sys::signal::{Signal::SIGSTOP, kill},
|
||||
unistd::Pid
|
||||
};
|
||||
use ratatui::{
|
||||
Frame,
|
||||
layout::{Constraint, Flex, Layout, Position, Rect},
|
||||
@@ -132,12 +136,6 @@ impl Zoom {
|
||||
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 {
|
||||
@@ -348,6 +346,7 @@ impl Tui {
|
||||
}])
|
||||
}
|
||||
|
||||
// TODO: Make a way to fill the width of the screen with one page and scroll down to view it
|
||||
#[must_use]
|
||||
pub fn render<'s>(
|
||||
&'s mut self,
|
||||
@@ -797,17 +796,10 @@ impl Tui {
|
||||
.unwrap();
|
||||
disable_raw_mode().unwrap();
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
// This process will hang after the SIGSTOP call until we get
|
||||
// foregrounded again by something else, at which point we need to
|
||||
// re-setup everything so that it all gets drawn again.
|
||||
nix::sys::signal::kill(
|
||||
nix::unistd::Pid::this(),
|
||||
nix::sys::signal::Signal::SIGSTOP
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
// This process will hang after the SIGSTOP call until we get
|
||||
// foregrounded again by something else, at which point we need to
|
||||
// re-setup everything so that it all gets drawn again.
|
||||
kill(Pid::this(), SIGSTOP).unwrap();
|
||||
|
||||
enable_raw_mode().unwrap();
|
||||
execute!(
|
||||
@@ -837,9 +829,6 @@ impl Tui {
|
||||
'J' if can_zoom => self.update_zoom(|z| z.pan(Direction::Down)),
|
||||
'K' if can_zoom => self.update_zoom(|z| z.pan(Direction::Up)),
|
||||
'G' if can_zoom => self.update_zoom(Zoom::pan_top),
|
||||
'0' if can_zoom => self.update_zoom(Zoom::pan_left),
|
||||
'$' if can_zoom => self.update_zoom(Zoom::pan_right),
|
||||
'r' => Some(InputAction::Rotate),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
@@ -1109,10 +1098,6 @@ gg/G (when on fill-screen):
|
||||
Scroll to top/bottom of page
|
||||
H, J, K, L (when zoomed in):
|
||||
Pan direction around page
|
||||
0/$ (when on fill-screen):
|
||||
Scroll to left/right side of page
|
||||
r:
|
||||
Rotate by 90 degrees
|
||||
";
|
||||
|
||||
pub enum InputAction {
|
||||
@@ -1121,7 +1106,6 @@ pub enum InputAction {
|
||||
Search(String),
|
||||
QuitApp,
|
||||
Invert,
|
||||
Rotate,
|
||||
Fullscreen,
|
||||
SwitchRenderZoom(crate::FitOrFill)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user