mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-22 07:11:03 +00:00
feat: add config support for coordinate and size adjustment for ueberzugpp image preview (#304)
This commit is contained in:
parent
c9178d4ab3
commit
2df1dae5af
4 changed files with 33 additions and 5 deletions
|
|
@ -21,4 +21,4 @@ ratatui = "^0"
|
|||
tokio = { version = "^1", features = [ "parking_lot", "io-util", "process" ] }
|
||||
|
||||
# Logging
|
||||
tracing = "^0"
|
||||
tracing = { version = "^0", features = [ "max_level_debug", "release_max_level_warn" ] }
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ use std::{path::PathBuf, process::Stdio};
|
|||
use anyhow::Result;
|
||||
use ratatui::prelude::Rect;
|
||||
use tokio::{io::AsyncWriteExt, process::{Child, Command}, sync::mpsc::{self, UnboundedSender}};
|
||||
use tracing::debug;
|
||||
use yazi_config::PREVIEW;
|
||||
|
||||
use crate::Adaptor;
|
||||
|
||||
|
|
@ -42,9 +44,24 @@ impl Ueberzug {
|
|||
)
|
||||
}
|
||||
|
||||
fn adjust_rect(mut rect: Rect) -> Rect {
|
||||
let scale = PREVIEW.ueberzug_scale;
|
||||
let (x, y, w, h) = PREVIEW.ueberzug_offset;
|
||||
|
||||
rect.x = 0f64.max(rect.x as f64 * scale + x) as u16;
|
||||
rect.y = 0f64.max(rect.y as f64 * scale + y) as u16;
|
||||
rect.width = 0f64.max(rect.width as f64 * scale + w) as u16;
|
||||
rect.height = 0f64.max(rect.height as f64 * scale + h) as u16;
|
||||
rect
|
||||
}
|
||||
|
||||
async fn send_command(child: &mut Child, cmd: Option<(PathBuf, Rect)>) -> Result<()> {
|
||||
let stdin = child.stdin.as_mut().unwrap();
|
||||
if let Some((path, rect)) = cmd {
|
||||
debug!("ueberzug rect before adjustment: {:?}", rect);
|
||||
let rect = Self::adjust_rect(rect);
|
||||
debug!("ueberzug rect after adjustment: {:?}", rect);
|
||||
|
||||
let s = format!(
|
||||
r#"{{"action":"add","identifier":"yazi","x":{},"y":{},"max_width":{},"max_height":{},"path":"{}"}}{}"#,
|
||||
rect.x,
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ show_hidden = false
|
|||
show_symlink = true
|
||||
|
||||
[preview]
|
||||
tab_size = 2
|
||||
max_width = 600
|
||||
max_height = 900
|
||||
cache_dir = ""
|
||||
tab_size = 2
|
||||
max_width = 600
|
||||
max_height = 900
|
||||
cache_dir = ""
|
||||
ueberzug_scale = 1
|
||||
ueberzug_offset = [ 0, 0, 0, 0 ]
|
||||
|
||||
[opener]
|
||||
edit = [
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ pub struct Preview {
|
|||
pub max_height: u32,
|
||||
|
||||
pub cache_dir: PathBuf,
|
||||
|
||||
pub ueberzug_scale: f64,
|
||||
pub ueberzug_offset: (f64, f64, f64, f64),
|
||||
}
|
||||
|
||||
impl Default for Preview {
|
||||
|
|
@ -28,6 +31,9 @@ impl Default for Preview {
|
|||
max_height: u32,
|
||||
|
||||
cache_dir: Option<String>,
|
||||
|
||||
ueberzug_scale: f64,
|
||||
ueberzug_offset: (f64, f64, f64, f64),
|
||||
}
|
||||
|
||||
let preview = toml::from_str::<Outer>(&MERGED_YAZI).unwrap().preview;
|
||||
|
|
@ -41,6 +47,9 @@ impl Default for Preview {
|
|||
max_height: preview.max_height,
|
||||
|
||||
cache_dir,
|
||||
|
||||
ueberzug_scale: preview.ueberzug_scale,
|
||||
ueberzug_offset: preview.ueberzug_offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue