diff --git a/adaptor/src/adaptor.rs b/adaptor/src/adaptor.rs index b5b86b99..7708667e 100644 --- a/adaptor/src/adaptor.rs +++ b/adaptor/src/adaptor.rs @@ -1,4 +1,7 @@ -use std::path::{Path, PathBuf}; +use std::{ + path::{Path, PathBuf}, + sync::atomic::{AtomicBool, Ordering}, +}; use anyhow::Result; use config::{preview::PreviewAdaptor, BOOT, PREVIEW}; @@ -9,6 +12,8 @@ use tokio::{fs, sync::mpsc::UnboundedSender}; use super::{Iterm2, Kitty}; use crate::Sixel; +static IMAGE_SHOWN: AtomicBool = AtomicBool::new(false); + #[allow(clippy::type_complexity)] pub(super) static UEBERZUG: RoCell>>> = RoCell::new(); @@ -29,11 +34,15 @@ impl Adaptor { _ => Ok(if let Some(tx) = &*UEBERZUG { tx.send(Some((path.to_path_buf(), rect)))?; }), - } + }?; + + Ok(IMAGE_SHOWN.store(true, Ordering::Relaxed)) } pub fn image_hide(rect: Rect) -> Result<()> { - return Ok(()); + if !IMAGE_SHOWN.swap(false, Ordering::Relaxed) { + return Ok(()); + } match PREVIEW.adaptor { PreviewAdaptor::Kitty => Kitty::image_hide(), diff --git a/adaptor/src/kitty.rs b/adaptor/src/kitty.rs index ea0913f3..7a1a0fc4 100644 --- a/adaptor/src/kitty.rs +++ b/adaptor/src/kitty.rs @@ -36,7 +36,7 @@ impl Kitty { if let Some(first) = it.next() { write!( buf, - "\x1b\\\x1b_Ga=d\x1b\\\x1b_Ga=T,f={},s={},v={},m={};{}\x1b\\", + "\x1b_Ga=T,f={},s={},v={},m={};{}\x1b\\", format, size.0, size.1, diff --git a/shared/src/term/cursor.rs b/shared/src/term/cursor.rs index f4ac5b2f..6d302afe 100644 --- a/shared/src/term/cursor.rs +++ b/shared/src/term/cursor.rs @@ -1,7 +1,11 @@ use std::io::{stdout, Write}; use anyhow::Result; -use crossterm::{cursor::{MoveTo, RestorePosition, SavePosition, SetCursorStyle}, execute, queue, terminal::{Clear, ClearType}}; +use crossterm::{ + cursor::{MoveTo, RestorePosition, SavePosition, SetCursorStyle}, + execute, queue, + terminal::{Clear, ClearType}, +}; use crate::Term; @@ -24,9 +28,10 @@ impl Term { { #[cfg(target_os = "windows")] { - queue!(&mut stdout, SavePosition, MoveTo(x, y), cursor::Show)?; + use crossterm::cursor::{Hide, Show}; + queue!(&mut stdout, SavePosition, MoveTo(x, y), Show)?; let result = cb(&mut stdout); - queue!(&mut stdout, cursor::Hide, RestorePosition)?; + queue!(&mut stdout, Hide, RestorePosition)?; stdout.flush()?; result } @@ -41,8 +46,12 @@ impl Term { } #[inline] - pub fn set_cursor_block() -> Result<()> { Ok(execute!(stdout(), SetCursorStyle::BlinkingBlock)?) } + pub fn set_cursor_block() -> Result<()> { + Ok(execute!(stdout(), SetCursorStyle::BlinkingBlock)?) + } #[inline] - pub fn set_cursor_bar() -> Result<()> { Ok(execute!(stdout(), SetCursorStyle::BlinkingBar)?) } + pub fn set_cursor_bar() -> Result<()> { + Ok(execute!(stdout(), SetCursorStyle::BlinkingBar)?) + } }