Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ kittage = { version = "0.1.1", features = ["crossterm-tokio", "image-crate", "lo
memmap2 = "0"
csscolorparser = { version = "0.8.0", default-features = false }
debounce = "0.2.2"
open = "5.1"

# logging
log = "0.4.27"
Expand All @@ -71,10 +72,6 @@ cpuprofiler = "0.0.4"
name = "rendering"
harness = false

[[bin]]
name = "for_profiling"
path = "./benches/for_profiling.rs"

[lints.clippy]
alloc_instead_of_core = "warn"
allow_attributes = "warn"
Expand Down Expand Up @@ -107,7 +104,7 @@ doc_link_code = "warn"
doc_link_with_quotes = "warn"
elidable_lifetime_names = "warn"
empty_drop = "warn"
empty_enums = "warn"
empty_enum = "warn"
empty_enum_variants_with_brackets = "warn"
empty_structs_with_brackets = "warn"
equatable_if_let = "warn"
Expand Down
12 changes: 8 additions & 4 deletions src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,14 @@ pub async fn run_conversion_loop(
.as_nanos() % 1_000_000;

let mut img = if shms_work {
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:?}"))
})?
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:?}"))
})?
} else {
kittage::image::Image::from(dyn_img)
};
Expand Down
7 changes: 6 additions & 1 deletion src/kitty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ 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 Ok(mut k_img) = kittage::image::Image::shm_from(img, &format!("tdf_test_{pid}")) else {
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 {
return false;
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 aspec ratio of the page with the aspect ratio of the
// we do this first by comparing the aspect 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
Expand Down
69 changes: 63 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, MUPDF_BLACK, MUPDF_WHITE, RenderError, RenderInfo, RenderNotif},
renderer::{self, LinkTarget, MUPDF_BLACK, MUPDF_WHITE, RenderError, RenderInfo, RenderNotif},
tui::{BottomMessage, InputAction, MessageSetting, Tui}
};

Expand Down Expand Up @@ -70,11 +70,18 @@ fn reset_term() {
);
}

#[tokio::main]
async fn main() -> Result<(), WrappedErr> {
let result = inner_main().await;
reset_term();
result
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
})
}

async fn inner_main() -> Result<(), WrappedErr> {
Expand Down Expand Up @@ -381,6 +388,9 @@ async fn enter_redraw_loop(
mut main_area: tdf::tui::RenderLayout,
font_size: FontSize
) -> Result<(), Box<dyn Error>> {
let (link_tx, link_rx) = flume::unbounded();
let mut link_rx = link_rx.into_stream();

loop {
let mut needs_redraw = true;
let next_ev = ev_stream.next().fuse();
Expand All @@ -401,10 +411,30 @@ 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();
}
InputAction::Click { col, row } => {
if let Some((page_num, mupdf_x, mupdf_y, mupdf_w, mupdf_h)) = tui.map_click_to_page(col, row, &main_area, font_size) {
let link_tx = link_tx.clone();
let (resp_tx, resp_rx) = flume::bounded(1);
to_renderer.send(RenderNotif::QueryLinkAt {
page: page_num,
mupdf_x_px: mupdf_x,
mupdf_y_px: mupdf_y,
mupdf_w_px: mupdf_w,
mupdf_h_px: mupdf_h,
resp: resp_tx
})?;
tokio::spawn(async move {
if let Ok(res) = resp_rx.recv_async().await {
let _ = link_tx.send_async(res).await;
}
});
}
}
}
}
},
Expand Down Expand Up @@ -437,6 +467,33 @@ async fn enter_redraw_loop(
Err(e) => tui.show_error(e),
}
},
Some(link_res) = link_rx.next() => {
match link_res {
Ok(Some(LinkTarget::Uri(uri))) => {
let mut clean_uri = uri.as_str();
if clean_uri.starts_with("file:") {
clean_uri = &clean_uri["file:".len()..];
if let Some((base, _)) = clean_uri.split_once('#') {
clean_uri = base;
}
}
if let Err(e) = open::that(clean_uri) {
tui.set_msg(MessageSetting::Some(BottomMessage::Error(
format!("Failed to open uri {clean_uri}: {e}")
)));
}
}
Ok(Some(LinkTarget::GoTo { page_index })) => {
tui.set_page(page_index);
to_renderer.send(RenderNotif::JumpToPage(page_index)).unwrap();
to_converter.send(ConverterMsg::GoToPage(page_index)).unwrap();
}
Ok(None) => {}
Err(err_str) => {
tui.set_msg(MessageSetting::Some(BottomMessage::Error(err_str)));
}
}
},
};

let new_area = Tui::main_layout(&term.get_frame(), fullscreen);
Expand Down
Loading