mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-08-25 20:54:30 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c2117daaf5 |
Generated
+1
-1
@@ -2390,7 +2390,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ratatui-image"
|
||||
version = "10.0.5"
|
||||
source = "git+https://github.com/itsjunetime/ratatui-image.git?rev=8ad154a219c1e4832a378bd07aaf39b3ddff959b#8ad154a219c1e4832a378bd07aaf39b3ddff959b"
|
||||
source = "git+https://github.com/itsjunetime/ratatui-image.git?rev=a276a87cb8e2976442c6cc59db831db81551da89#a276a87cb8e2976442c6cc59db831db81551da89"
|
||||
dependencies = [
|
||||
"base64-simd",
|
||||
"icy_sixel",
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ name = "tdf"
|
||||
ratatui = { git = "https://github.com/itsjunetime/ratatui.git", rev = "720ac2d0cad1ac6424364fea74856fec9c100cb1", default-features = false, features = [ "crossterm", "layout-cache" ] }
|
||||
# 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 = "8ad154a219c1e4832a378bd07aaf39b3ddff959b", default-features = false }
|
||||
ratatui-image = { git = "https://github.com/itsjunetime/ratatui-image.git", rev = "a276a87cb8e2976442c6cc59db831db81551da89", 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"] }
|
||||
|
||||
+1
-1
Submodule ratatui updated: abe7dcf234...720ac2d0ca
+1
-1
Submodule ratatui-image updated: f791e0a99c...8ad154a219
+1
-1
@@ -72,7 +72,7 @@ pub async fn run_conversion_loop(
|
||||
picker: Picker,
|
||||
prerender: usize,
|
||||
shms_work: bool
|
||||
) -> Result<(), SendError<Result<ConvertedPage, RenderError>>> {
|
||||
) -> Result<(), Box<SendError<Result<ConvertedPage, RenderError>>>> {
|
||||
let mut images = vec![];
|
||||
let mut page: usize = 0;
|
||||
let pid = std::process::id();
|
||||
|
||||
+7
-55
@@ -1,8 +1,5 @@
|
||||
use core::fmt::Display;
|
||||
use std::{
|
||||
io::{StdoutLock, Write, stdout},
|
||||
num::NonZeroU32
|
||||
};
|
||||
use std::{io::Write, num::NonZeroU32};
|
||||
|
||||
use crossterm::{
|
||||
cursor::MoveTo,
|
||||
@@ -18,8 +15,7 @@ use kittage::{
|
||||
display::{CursorMovementPolicy, DisplayConfig, DisplayLocation},
|
||||
error::TransmitError,
|
||||
image::Image,
|
||||
medium::Medium,
|
||||
tmux::TmuxWriter
|
||||
medium::Medium
|
||||
};
|
||||
use ratatui::layout::Position;
|
||||
use smallvec::SmallVec;
|
||||
@@ -36,7 +32,7 @@ pub struct KittyReadyToDisplay<'tui> {
|
||||
pub enum KittyDisplay<'tui> {
|
||||
NoChange,
|
||||
ClearImages,
|
||||
DisplayImages(SmallVec<[KittyReadyToDisplay<'tui>; 1]>)
|
||||
DisplayImages(Vec<KittyReadyToDisplay<'tui>>)
|
||||
}
|
||||
|
||||
pub struct DbgWriter<W: Write> {
|
||||
@@ -66,58 +62,22 @@ impl<W: Write> Write for DbgWriter<W> {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MaybeTmuxWriter<W>
|
||||
where
|
||||
W: Write
|
||||
{
|
||||
Tmux(TmuxWriter<W>),
|
||||
Normal(W)
|
||||
}
|
||||
|
||||
impl<W: Write> MaybeTmuxWriter<W> {
|
||||
pub fn new(w: W, is_tmux: bool) -> Self {
|
||||
if is_tmux {
|
||||
Self::Tmux(TmuxWriter::new(w))
|
||||
} else {
|
||||
Self::Normal(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: Write> Write for &mut MaybeTmuxWriter<W> {
|
||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||
match *self {
|
||||
MaybeTmuxWriter::Tmux(t) => t.write(buf),
|
||||
MaybeTmuxWriter::Normal(w) => w.write(buf)
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> std::io::Result<()> {
|
||||
match *self {
|
||||
MaybeTmuxWriter::Tmux(t) => t.flush(),
|
||||
MaybeTmuxWriter::Normal(w) => w.flush()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run_action<'es>(
|
||||
action: Action<'_, '_>,
|
||||
writer: &mut MaybeTmuxWriter<StdoutLock<'_>>,
|
||||
ev_stream: &'es mut EventStream
|
||||
) -> Result<Option<ImageId>, TransmitError<<&'es mut EventStream as AsyncInputReader>::Error>> {
|
||||
let writer = DbgWriter {
|
||||
w: writer,
|
||||
w: std::io::stdout().lock(),
|
||||
#[cfg(debug_assertions)]
|
||||
buf: String::new()
|
||||
};
|
||||
|
||||
action
|
||||
.execute_async(writer, ev_stream)
|
||||
.await
|
||||
.map(|(_, i)| i)
|
||||
}
|
||||
|
||||
pub async fn do_shms_work(is_tmux: bool, ev_stream: &mut EventStream) -> bool {
|
||||
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}");
|
||||
@@ -134,8 +94,7 @@ pub async fn do_shms_work(is_tmux: bool, ev_stream: &mut EventStream) -> bool {
|
||||
|
||||
enable_raw_mode().unwrap();
|
||||
|
||||
let mut writer = MaybeTmuxWriter::new(stdout().lock(), is_tmux);
|
||||
let res = run_action(Action::Query(&k_img), &mut writer, ev_stream).await;
|
||||
let res = run_action(Action::Query(&k_img), ev_stream).await;
|
||||
|
||||
disable_raw_mode().unwrap();
|
||||
|
||||
@@ -180,12 +139,9 @@ impl Display for DisplayErrSource<'_> {
|
||||
|
||||
pub async fn display_kitty_images<'es>(
|
||||
display: KittyDisplay<'_>,
|
||||
is_tmux: bool,
|
||||
ev_stream: &'es mut EventStream,
|
||||
last_z_index: &mut i32
|
||||
) -> Result<(), DisplayErr<'es>> {
|
||||
let mut writer = MaybeTmuxWriter::new(stdout().lock(), is_tmux);
|
||||
|
||||
let images = match display {
|
||||
KittyDisplay::NoChange => return Ok(()),
|
||||
KittyDisplay::ClearImages =>
|
||||
@@ -194,7 +150,6 @@ pub async fn display_kitty_images<'es>(
|
||||
effect: ClearOrDelete::Clear,
|
||||
which: WhichToDelete::All
|
||||
}),
|
||||
&mut writer,
|
||||
ev_stream
|
||||
)
|
||||
.await
|
||||
@@ -221,7 +176,7 @@ pub async fn display_kitty_images<'es>(
|
||||
..DisplayConfig::default()
|
||||
};
|
||||
|
||||
execute!(&mut writer, MoveTo(pos.x, pos.y)).unwrap();
|
||||
execute!(std::io::stdout(), MoveTo(pos.x, pos.y)).unwrap();
|
||||
|
||||
log::debug!("going to display img {img:#?}");
|
||||
log::debug!("displaying with config {config:#?}");
|
||||
@@ -250,7 +205,6 @@ pub async fn display_kitty_images<'es>(
|
||||
config,
|
||||
placement_id: None
|
||||
},
|
||||
&mut writer,
|
||||
ev_stream
|
||||
)
|
||||
.await
|
||||
@@ -267,7 +221,6 @@ pub async fn display_kitty_images<'es>(
|
||||
placement_id: *image_id,
|
||||
config
|
||||
},
|
||||
&mut writer,
|
||||
ev_stream
|
||||
)
|
||||
.await
|
||||
@@ -300,7 +253,6 @@ pub async fn display_kitty_images<'es>(
|
||||
effect: ClearOrDelete::Clear,
|
||||
which: WhichToDelete::PlacementsWithZIndex(z_idxes_to_remove)
|
||||
}),
|
||||
&mut writer,
|
||||
ev_stream
|
||||
)
|
||||
.await
|
||||
|
||||
+24
-38
@@ -1,4 +1,7 @@
|
||||
use core::{error::Error, num::NonZeroUsize};
|
||||
use core::{
|
||||
error::Error,
|
||||
num::{NonZeroU32, NonZeroUsize}
|
||||
};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
ffi::OsString,
|
||||
@@ -13,8 +16,8 @@ use crossterm::{
|
||||
event::EventStream,
|
||||
execute,
|
||||
terminal::{
|
||||
EndSynchronizedUpdate, EnterAlternateScreen, LeaveAlternateScreen, WindowSize,
|
||||
disable_raw_mode, enable_raw_mode, window_size
|
||||
EndSynchronizedUpdate, EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode,
|
||||
enable_raw_mode, window_size
|
||||
}
|
||||
};
|
||||
use debounce::EventDebouncer;
|
||||
@@ -36,8 +39,7 @@ use tdf::{
|
||||
PrerenderLimit,
|
||||
converter::{ConvertedPage, ConverterMsg, run_conversion_loop},
|
||||
kitty::{
|
||||
DisplayErr, DisplayErrSource, KittyDisplay, MaybeTmuxWriter, display_kitty_images,
|
||||
do_shms_work, run_action
|
||||
DisplayErr, DisplayErrSource, KittyDisplay, display_kitty_images, do_shms_work, run_action
|
||||
},
|
||||
renderer::{self, MUPDF_BLACK, MUPDF_WHITE, RenderError, RenderInfo, RenderNotif},
|
||||
tui::{BottomMessage, InputAction, MessageSetting, Tui}
|
||||
@@ -248,20 +250,22 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
// We need to create `picker` on this thread because if we create it on the `renderer` thread,
|
||||
// it messes up something with user input. Input never makes it to the crossterm thing
|
||||
let picker = Picker::from_query_stdio()
|
||||
.or_else(|e| match (e, window_size) {
|
||||
(
|
||||
ratatui_image::errors::Errors::NoFontSize,
|
||||
WindowSize { width: 1.., height: 1.., columns: 1.., rows: 1.. }
|
||||
) => {
|
||||
.or_else(|e| match e {
|
||||
ratatui_image::errors::Errors::NoFontSize if
|
||||
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)))
|
||||
},
|
||||
(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()
|
||||
)),
|
||||
(e, _) => Err(WrappedErr(format!("Couldn't get the necessary information to set up images: {e}").into()))
|
||||
e => Err(WrappedErr(format!("Couldn't get the necessary information to set up images: {e}").into()))
|
||||
})?;
|
||||
|
||||
// then we want to spawn off the rendering task
|
||||
@@ -294,9 +298,8 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
let (to_main, from_converter) = flume::unbounded();
|
||||
|
||||
let is_kitty = picker.protocol_type() == ProtocolType::Kitty;
|
||||
let is_tmux = picker.is_tmux();
|
||||
|
||||
let shms_work = is_kitty && do_shms_work(is_tmux, &mut ev_stream).await;
|
||||
let shms_work = is_kitty && do_shms_work(&mut ev_stream).await;
|
||||
|
||||
tokio::spawn(run_conversion_loop(
|
||||
to_main, from_main, picker, 20, shms_work
|
||||
@@ -321,13 +324,11 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
})?;
|
||||
|
||||
if is_kitty {
|
||||
let mut writer = MaybeTmuxWriter::new(stdout().lock(), is_tmux);
|
||||
run_action(
|
||||
Action::Delete(DeleteConfig {
|
||||
effect: ClearOrDelete::Delete,
|
||||
which: WhichToDelete::All
|
||||
which: WhichToDelete::IdRange(NonZeroU32::new(1).unwrap()..=NonZeroU32::MAX)
|
||||
}),
|
||||
&mut writer,
|
||||
&mut ev_stream
|
||||
)
|
||||
.await
|
||||
@@ -349,14 +350,13 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
let tui_rx = tui_rx.into_stream();
|
||||
let from_converter = from_converter.into_stream();
|
||||
|
||||
let res = enter_redraw_loop(
|
||||
&mut ev_stream,
|
||||
enter_redraw_loop(
|
||||
ev_stream,
|
||||
to_renderer,
|
||||
tui_rx,
|
||||
to_converter,
|
||||
from_converter,
|
||||
fullscreen,
|
||||
is_tmux,
|
||||
tui,
|
||||
&mut term,
|
||||
main_area,
|
||||
@@ -370,35 +370,21 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
||||
)
|
||||
.into()
|
||||
)
|
||||
});
|
||||
})?;
|
||||
|
||||
if is_kitty {
|
||||
let mut writer = MaybeTmuxWriter::new(stdout().lock(), is_tmux);
|
||||
_ = run_action(
|
||||
Action::Delete(DeleteConfig {
|
||||
effect: ClearOrDelete::Delete,
|
||||
which: WhichToDelete::All
|
||||
}),
|
||||
&mut writer,
|
||||
&mut ev_stream
|
||||
)
|
||||
.await;
|
||||
}
|
||||
drop(maybe_logger);
|
||||
|
||||
res
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// oh shut up clippy who cares
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
async fn enter_redraw_loop(
|
||||
ev_stream: &mut EventStream,
|
||||
mut ev_stream: EventStream,
|
||||
to_renderer: Sender<RenderNotif>,
|
||||
mut tui_rx: RecvStream<'_, Result<RenderInfo, RenderError>>,
|
||||
to_converter: Sender<ConverterMsg>,
|
||||
mut from_converter: RecvStream<'_, Result<ConvertedPage, RenderError>>,
|
||||
mut fullscreen: bool,
|
||||
is_tmux: bool,
|
||||
mut tui: Tui,
|
||||
term: &mut Terminal<CrosstermBackend<Stdout>>,
|
||||
mut main_area: tdf::tui::RenderLayout,
|
||||
@@ -479,7 +465,7 @@ async fn enter_redraw_loop(
|
||||
})?;
|
||||
|
||||
let maybe_err =
|
||||
display_kitty_images(to_display, is_tmux, ev_stream, &mut kitty_z_idx).await;
|
||||
display_kitty_images(to_display, &mut ev_stream, &mut kitty_z_idx).await;
|
||||
|
||||
if let Err(DisplayErr {
|
||||
failed_pages,
|
||||
|
||||
+11
-12
@@ -19,7 +19,6 @@ use ratatui::{
|
||||
widgets::{Block, Borders, Clear, Padding, Paragraph, Wrap}
|
||||
};
|
||||
use ratatui_image::{FontSize, Image};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
FitOrFill,
|
||||
@@ -360,7 +359,7 @@ impl Tui {
|
||||
.cell_pan_from_top
|
||||
.min(img_cell_h.saturating_sub(img_section_h.ceil() as u16));
|
||||
|
||||
KittyDisplay::DisplayImages(SmallVec::from([KittyReadyToDisplay {
|
||||
KittyDisplay::DisplayImages(vec![KittyReadyToDisplay {
|
||||
img,
|
||||
page_num,
|
||||
pos: Position {
|
||||
@@ -376,7 +375,7 @@ impl Tui {
|
||||
rows: img_area.height,
|
||||
..DisplayLocation::default()
|
||||
}
|
||||
}]))
|
||||
}])
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -518,7 +517,7 @@ impl Tui {
|
||||
display_loc: DisplayLocation::default()
|
||||
})
|
||||
})
|
||||
.collect::<SmallVec<_>>();
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// we want to set this at the very end so it doesn't get set somewhere halfway through and
|
||||
// then the whole diffing thing messes it up
|
||||
@@ -740,19 +739,19 @@ impl Tui {
|
||||
InputAction::Redraw.into()
|
||||
}
|
||||
KeyCode::Char(c)
|
||||
if let BottomMessage::Input(InputCommand::GoToPage(ref mut page)) =
|
||||
self.bottom_msg && matches!(c, 'g' if self.is_kitty) =>
|
||||
c.to_digit(10).map(|input_num| {
|
||||
*page = (*page * 10) + input_num as usize;
|
||||
InputAction::Redraw
|
||||
}),
|
||||
KeyCode::Char(_)
|
||||
if let BottomMessage::Input(InputCommand::GoToPage(_)) =
|
||||
self.bottom_msg =>
|
||||
self.bottom_msg && matches!(c, 'g' if self.is_kitty) =>
|
||||
{
|
||||
self.set_msg(MessageSetting::Pop);
|
||||
self.update_zoom(Zoom::pan_bottom)
|
||||
}
|
||||
KeyCode::Char(c)
|
||||
if let BottomMessage::Input(InputCommand::GoToPage(ref mut page)) =
|
||||
self.bottom_msg =>
|
||||
c.to_digit(10).map(|input_num| {
|
||||
*page = (*page * 10) + input_num as usize;
|
||||
InputAction::Redraw
|
||||
}),
|
||||
KeyCode::Char(c) => match c {
|
||||
'l' => self.change_page(PageChange::Next, ChangeAmount::Single),
|
||||
'j' => self.change_page(PageChange::Next, ChangeAmount::WholeScreen),
|
||||
|
||||
Reference in New Issue
Block a user