mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
151f91f58e
commit
5d76177f32
11 changed files with 32 additions and 32 deletions
|
|
@ -4,7 +4,7 @@ sort_reverse = true
|
|||
show_hidden = false
|
||||
|
||||
[preview]
|
||||
adapter = "kitty"
|
||||
adaptor = "kitty"
|
||||
tab_size = 2
|
||||
max_width = 600
|
||||
max_height = 900
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@ use serde::Deserialize;
|
|||
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(try_from = "String")]
|
||||
pub enum PreviewAdapter {
|
||||
pub enum PreviewAdaptor {
|
||||
Kitty,
|
||||
Ueberzug,
|
||||
}
|
||||
|
||||
impl TryFrom<String> for PreviewAdapter {
|
||||
impl TryFrom<String> for PreviewAdaptor {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
Ok(match value.to_lowercase().as_str() {
|
||||
"kitty" => Self::Kitty,
|
||||
"ueberzug" => Self::Ueberzug,
|
||||
_ => bail!("invalid preview adapter: {}", value),
|
||||
_ => bail!("invalid preview adaptor: {}", value),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
mod adapter;
|
||||
mod adaptor;
|
||||
mod preview;
|
||||
|
||||
pub use adapter::*;
|
||||
pub use adaptor::*;
|
||||
pub use preview::*;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use super::PreviewAdapter;
|
||||
use super::PreviewAdaptor;
|
||||
use crate::config::MERGED_YAZI;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Preview {
|
||||
pub adapter: PreviewAdapter,
|
||||
pub adaptor: PreviewAdaptor,
|
||||
pub tab_size: u32,
|
||||
|
||||
pub max_width: u32,
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
mod adapter;
|
||||
mod kitty;
|
||||
mod ueberzug;
|
||||
|
||||
pub use adapter::*;
|
||||
|
|
@ -5,27 +5,27 @@ use ratatui::prelude::Rect;
|
|||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use super::{kitty::Kitty, ueberzug::Ueberzug};
|
||||
use crate::config::{preview::PreviewAdapter, PREVIEW};
|
||||
use crate::config::{preview::PreviewAdaptor, PREVIEW};
|
||||
|
||||
pub struct Adapter {
|
||||
pub struct Adaptor {
|
||||
ueberzug: Option<UnboundedSender<Option<(PathBuf, Rect)>>>,
|
||||
}
|
||||
|
||||
impl Adapter {
|
||||
impl Adaptor {
|
||||
pub fn new() -> Self {
|
||||
let mut adapter = Self { ueberzug: None };
|
||||
let mut adaptor = Self { ueberzug: None };
|
||||
|
||||
if PREVIEW.adapter == PreviewAdapter::Ueberzug {
|
||||
adapter.ueberzug = Ueberzug::init().ok();
|
||||
if PREVIEW.adaptor == PreviewAdaptor::Ueberzug {
|
||||
adaptor.ueberzug = Ueberzug::init().ok();
|
||||
}
|
||||
|
||||
adapter
|
||||
adaptor
|
||||
}
|
||||
|
||||
pub async fn image_show(&self, path: &Path, rect: Rect) -> Result<()> {
|
||||
match PREVIEW.adapter {
|
||||
PreviewAdapter::Kitty => Kitty::image_show(path, rect).await,
|
||||
PreviewAdapter::Ueberzug => {
|
||||
match PREVIEW.adaptor {
|
||||
PreviewAdaptor::Kitty => Kitty::image_show(path, rect).await,
|
||||
PreviewAdaptor::Ueberzug => {
|
||||
if let Some(tx) = &self.ueberzug {
|
||||
tx.send(Some((path.to_path_buf(), rect))).ok();
|
||||
}
|
||||
|
|
@ -35,9 +35,9 @@ impl Adapter {
|
|||
}
|
||||
|
||||
pub fn image_hide(&self) {
|
||||
match PREVIEW.adapter {
|
||||
PreviewAdapter::Kitty => Kitty::image_hide(),
|
||||
PreviewAdapter::Ueberzug => {
|
||||
match PREVIEW.adaptor {
|
||||
PreviewAdaptor::Kitty => Kitty::image_hide(),
|
||||
PreviewAdaptor::Ueberzug => {
|
||||
if let Some(tx) = &self.ueberzug {
|
||||
tx.send(None).ok();
|
||||
}
|
||||
5
src/core/adaptor/mod.rs
Normal file
5
src/core/adaptor/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
mod adaptor;
|
||||
mod kitty;
|
||||
mod ueberzug;
|
||||
|
||||
pub use adaptor::*;
|
||||
|
|
@ -6,7 +6,7 @@ use syntect::{easy::HighlightFile, highlighting::{Theme, ThemeSet}, parsing::Syn
|
|||
use tokio::{fs, task::JoinHandle};
|
||||
|
||||
use super::{ALL_RATIO, PREVIEW_BORDER, PREVIEW_PADDING, PREVIEW_RATIO};
|
||||
use crate::{config::{PREVIEW, THEME}, core::{adapter::Adapter, external, files::{Files, FilesOp}, tasks::Precache}, emit, misc::{tty_size, MimeKind}};
|
||||
use crate::{config::{PREVIEW, THEME}, core::{adaptor::Adaptor, external, files::{Files, FilesOp}, tasks::Precache}, emit, misc::{tty_size, MimeKind}};
|
||||
|
||||
static SYNTECT_SYNTAX: OnceLock<SyntaxSet> = OnceLock::new();
|
||||
static SYNTECT_THEME: OnceLock<Theme> = OnceLock::new();
|
||||
|
|
@ -16,7 +16,7 @@ pub struct Preview {
|
|||
pub data: PreviewData,
|
||||
|
||||
handle: Option<JoinHandle<()>>,
|
||||
adaptor: Arc<Adapter>,
|
||||
adaptor: Arc<Adaptor>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
|
@ -33,7 +33,7 @@ impl Preview {
|
|||
path: Default::default(),
|
||||
data: Default::default(),
|
||||
handle: Default::default(),
|
||||
adaptor: Arc::new(Adapter::new()),
|
||||
adaptor: Arc::new(Adaptor::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ impl Preview {
|
|||
Ok(PreviewData::Folder)
|
||||
}
|
||||
|
||||
pub async fn image(adaptor: Arc<Adapter>, mut path: &Path) -> Result<PreviewData> {
|
||||
pub async fn image(adaptor: Arc<Adaptor>, mut path: &Path) -> Result<PreviewData> {
|
||||
let cache = Precache::cache(path);
|
||||
if fs::metadata(&cache).await.is_ok() {
|
||||
path = cache.as_path();
|
||||
|
|
@ -100,7 +100,7 @@ impl Preview {
|
|||
Ok(PreviewData::None)
|
||||
}
|
||||
|
||||
pub async fn video(adaptor: Arc<Adapter>, path: &Path) -> Result<PreviewData> {
|
||||
pub async fn video(adaptor: Arc<Adaptor>, path: &Path) -> Result<PreviewData> {
|
||||
let cache = Precache::cache(path);
|
||||
if fs::metadata(&cache).await.is_err() {
|
||||
external::ffmpegthumbnailer(path, &cache).await?;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
pub mod adapter;
|
||||
pub mod adaptor;
|
||||
mod blocker;
|
||||
mod event;
|
||||
pub mod external;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue