mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
0d5a5d1212
commit
876a906bed
3 changed files with 27 additions and 9 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::{
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use config::{preview::PreviewAdaptor, BOOT, PREVIEW};
|
use config::{preview::PreviewAdaptor, BOOT, PREVIEW};
|
||||||
|
|
@ -9,6 +12,8 @@ use tokio::{fs, sync::mpsc::UnboundedSender};
|
||||||
use super::{Iterm2, Kitty};
|
use super::{Iterm2, Kitty};
|
||||||
use crate::Sixel;
|
use crate::Sixel;
|
||||||
|
|
||||||
|
static IMAGE_SHOWN: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub(super) static UEBERZUG: RoCell<Option<UnboundedSender<Option<(PathBuf, Rect)>>>> =
|
pub(super) static UEBERZUG: RoCell<Option<UnboundedSender<Option<(PathBuf, Rect)>>>> =
|
||||||
RoCell::new();
|
RoCell::new();
|
||||||
|
|
@ -29,11 +34,15 @@ impl Adaptor {
|
||||||
_ => Ok(if let Some(tx) = &*UEBERZUG {
|
_ => Ok(if let Some(tx) = &*UEBERZUG {
|
||||||
tx.send(Some((path.to_path_buf(), rect)))?;
|
tx.send(Some((path.to_path_buf(), rect)))?;
|
||||||
}),
|
}),
|
||||||
}
|
}?;
|
||||||
|
|
||||||
|
Ok(IMAGE_SHOWN.store(true, Ordering::Relaxed))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn image_hide(rect: Rect) -> Result<()> {
|
pub fn image_hide(rect: Rect) -> Result<()> {
|
||||||
|
if !IMAGE_SHOWN.swap(false, Ordering::Relaxed) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
match PREVIEW.adaptor {
|
match PREVIEW.adaptor {
|
||||||
PreviewAdaptor::Kitty => Kitty::image_hide(),
|
PreviewAdaptor::Kitty => Kitty::image_hide(),
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ impl Kitty {
|
||||||
if let Some(first) = it.next() {
|
if let Some(first) = it.next() {
|
||||||
write!(
|
write!(
|
||||||
buf,
|
buf,
|
||||||
"\x1b\\\x1b_Ga=d\x1b\\\x1b_Ga=T,f={},s={},v={},m={};{}\x1b\\",
|
"\x1b_Ga=T,f={},s={},v={},m={};{}\x1b\\",
|
||||||
format,
|
format,
|
||||||
size.0,
|
size.0,
|
||||||
size.1,
|
size.1,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
use std::io::{stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
|
|
||||||
use anyhow::Result;
|
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;
|
use crate::Term;
|
||||||
|
|
||||||
|
|
@ -24,9 +28,10 @@ impl Term {
|
||||||
{
|
{
|
||||||
#[cfg(target_os = "windows")]
|
#[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);
|
let result = cb(&mut stdout);
|
||||||
queue!(&mut stdout, cursor::Hide, RestorePosition)?;
|
queue!(&mut stdout, Hide, RestorePosition)?;
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
@ -41,8 +46,12 @@ impl Term {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_cursor_block() -> Result<()> { Ok(execute!(stdout(), SetCursorStyle::BlinkingBlock)?) }
|
pub fn set_cursor_block() -> Result<()> {
|
||||||
|
Ok(execute!(stdout(), SetCursorStyle::BlinkingBlock)?)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_cursor_bar() -> Result<()> { Ok(execute!(stdout(), SetCursorStyle::BlinkingBar)?) }
|
pub fn set_cursor_bar() -> Result<()> {
|
||||||
|
Ok(execute!(stdout(), SetCursorStyle::BlinkingBar)?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue