Maybe fixed tmux for kitty

This commit is contained in:
itsjunetime
2026-02-08 23:43:56 -06:00
parent 06f737b1fe
commit bd00c7e913
5 changed files with 34 additions and 15 deletions
Generated
+1 -1
View File
@@ -2390,7 +2390,7 @@ dependencies = [
[[package]] [[package]]
name = "ratatui-image" name = "ratatui-image"
version = "10.0.5" version = "10.0.5"
source = "git+https://github.com/itsjunetime/ratatui-image.git?rev=a276a87cb8e2976442c6cc59db831db81551da89#a276a87cb8e2976442c6cc59db831db81551da89" source = "git+https://github.com/itsjunetime/ratatui-image.git?rev=8ad154a219c1e4832a378bd07aaf39b3ddff959b#8ad154a219c1e4832a378bd07aaf39b3ddff959b"
dependencies = [ dependencies = [
"base64-simd", "base64-simd",
"icy_sixel", "icy_sixel",
+1 -1
View File
@@ -26,7 +26,7 @@ name = "tdf"
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", rev = "720ac2d0cad1ac6424364fea74856fec9c100cb1", default-features = false, features = [ "crossterm", "layout-cache" ] }
# ratatui = { path = "./ratatui/ratatui/" } # 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 # 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", rev = "8ad154a219c1e4832a378bd07aaf39b3ddff959b", default-features = false }
# ratatui-image = { path = "./ratatui-image", default-features = false } # ratatui-image = { path = "./ratatui-image", default-features = false }
crossterm = { version = "0.29.0", features = ["event-stream"] } crossterm = { version = "0.29.0", features = ["event-stream"] }
# crossterm = { path = "../crossterm", features = ["event-stream"] } # crossterm = { path = "../crossterm", features = ["event-stream"] }
+22 -8
View File
@@ -15,7 +15,8 @@ use kittage::{
display::{CursorMovementPolicy, DisplayConfig, DisplayLocation}, display::{CursorMovementPolicy, DisplayConfig, DisplayLocation},
error::TransmitError, error::TransmitError,
image::Image, image::Image,
medium::Medium medium::Medium,
tmux::TmuxWriter
}; };
use ratatui::layout::Position; use ratatui::layout::Position;
use smallvec::SmallVec; use smallvec::SmallVec;
@@ -32,7 +33,7 @@ pub struct KittyReadyToDisplay<'tui> {
pub enum KittyDisplay<'tui> { pub enum KittyDisplay<'tui> {
NoChange, NoChange,
ClearImages, ClearImages,
DisplayImages(Vec<KittyReadyToDisplay<'tui>>) DisplayImages(SmallVec<[KittyReadyToDisplay<'tui>; 1]>)
} }
pub struct DbgWriter<W: Write> { pub struct DbgWriter<W: Write> {
@@ -64,6 +65,7 @@ impl<W: Write> Write for DbgWriter<W> {
pub async fn run_action<'es>( pub async fn run_action<'es>(
action: Action<'_, '_>, action: Action<'_, '_>,
is_tmux: bool,
ev_stream: &'es mut EventStream ev_stream: &'es mut EventStream
) -> Result<Option<ImageId>, TransmitError<<&'es mut EventStream as AsyncInputReader>::Error>> { ) -> Result<Option<ImageId>, TransmitError<<&'es mut EventStream as AsyncInputReader>::Error>> {
let writer = DbgWriter { let writer = DbgWriter {
@@ -71,13 +73,21 @@ pub async fn run_action<'es>(
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
buf: String::new() buf: String::new()
}; };
action
.execute_async(writer, ev_stream) if is_tmux {
.await action
.map(|(_, i)| i) .execute_async(TmuxWriter::new(writer), ev_stream)
.await
.map(|(_, i)| i)
} else {
action
.execute_async(writer, ev_stream)
.await
.map(|(_, i)| i)
}
} }
pub async fn do_shms_work(ev_stream: &mut EventStream) -> bool { pub async fn do_shms_work(is_tmux: bool, ev_stream: &mut EventStream) -> bool {
let img = DynamicImage::new_rgb8(1, 1); let img = DynamicImage::new_rgb8(1, 1);
let pid = std::process::id(); let pid = std::process::id();
let shm_name = format!("tdf_test_{pid}"); let shm_name = format!("tdf_test_{pid}");
@@ -94,7 +104,7 @@ pub async fn do_shms_work(ev_stream: &mut EventStream) -> bool {
enable_raw_mode().unwrap(); enable_raw_mode().unwrap();
let res = run_action(Action::Query(&k_img), ev_stream).await; let res = run_action(Action::Query(&k_img), is_tmux, ev_stream).await;
disable_raw_mode().unwrap(); disable_raw_mode().unwrap();
@@ -139,6 +149,7 @@ impl Display for DisplayErrSource<'_> {
pub async fn display_kitty_images<'es>( pub async fn display_kitty_images<'es>(
display: KittyDisplay<'_>, display: KittyDisplay<'_>,
is_tmux: bool,
ev_stream: &'es mut EventStream, ev_stream: &'es mut EventStream,
last_z_index: &mut i32 last_z_index: &mut i32
) -> Result<(), DisplayErr<'es>> { ) -> Result<(), DisplayErr<'es>> {
@@ -150,6 +161,7 @@ pub async fn display_kitty_images<'es>(
effect: ClearOrDelete::Clear, effect: ClearOrDelete::Clear,
which: WhichToDelete::All which: WhichToDelete::All
}), }),
is_tmux,
ev_stream ev_stream
) )
.await .await
@@ -205,6 +217,7 @@ pub async fn display_kitty_images<'es>(
config, config,
placement_id: None placement_id: None
}, },
is_tmux,
ev_stream ev_stream
) )
.await .await
@@ -221,6 +234,7 @@ pub async fn display_kitty_images<'es>(
placement_id: *image_id, placement_id: *image_id,
config config
}, },
is_tmux,
ev_stream ev_stream
) )
.await .await
+6 -2
View File
@@ -298,8 +298,9 @@ async fn inner_main() -> Result<(), WrappedErr> {
let (to_main, from_converter) = flume::unbounded(); let (to_main, from_converter) = flume::unbounded();
let is_kitty = picker.protocol_type() == ProtocolType::Kitty; let is_kitty = picker.protocol_type() == ProtocolType::Kitty;
let is_tmux = picker.is_tmux();
let shms_work = is_kitty && do_shms_work(&mut ev_stream).await; let shms_work = is_kitty && do_shms_work(is_tmux, &mut ev_stream).await;
tokio::spawn(run_conversion_loop( tokio::spawn(run_conversion_loop(
to_main, from_main, picker, 20, shms_work to_main, from_main, picker, 20, shms_work
@@ -329,6 +330,7 @@ async fn inner_main() -> Result<(), WrappedErr> {
effect: ClearOrDelete::Delete, effect: ClearOrDelete::Delete,
which: WhichToDelete::IdRange(NonZeroU32::new(1).unwrap()..=NonZeroU32::MAX) which: WhichToDelete::IdRange(NonZeroU32::new(1).unwrap()..=NonZeroU32::MAX)
}), }),
is_tmux,
&mut ev_stream &mut ev_stream
) )
.await .await
@@ -357,6 +359,7 @@ async fn inner_main() -> Result<(), WrappedErr> {
to_converter, to_converter,
from_converter, from_converter,
fullscreen, fullscreen,
is_tmux,
tui, tui,
&mut term, &mut term,
main_area, main_area,
@@ -385,6 +388,7 @@ async fn enter_redraw_loop(
to_converter: Sender<ConverterMsg>, to_converter: Sender<ConverterMsg>,
mut from_converter: RecvStream<'_, Result<ConvertedPage, RenderError>>, mut from_converter: RecvStream<'_, Result<ConvertedPage, RenderError>>,
mut fullscreen: bool, mut fullscreen: bool,
is_tmux: bool,
mut tui: Tui, mut tui: Tui,
term: &mut Terminal<CrosstermBackend<Stdout>>, term: &mut Terminal<CrosstermBackend<Stdout>>,
mut main_area: tdf::tui::RenderLayout, mut main_area: tdf::tui::RenderLayout,
@@ -465,7 +469,7 @@ async fn enter_redraw_loop(
})?; })?;
let maybe_err = let maybe_err =
display_kitty_images(to_display, &mut ev_stream, &mut kitty_z_idx).await; display_kitty_images(to_display, is_tmux, &mut ev_stream, &mut kitty_z_idx).await;
if let Err(DisplayErr { if let Err(DisplayErr {
failed_pages, failed_pages,
+4 -3
View File
@@ -19,6 +19,7 @@ use ratatui::{
widgets::{Block, Borders, Clear, Padding, Paragraph, Wrap} widgets::{Block, Borders, Clear, Padding, Paragraph, Wrap}
}; };
use ratatui_image::{FontSize, Image}; use ratatui_image::{FontSize, Image};
use smallvec::SmallVec;
use crate::{ use crate::{
FitOrFill, FitOrFill,
@@ -359,7 +360,7 @@ impl Tui {
.cell_pan_from_top .cell_pan_from_top
.min(img_cell_h.saturating_sub(img_section_h.ceil() as u16)); .min(img_cell_h.saturating_sub(img_section_h.ceil() as u16));
KittyDisplay::DisplayImages(vec![KittyReadyToDisplay { KittyDisplay::DisplayImages(SmallVec::from([KittyReadyToDisplay {
img, img,
page_num, page_num,
pos: Position { pos: Position {
@@ -375,7 +376,7 @@ impl Tui {
rows: img_area.height, rows: img_area.height,
..DisplayLocation::default() ..DisplayLocation::default()
} }
}]) }]))
} }
#[must_use] #[must_use]
@@ -517,7 +518,7 @@ impl Tui {
display_loc: DisplayLocation::default() display_loc: DisplayLocation::default()
}) })
}) })
.collect::<Vec<_>>(); .collect::<SmallVec<_>>();
// we want to set this at the very end so it doesn't get set somewhere halfway through and // 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 // then the whole diffing thing messes it up