mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-27 08:04:29 -04:00
Use upstream versions of ratatui crates
This commit is contained in:
+6
-8
@@ -8,7 +8,7 @@ use flume::{Receiver, SendError, Sender, TryRecvError};
|
||||
use futures_util::stream::StreamExt as _;
|
||||
use image::{DynamicImage, codecs::pnm::PnmDecoder};
|
||||
use kittage::NumberOrId;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::prelude::Size;
|
||||
use ratatui_image::{
|
||||
Resize,
|
||||
picker::{Picker, ProtocolType},
|
||||
@@ -27,7 +27,7 @@ pub enum MaybeTransferred {
|
||||
Transferred(kittage::ImageId)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
// #[derive(Debug)]
|
||||
pub enum ConvertedImage {
|
||||
Generic(Protocol),
|
||||
Kitty {
|
||||
@@ -42,8 +42,8 @@ impl ConvertedImage {
|
||||
pub fn w_h(&self) -> (u16, u16) {
|
||||
match self {
|
||||
Self::Generic(prot) => {
|
||||
let a = prot.area();
|
||||
(a.width, a.height)
|
||||
let Size { width, height } = prot.size();
|
||||
(width, height)
|
||||
}
|
||||
Self::Kitty {
|
||||
img: _,
|
||||
@@ -134,11 +134,9 @@ pub async fn run_conversion_loop(
|
||||
.for_each(|(_, _, px)| px.0[2] = px.0[2].saturating_sub(u8::MAX / 2));
|
||||
}
|
||||
|
||||
let img_area = Rect {
|
||||
let img_size = Size {
|
||||
width: page_info.img_data.cell_w,
|
||||
height: page_info.img_data.cell_h,
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
let dyn_img = DynamicImage::ImageRgb8(dyn_img);
|
||||
@@ -174,7 +172,7 @@ pub async fn run_conversion_loop(
|
||||
}
|
||||
_ => ConvertedImage::Generic(
|
||||
picker
|
||||
.new_protocol(dyn_img, img_area, Resize::None)
|
||||
.new_protocol(dyn_img, img_size, Resize::Crop(None))
|
||||
.map_err(|e| {
|
||||
RenderError::Converting(format!(
|
||||
"Couldn't convert DynamicImage to ratatui image: {e}"
|
||||
|
||||
+2
-2
@@ -260,7 +260,7 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
// 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)))
|
||||
Ok(Picker::from_fontsize(FontSize { width: cell_width_px, height: 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()
|
||||
@@ -315,7 +315,7 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
let mut term = Terminal::new(backend).map_err(|e| {
|
||||
WrappedErr(format!("Couldn't set up crossterm's terminal backend: {e}").into())
|
||||
})?;
|
||||
term.skip_diff(true);
|
||||
// term.skip_diff(true);
|
||||
|
||||
enable_raw_mode().map_err(|e| {
|
||||
WrappedErr(
|
||||
|
||||
+3
-12
@@ -1,23 +1,14 @@
|
||||
use std::num::NonZeroUsize;
|
||||
|
||||
use ratatui::widgets::Widget;
|
||||
use ratatui::{prelude::buffer::CellDiffOption, widgets::Widget};
|
||||
|
||||
pub struct Skip {
|
||||
skip: bool
|
||||
}
|
||||
|
||||
impl Skip {
|
||||
#[must_use]
|
||||
pub fn new(skip: bool) -> Self {
|
||||
Self { skip }
|
||||
}
|
||||
}
|
||||
pub struct Skip;
|
||||
|
||||
impl Widget for Skip {
|
||||
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) {
|
||||
for x in area.x..(area.x + area.width) {
|
||||
for y in area.y..(area.y + area.height) {
|
||||
buf[(x, y)].skip = self.skip;
|
||||
buf[(x, y)].diff_option = CellDiffOption::Skip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -349,8 +349,8 @@ impl Tui {
|
||||
}
|
||||
}
|
||||
|
||||
let width = (img_section_w * f32::from(font_size.0)) as u32;
|
||||
let height = (img_section_h * f32::from(font_size.1)) as u32;
|
||||
let width = (img_section_w * f32::from(font_size.width)) as u32;
|
||||
let height = (img_section_h * f32::from(font_size.height)) as u32;
|
||||
|
||||
zoom.cell_pan_from_left = zoom
|
||||
.cell_pan_from_left
|
||||
@@ -367,8 +367,8 @@ impl Tui {
|
||||
y: img_area.y
|
||||
},
|
||||
display_loc: DisplayLocation {
|
||||
x: u32::from(zoom.cell_pan_from_left) * u32::from(font_size.0),
|
||||
y: u32::from(zoom.cell_pan_from_top) * u32::from(font_size.1),
|
||||
x: u32::from(zoom.cell_pan_from_left) * u32::from(font_size.width),
|
||||
y: u32::from(zoom.cell_pan_from_top) * u32::from(font_size.height),
|
||||
width,
|
||||
height,
|
||||
columns: img_area.width,
|
||||
@@ -409,7 +409,7 @@ impl Tui {
|
||||
// resize this time), then go through every element in the buffer where any Image would
|
||||
// be written and set to skip it so that ratatui doesn't spend a lot of time diffing it
|
||||
// each re-render
|
||||
frame.render_widget(Skip::new(true), img_area);
|
||||
frame.render_widget(Skip, img_area);
|
||||
return KittyDisplay::NoChange;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user