-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: deprecate
--sync
option for the plugin
command
- Loading branch information
Showing
21 changed files
with
258 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
use mlua::TableExt; | ||
use yazi_config::LAYOUT; | ||
use yazi_macro::emit; | ||
use yazi_shared::{Layer, event::Cmd}; | ||
use yazi_proxy::{AppProxy, options::{PluginCallback, PluginOpt}}; | ||
use yazi_shared::event::Cmd; | ||
|
||
use crate::{LUA, Opt, OptCallback, bindings::Cast, elements::Rect, file::File}; | ||
use crate::{LUA, bindings::Cast, elements::Rect, file::File}; | ||
|
||
pub fn seek_sync(cmd: &Cmd, file: yazi_shared::fs::File, units: i16) { | ||
let cb: OptCallback = Box::new(move |_, plugin| { | ||
let cb: PluginCallback = Box::new(move |_, plugin| { | ||
plugin.raw_set("file", File::cast(&LUA, file)?)?; | ||
plugin.raw_set("area", Rect::from(LAYOUT.get().preview))?; | ||
plugin.call_method("seek", units) | ||
}); | ||
|
||
let cmd: Cmd = | ||
Opt { id: cmd.name.to_owned(), sync: true, cb: Some(cb), ..Default::default() }.into(); | ||
|
||
emit!(Call(cmd.with_name("plugin"), Layer::App)); | ||
AppProxy::plugin(PluginOpt::new_callback(&cmd.name, cb)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::borrow::Cow; | ||
|
||
pub struct Chunk { | ||
pub bytes: Cow<'static, [u8]>, | ||
pub sync_entry: bool, | ||
} | ||
|
||
impl Chunk { | ||
#[inline] | ||
pub fn as_bytes(&self) -> &[u8] { &self.bytes } | ||
|
||
fn analyze(&mut self) { | ||
for line in self.bytes.split(|&b| b == b'\n') { | ||
let Some(rest) = line.strip_prefix(b"---") else { break }; | ||
|
||
let rest = rest.trim_ascii(); | ||
let Some(pos) = rest.iter().position(|&b| b == b' ' || b == b'\t') else { break }; | ||
|
||
match (rest[..pos].trim_ascii(), rest[pos..].trim_ascii()) { | ||
(b"@sync", b"entry") => self.sync_entry = true, | ||
(_, []) => break, | ||
(b, _) if b.strip_prefix(b"@").unwrap_or(b"").is_empty() => break, | ||
_ => continue, | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<Cow<'static, [u8]>> for Chunk { | ||
fn from(b: Cow<'static, [u8]>) -> Self { | ||
let mut chunk = Self { bytes: b, sync_entry: false }; | ||
chunk.analyze(); | ||
chunk | ||
} | ||
} | ||
|
||
impl From<&'static [u8]> for Chunk { | ||
fn from(b: &'static [u8]) -> Self { Self::from(Cow::Borrowed(b)) } | ||
} | ||
|
||
impl From<Vec<u8>> for Chunk { | ||
fn from(b: Vec<u8>) -> Self { Self::from(Cow::Owned(b)) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.