mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Simplify
This commit is contained in:
parent
45081eeaec
commit
03bc86f46f
3 changed files with 25 additions and 29 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{cmp::max, path::PathBuf, process::Stdio};
|
||||
use std::{path::PathBuf, process::Stdio};
|
||||
|
||||
use anyhow::Result;
|
||||
use ratatui::prelude::Rect;
|
||||
|
|
@ -33,17 +33,6 @@ impl Ueberzug {
|
|||
Ok(tx)
|
||||
}
|
||||
|
||||
fn adjust_rect(mut rect: Rect) -> Rect {
|
||||
let cfg = &PREVIEW.ueberzug;
|
||||
rect.x = max((rect.x as f64 / cfg.scale_down_factor + cfg.x_offset) as i32, 0) as u16;
|
||||
rect.y = max((rect.y as f64 / cfg.scale_down_factor + cfg.y_offset) as i32, 0) as u16;
|
||||
rect.width =
|
||||
max((rect.width as f64 / cfg.scale_down_factor + cfg.width_offset) as i32, 0) as u16;
|
||||
rect.height =
|
||||
max((rect.height as f64 / cfg.scale_down_factor + cfg.height_offset) as i32, 0) as u16;
|
||||
return rect;
|
||||
}
|
||||
|
||||
fn create_demon(adaptor: Adaptor) -> Result<Child> {
|
||||
Ok(
|
||||
Command::new("ueberzug")
|
||||
|
|
@ -55,12 +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, tmp_rect)) = cmd {
|
||||
debug!("ueberzug rect before adjustment: {:?}", tmp_rect);
|
||||
let rect = Self::adjust_rect(tmp_rect);
|
||||
debug!("ueberzug rect after adjustment: {:?}", rect);
|
||||
|
||||
let s = format!(
|
||||
r#"{{"action":"add","identifier":"yazi","x":{},"y":{},"max_width":{},"max_height":{},"path":"{}"}}{}"#,
|
||||
rect.x,
|
||||
|
|
|
|||
|
|
@ -13,16 +13,8 @@ tab_size = 2
|
|||
max_width = 600
|
||||
max_height = 900
|
||||
cache_dir = ""
|
||||
|
||||
[preview.ueberzug]
|
||||
# Scale down the coordinate and size of image preview that is incorrectly scaled
|
||||
# up by ueberzugpp in Wayland (tested under Hyprland). Example usage: if your
|
||||
# monitor has a 2.0 scale factor, you should pass 2.0 here.
|
||||
scale_down_factor = 1.0
|
||||
x_offset = 0.0
|
||||
y_offset = 0.0
|
||||
width_offset = 0.0
|
||||
height_offset = 0.0
|
||||
ueberzug_scale = 1
|
||||
ueberzug_offset = [ 0, 0, 0, 0 ]
|
||||
|
||||
[opener]
|
||||
edit = [
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ pub struct Preview {
|
|||
|
||||
pub cache_dir: PathBuf,
|
||||
|
||||
pub ueberzug: UeberzugPreview,
|
||||
pub ueberzug_scale: f64,
|
||||
pub ueberzug_offset: (f64, f64, f64, f64),
|
||||
}
|
||||
|
||||
impl Default for Preview {
|
||||
|
|
@ -40,7 +41,8 @@ impl Default for Preview {
|
|||
|
||||
cache_dir: Option<String>,
|
||||
|
||||
ueberzug: UeberzugPreview,
|
||||
ueberzug_scale: f64,
|
||||
ueberzug_offset: (f64, f64, f64, f64),
|
||||
}
|
||||
|
||||
let preview = toml::from_str::<Outer>(&MERGED_YAZI).unwrap().preview;
|
||||
|
|
@ -55,7 +57,8 @@ impl Default for Preview {
|
|||
|
||||
cache_dir,
|
||||
|
||||
ueberzug: preview.ueberzug,
|
||||
ueberzug_scale: preview.ueberzug_scale,
|
||||
ueberzug_offset: preview.ueberzug_offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue