diff --git a/yazi-adaptor/src/iterm2.rs b/yazi-adaptor/src/iterm2.rs index 34948ea30..97c0262f3 100644 --- a/yazi-adaptor/src/iterm2.rs +++ b/yazi-adaptor/src/iterm2.rs @@ -1,7 +1,7 @@ use std::{io::Write, path::Path}; use anyhow::Result; -use base64::{engine::general_purpose, Engine}; +use base64::{engine::{general_purpose::STANDARD, Config}, Engine}; use image::{codecs::jpeg::JpegEncoder, DynamicImage}; use ratatui::layout::Rect; use yazi_shared::term::Term; @@ -38,20 +38,20 @@ impl Iterm2 { async fn encode(img: DynamicImage) -> Result> { tokio::task::spawn_blocking(move || { - let size = (img.width(), img.height()); - let mut jpg = vec![]; JpegEncoder::new_with_quality(&mut jpg, 75).encode_image(&img)?; - let mut buf = vec![]; + let len = base64::encoded_len(jpg.len(), STANDARD.config().encode_padding()); + let mut buf = Vec::with_capacity(200 + len.unwrap_or(1 << 16)); + write!( buf, "{}]1337;File=inline=1;size={};width={}px;height={}px;doNotMoveCursor=1:{}\x07{}", START, jpg.len(), - size.0, - size.1, - general_purpose::STANDARD.encode(&jpg), + img.width(), + img.height(), + STANDARD.encode(&jpg), CLOSE )?; Ok(buf) diff --git a/yazi-config/src/keymap/key.rs b/yazi-config/src/keymap/key.rs index 0de1ba7d3..2c1934793 100644 --- a/yazi-config/src/keymap/key.rs +++ b/yazi-config/src/keymap/key.rs @@ -7,29 +7,27 @@ use serde::Deserialize; #[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Hash)] #[serde(try_from = "String")] pub struct Key { - pub code: KeyCode, - pub shift: bool, - pub ctrl: bool, - pub alt: bool, + pub code: KeyCode, + pub shift: bool, + pub ctrl: bool, + pub alt: bool, + pub super_: bool, } impl Key { #[inline] pub fn plain(&self) -> Option { match self.code { - KeyCode::Char(c) if !self.ctrl && !self.alt => Some(c), + KeyCode::Char(c) if !self.ctrl && !self.alt && !self.super_ => Some(c), _ => None, } } - - #[inline] - pub fn is_enter(&self) -> bool { - matches!(self, Key { code: KeyCode::Enter, shift: false, ctrl: false, alt: false }) - } } impl Default for Key { - fn default() -> Self { Self { code: KeyCode::Null, shift: false, ctrl: false, alt: false } } + fn default() -> Self { + Self { code: KeyCode::Null, shift: false, ctrl: false, alt: false, super_: false } + } } impl From for Key { @@ -56,6 +54,7 @@ impl From for Key { shift, ctrl: value.modifiers.contains(KeyModifiers::CONTROL), alt: value.modifiers.contains(KeyModifiers::ALT), + super_: value.modifiers.contains(KeyModifiers::SUPER), } } } @@ -82,6 +81,7 @@ impl FromStr for Key { "S-" => key.shift = true, "C-" => key.ctrl = true, "A-" => key.alt = true, + "D-" => key.super_ = true, "Space" => key.code = KeyCode::Char(' '), "Backspace" => key.code = KeyCode::Backspace, @@ -140,6 +140,9 @@ impl Display for Key { } write!(f, "<")?; + if self.super_ { + write!(f, "D-")?; + } if self.ctrl { write!(f, "C-")?; } diff --git a/yazi-core/src/help/help.rs b/yazi-core/src/help/help.rs index f28989458..af13964da 100644 --- a/yazi-core/src/help/help.rs +++ b/yazi-core/src/help/help.rs @@ -43,15 +43,15 @@ impl Help { }; match key { - Key { code: KeyCode::Esc, shift: false, ctrl: false, alt: false } => { + Key { code: KeyCode::Esc, shift: false, ctrl: false, alt: false, super_: false } => { self.in_filter = None; render!(); } - Key { code: KeyCode::Enter, shift: false, ctrl: false, alt: false } => { + Key { code: KeyCode::Enter, shift: false, ctrl: false, alt: false, super_: false } => { self.in_filter = None; return render_and!(true); // Don't do the `filter_apply` below, since we already have the filtered results. } - Key { code: KeyCode::Backspace, shift: false, ctrl: false, alt: false } => { + Key { code: KeyCode::Backspace, shift: false, ctrl: false, alt: false, super_: false } => { input.backspace(false); } _ => {