mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-01 23:51:46 -04:00
- Run fmt
- Use built-in async benching - Use custom Resize::None when making ratatui images to save some cycles
This commit is contained in:
+2
-2
@@ -1,8 +1,8 @@
|
||||
use flume::{Receiver, SendError, Sender, TryRecvError};
|
||||
use futures_util::stream::StreamExt;
|
||||
use image::ImageFormat;
|
||||
use itertools::Itertools;
|
||||
use ratatui_image::{picker::Picker, protocol::Protocol, Resize};
|
||||
use futures_util::stream::StreamExt;
|
||||
|
||||
use crate::renderer::{fill_default, PageInfo, RenderError};
|
||||
|
||||
@@ -67,7 +67,7 @@ pub async fn run_conversion_loop(
|
||||
// size for the area given, so to save ratatui the work of having to
|
||||
// resize it, we tell them to crop it to fit.
|
||||
let txt_img = picker
|
||||
.new_protocol(dyn_img, img_area, Resize::Crop)
|
||||
.new_protocol(dyn_img, img_area, Resize::None)
|
||||
.map_err(|e| {
|
||||
RenderError::Render(format!(
|
||||
"Couldn't convert DynamicImage to ratatui image: {e}"
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#![feature(if_let_guard)]
|
||||
|
||||
pub mod renderer;
|
||||
pub mod converter;
|
||||
pub mod tui;
|
||||
pub mod renderer;
|
||||
pub mod skip;
|
||||
pub mod tui;
|
||||
|
||||
+3
-1
@@ -44,7 +44,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
#[cfg(feature = "tracing")]
|
||||
console_subscriber::init();
|
||||
|
||||
let file = std::env::args().nth(1).ok_or("Program requires a file to process")?;
|
||||
let file = std::env::args()
|
||||
.nth(1)
|
||||
.ok_or("Program requires a file to process")?;
|
||||
let path = PathBuf::from_str(&file)?.canonicalize()?;
|
||||
|
||||
//let (watch_tx, render_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
|
||||
+9
-10
@@ -198,11 +198,10 @@ pub fn start_rendering(
|
||||
// We know this is in range 'cause we're iterating over it but we still just want
|
||||
// to be safe
|
||||
let Some(page) = doc.page(num as i32) else {
|
||||
sender
|
||||
.send(Err(RenderError::Render(format!(
|
||||
"Couldn't get page {num} ({}) of doc?",
|
||||
num as i32
|
||||
))))?;
|
||||
sender.send(Err(RenderError::Render(format!(
|
||||
"Couldn't get page {num} ({}) of doc?",
|
||||
num as i32
|
||||
))))?;
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -242,7 +241,7 @@ pub fn start_rendering(
|
||||
render_ctx_to_png(ctx, &mut sender, (col_w, col_h), num)
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
// And if we got an error, then obviously we need to propagate that
|
||||
Err(e) => sender.send(Err(RenderError::Render(e)))?
|
||||
}
|
||||
@@ -285,7 +284,7 @@ fn render_single_page_to_ctx(
|
||||
page: Page,
|
||||
search_term: &Option<String>,
|
||||
already_rendered_no_results: bool,
|
||||
(area_w, area_h): (f64, f64),
|
||||
(area_w, area_h): (f64, f64)
|
||||
) -> Result<Option<RenderedContext>, String> {
|
||||
let mut result_rects = search_term
|
||||
.as_ref()
|
||||
@@ -393,9 +392,9 @@ fn render_ctx_to_png(
|
||||
let mut img_data = Vec::with_capacity((ctx.surface_height * ctx.surface_width) as usize);
|
||||
|
||||
match ctx.surface.write_to_png(&mut img_data) {
|
||||
Err(e) => sender.send(Err(RenderError::Render(
|
||||
format!("Couldn't write surface to png: {e}")
|
||||
))),
|
||||
Err(e) => sender.send(Err(RenderError::Render(format!(
|
||||
"Couldn't write surface to png: {e}"
|
||||
)))),
|
||||
Ok(()) => sender.send(Ok(RenderInfo::Page(PageInfo {
|
||||
img_data: ImageData {
|
||||
data: img_data,
|
||||
|
||||
Reference in New Issue
Block a user