repo
stringlengths
6
65
file_url
stringlengths
81
311
file_path
stringlengths
6
227
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:31:58
2026-01-04 20:25:31
truncated
bool
2 classes
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/help/toggle.rs
yazi-parser/src/help/toggle.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{Layer, event::CmdCow}; #[derive(Debug)] pub struct ToggleOpt { pub layer: Layer, } impl TryFrom<CmdCow> for ToggleOpt { type Error = anyhow::Error; fn try_from(c: CmdCow) -> Result<Self, Self::Error> { Ok(Self { layer: c.str(0).parse()? }) } } impl From<Layer> for ToggleOpt { fn from(layer: Layer) -> Self { Self { layer } } } impl FromLua for ToggleOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ToggleOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/help/mod.rs
yazi-parser/src/help/mod.rs
yazi_macro::mod_flat!(toggle);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/open.rs
yazi-parser/src/mgr/open.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlCow}; #[derive(Debug)] pub struct OpenOpt { pub cwd: Option<UrlCow<'static>>, pub targets: Vec<UrlCow<'static>>, pub interactive: bool, pub hovered: bool, } impl TryFrom<CmdCow> for OpenOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { return opt; } Ok(Self { cwd: c.take("cwd").ok(), targets: c.take_seq(), interactive: c.bool("interactive"), hovered: c.bool("hovered"), }) } } impl FromLua for OpenOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for OpenOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/stash.rs
yazi-parser/src/mgr/stash.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, LuaSerdeExt, Value}; use serde::{Deserialize, Serialize}; use yazi_binding::Url; use yazi_shared::{event::CmdCow, url::UrlBuf}; use crate::mgr::{CdOpt, CdSource}; #[derive(Debug, Deserialize, Serialize)] pub struct StashOpt { pub target: UrlBuf, pub source: CdSource, } impl TryFrom<CmdCow> for StashOpt { type Error = anyhow::Error; fn try_from(_: CmdCow) -> Result<Self, Self::Error> { bail!("unsupported") } } impl From<CdOpt> for StashOpt { fn from(opt: CdOpt) -> Self { Self { target: opt.target, source: opt.source } } } impl FromLua for StashOpt { fn from_lua(value: Value, lua: &Lua) -> mlua::Result<Self> { let tbl = value.as_table().ok_or_else(|| "expected table".into_lua_err())?; Ok(Self { target: tbl.get::<Url>("target")?.into(), source: lua.from_value(tbl.get("source")?)?, }) } } impl IntoLua for StashOpt { fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { lua .create_table_from([ ("target", Url::new(self.target).into_lua(lua)?), ("source", lua.to_value(&self.source)?), ])? .into_lua(lua) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/update_mimes.rs
yazi-parser/src/mgr/update_mimes.rs
use anyhow::bail; use hashbrown::HashMap; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{data::{Data, DataKey}, event::CmdCow}; #[derive(Debug)] pub struct UpdateMimesOpt { pub updates: HashMap<DataKey, Data>, } impl TryFrom<CmdCow> for UpdateMimesOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { let Ok(updates) = c.take("updates") else { bail!("Invalid 'updates' argument in UpdateMimesOpt"); }; Ok(Self { updates }) } } impl FromLua for UpdateMimesOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for UpdateMimesOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/link.rs
yazi-parser/src/mgr/link.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct LinkOpt { pub relative: bool, pub force: bool, } impl From<CmdCow> for LinkOpt { fn from(c: CmdCow) -> Self { Self { relative: c.bool("relative"), force: c.bool("force") } } } impl FromLua for LinkOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for LinkOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/download.rs
yazi-parser/src/mgr/download.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlCow}; #[derive(Debug, Default)] pub struct DownloadOpt { pub urls: Vec<UrlCow<'static>>, pub open: bool, } impl From<CmdCow> for DownloadOpt { fn from(mut c: CmdCow) -> Self { Self { urls: c.take_seq(), open: c.bool("open") } } } impl FromLua for DownloadOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for DownloadOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/yank.rs
yazi-parser/src/mgr/yank.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct YankOpt { pub cut: bool, } impl From<CmdCow> for YankOpt { fn from(c: CmdCow) -> Self { Self { cut: c.bool("cut") } } } impl FromLua for YankOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for YankOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/hardlink.rs
yazi-parser/src/mgr/hardlink.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct HardlinkOpt { pub force: bool, pub follow: bool, } impl From<CmdCow> for HardlinkOpt { fn from(c: CmdCow) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } } impl FromLua for HardlinkOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for HardlinkOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/cd.rs
yazi-parser/src/mgr/cd.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use serde::{Deserialize, Serialize}; use yazi_fs::path::{clean_url, expand_url}; use yazi_shared::{event::CmdCow, url::{Url, UrlBuf}}; use yazi_vfs::provider; #[derive(Debug)] pub struct CdOpt { pub target: UrlBuf, pub interactive: bool, pub source: CdSource, } impl From<CmdCow> for CdOpt { fn from(mut c: CmdCow) -> Self { let mut target = c.take_first().unwrap_or_default(); if !c.bool("raw") { target = expand_url(target); } if let Some(u) = provider::try_absolute(&target) && u.is_owned() { target = u.into_static(); } Self { target: clean_url(target), interactive: c.bool("interactive"), source: CdSource::Cd, } } } impl From<(UrlBuf, CdSource)> for CdOpt { fn from((target, source): (UrlBuf, CdSource)) -> Self { Self { target, interactive: false, source } } } impl From<(Url<'_>, CdSource)> for CdOpt { fn from((target, source): (Url, CdSource)) -> Self { Self::from((target.to_owned(), source)) } } impl FromLua for CdOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CdOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } } // --- Source #[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] #[serde(rename_all = "kebab-case")] pub enum CdSource { Tab, Cd, Reveal, Enter, Leave, Follow, Forward, Back, Escape, Displace, }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/filter.rs
yazi-parser/src/mgr/filter.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_fs::FilterCase; use yazi_shared::{SStr, event::CmdCow}; #[derive(Debug, Default)] pub struct FilterOpt { pub query: SStr, pub case: FilterCase, pub done: bool, } impl TryFrom<CmdCow> for FilterOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { return opt; } Ok(Self { query: c.take_first().unwrap_or_default(), case: FilterCase::from(&*c), done: c.bool("done"), }) } } impl FromLua for FilterOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for FilterOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/update_spotted.rs
yazi-parser/src/mgr/update_spotted.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Table, Value}; use yazi_binding::{FileRef, elements::Renderable}; use yazi_shared::{Id, event::CmdCow}; #[derive(Debug)] pub struct UpdateSpottedOpt { pub lock: SpotLock, } impl TryFrom<CmdCow> for UpdateSpottedOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { return opt; } let Some(lock) = c.take_any("lock") else { bail!("Invalid 'lock' argument in UpdateSpottedOpt"); }; Ok(Self { lock }) } } impl FromLua for UpdateSpottedOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for UpdateSpottedOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } } // --- Lock #[derive(Debug)] pub struct SpotLock { pub url: yazi_shared::url::UrlBuf, pub cha: yazi_fs::cha::Cha, pub mime: String, pub id: Id, pub skip: usize, pub data: Vec<Renderable>, } impl TryFrom<Table> for SpotLock { type Error = mlua::Error; fn try_from(t: Table) -> Result<Self, Self::Error> { let file: FileRef = t.raw_get("file")?; Ok(Self { url: file.url_owned(), cha: file.cha, mime: t.raw_get("mime")?, id: *t.raw_get::<yazi_binding::Id>("id")?, skip: t.raw_get("skip")?, data: Default::default(), }) } } impl SpotLock { pub fn len(&self) -> Option<usize> { Some(self.table()?.len()) } pub fn select(&mut self, idx: Option<usize>) { if let Some(t) = self.table_mut() { t.select(idx); } } pub fn selected(&self) -> Option<usize> { self.table()?.selected() } pub fn table(&self) -> Option<&yazi_binding::elements::Table> { self.data.iter().rev().find_map(|r| match r { Renderable::Table(t) => Some(t.as_ref()), _ => None, }) } pub fn table_mut(&mut self) -> Option<&mut yazi_binding::elements::Table> { self.data.iter_mut().rev().find_map(|r| match r { Renderable::Table(t) => Some(t.as_mut()), _ => None, }) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/sort.rs
yazi-parser/src/mgr/sort.rs
use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value}; use serde::{Deserialize, Serialize}; use yazi_fs::SortBy; use yazi_shared::event::CmdCow; #[derive(Debug, Default, Deserialize, Serialize)] pub struct SortOpt { pub by: Option<SortBy>, pub reverse: Option<bool>, pub dir_first: Option<bool>, pub sensitive: Option<bool>, pub translit: Option<bool>, } impl TryFrom<CmdCow> for SortOpt { type Error = anyhow::Error; fn try_from(c: CmdCow) -> Result<Self, Self::Error> { Ok(Self { by: c.first().ok().map(str::parse).transpose()?, reverse: c.get("reverse").ok(), dir_first: c.get("dir-first").ok(), sensitive: c.get("sensitive").ok(), translit: c.get("translit").ok(), }) } } impl FromLua for SortOpt { fn from_lua(value: Value, lua: &Lua) -> mlua::Result<Self> { lua.from_value(value) } } impl IntoLua for SortOpt { fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { lua.to_value(&self) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/rename.rs
yazi-parser/src/mgr/rename.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{SStr, event::CmdCow}; #[derive(Debug)] pub struct RenameOpt { pub hovered: bool, pub force: bool, pub empty: SStr, pub cursor: SStr, } impl From<CmdCow> for RenameOpt { fn from(mut c: CmdCow) -> Self { Self { hovered: c.bool("hovered"), force: c.bool("force"), empty: c.take("empty").unwrap_or_default(), cursor: c.take("cursor").unwrap_or_default(), } } } impl FromLua for RenameOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for RenameOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/toggle_all.rs
yazi-parser/src/mgr/toggle_all.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlCow}; #[derive(Debug)] pub struct ToggleAllOpt { pub urls: Vec<UrlCow<'static>>, pub state: Option<bool>, } impl From<CmdCow> for ToggleAllOpt { fn from(mut c: CmdCow) -> Self { Self { urls: c.take_seq(), state: match c.get("state") { Ok("on") => Some(true), Ok("off") => Some(false), _ => None, }, } } } impl From<Option<bool>> for ToggleAllOpt { fn from(state: Option<bool>) -> Self { Self { urls: vec![], state } } } impl FromLua for ToggleAllOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ToggleAllOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/tab_close.rs
yazi-parser/src/mgr/tab_close.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct TabCloseOpt { pub idx: usize, } impl From<CmdCow> for TabCloseOpt { fn from(c: CmdCow) -> Self { Self { idx: c.first().unwrap_or(0) } } } impl From<usize> for TabCloseOpt { fn from(idx: usize) -> Self { Self { idx } } } impl FromLua for TabCloseOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for TabCloseOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/peek.rs
yazi-parser/src/mgr/peek.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlCow}; #[derive(Debug, Default)] pub struct PeekOpt { pub skip: Option<usize>, pub force: bool, pub only_if: Option<UrlCow<'static>>, pub upper_bound: bool, } impl From<CmdCow> for PeekOpt { fn from(mut c: CmdCow) -> Self { Self { skip: c.first().ok(), force: c.bool("force"), only_if: c.take("only-if").ok(), upper_bound: c.bool("upper-bound"), } } } impl From<bool> for PeekOpt { fn from(force: bool) -> Self { Self { force, ..Default::default() } } } impl FromLua for PeekOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for PeekOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/open_do.rs
yazi-parser/src/mgr/open_do.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlCow}; #[derive(Debug, Default)] pub struct OpenDoOpt { pub cwd: UrlCow<'static>, pub targets: Vec<UrlCow<'static>>, pub interactive: bool, } impl TryFrom<CmdCow> for OpenDoOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { opt } else { bail!("'opt' is required for OpenDoOpt"); } } } impl FromLua for OpenDoOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for OpenDoOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/update_files.rs
yazi-parser/src/mgr/update_files.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_fs::FilesOp; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct UpdateFilesOpt { pub op: FilesOp, } impl TryFrom<CmdCow> for UpdateFilesOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { let Some(op) = c.take_any("op") else { bail!("Invalid 'op' argument in UpdateFilesOpt"); }; Ok(Self { op }) } } impl From<FilesOp> for UpdateFilesOpt { fn from(op: FilesOp) -> Self { Self { op } } } impl FromLua for UpdateFilesOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for UpdateFilesOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/toggle.rs
yazi-parser/src/mgr/toggle.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlCow}; #[derive(Debug)] pub struct ToggleOpt { pub url: Option<UrlCow<'static>>, pub state: Option<bool>, } impl From<CmdCow> for ToggleOpt { fn from(mut c: CmdCow) -> Self { Self { url: c.take_first().ok(), state: match c.get("state") { Ok("on") => Some(true), Ok("off") => Some(false), _ => None, }, } } } impl FromLua for ToggleOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ToggleOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/shell.rs
yazi-parser/src/mgr/shell.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{SStr, event::CmdCow, url::UrlCow}; #[derive(Debug)] pub struct ShellOpt { pub run: SStr, pub cwd: Option<UrlCow<'static>>, pub block: bool, pub orphan: bool, pub interactive: bool, pub cursor: Option<usize>, } impl TryFrom<CmdCow> for ShellOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { let me = Self { run: c.take_first().unwrap_or_default(), cwd: c.take("cwd").ok(), block: c.bool("block"), orphan: c.bool("orphan"), interactive: c.bool("interactive"), cursor: c.get("cursor").ok(), }; if me.cursor.is_some_and(|c| c > me.run.chars().count()) { bail!("The cursor position is out of bounds."); } Ok(me) } } impl FromLua for ShellOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ShellOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/hover.rs
yazi-parser/src/mgr/hover.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::path::PathBufDyn; #[derive(Debug, Default)] pub struct HoverOpt { pub urn: Option<PathBufDyn>, } impl From<Option<PathBufDyn>> for HoverOpt { fn from(urn: Option<PathBufDyn>) -> Self { Self { urn } } } impl FromLua for HoverOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for HoverOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/search.rs
yazi-parser/src/mgr/search.rs
use std::str::FromStr; use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use serde::Deserialize; use yazi_shared::{SStr, event::CmdCow}; #[derive(Debug)] pub struct SearchOpt { pub via: SearchOptVia, pub subject: SStr, pub args: Vec<String>, pub args_raw: SStr, } impl TryFrom<CmdCow> for SearchOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { // TODO: remove this let (via, subject) = if let Ok(s) = c.get("via") { (str::parse(s)?, c.take_first().unwrap_or_default()) } else { (c.str(0).parse()?, "".into()) }; let Ok(args) = yazi_shared::shell::unix::split(c.str("args"), false) else { bail!("Invalid 'args' argument in SearchOpt"); }; Ok(Self { via, subject, // TODO: use second positional argument instead of `args` parameter args: args.0, args_raw: c.take("args").unwrap_or_default(), }) } } impl FromLua for SearchOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for SearchOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } } // Via #[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)] #[serde(rename_all = "kebab-case")] pub enum SearchOptVia { Rg, Rga, Fd, } impl FromStr for SearchOptVia { type Err = serde::de::value::Error; fn from_str(s: &str) -> Result<Self, Self::Err> { Self::deserialize(serde::de::value::StrDeserializer::new(s)) } } impl SearchOptVia { pub fn into_str(self) -> &'static str { match self { Self::Rg => "rg", Self::Rga => "rga", Self::Fd => "fd", } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/find.rs
yazi-parser/src/mgr/find.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_fs::FilterCase; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct FindOpt { pub prev: bool, pub case: FilterCase, } impl TryFrom<CmdCow> for FindOpt { type Error = anyhow::Error; fn try_from(c: CmdCow) -> Result<Self, Self::Error> { Ok(Self { prev: c.bool("previous"), case: FilterCase::from(&*c) }) } } impl FromLua for FindOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for FindOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/quit.rs
yazi-parser/src/mgr/quit.rs
use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value}; use serde::{Deserialize, Serialize}; use yazi_shared::event::{CmdCow, EventQuit}; #[derive(Debug, Default, Deserialize, Serialize)] pub struct QuitOpt { pub code: i32, pub no_cwd_file: bool, } impl From<CmdCow> for QuitOpt { fn from(c: CmdCow) -> Self { Self { code: c.get("code").unwrap_or_default(), no_cwd_file: c.bool("no-cwd-file") } } } impl From<QuitOpt> for EventQuit { fn from(value: QuitOpt) -> Self { Self { code: value.code, no_cwd_file: value.no_cwd_file, ..Default::default() } } } impl FromLua for QuitOpt { fn from_lua(value: Value, lua: &Lua) -> mlua::Result<Self> { lua.from_value(value) } } impl IntoLua for QuitOpt { fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { lua.to_value(&self) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/find_arrow.rs
yazi-parser/src/mgr/find_arrow.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct FindArrowOpt { pub prev: bool, } impl From<CmdCow> for FindArrowOpt { fn from(c: CmdCow) -> Self { Self { prev: c.bool("previous") } } } impl FromLua for FindArrowOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for FindArrowOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/copy.rs
yazi-parser/src/mgr/copy.rs
use std::{borrow::Cow, str::FromStr}; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use serde::Deserialize; use yazi_shared::{SStr, event::CmdCow, strand::AsStrand}; #[derive(Debug)] pub struct CopyOpt { pub r#type: SStr, pub separator: CopySeparator, pub hovered: bool, } impl From<CmdCow> for CopyOpt { fn from(mut c: CmdCow) -> Self { Self { r#type: c.take_first().unwrap_or_default(), separator: c.str("separator").parse().unwrap_or_default(), hovered: c.bool("hovered"), } } } impl FromLua for CopyOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CopyOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } } // --- Separator #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Deserialize)] #[serde(rename_all = "kebab-case")] pub enum CopySeparator { #[default] Auto, Unix, } impl FromStr for CopySeparator { type Err = serde::de::value::Error; fn from_str(s: &str) -> Result<Self, Self::Err> { Self::deserialize(serde::de::value::StrDeserializer::new(s)) } } impl CopySeparator { pub fn transform<T>(self, s: &T) -> Cow<'_, [u8]> where T: ?Sized + AsStrand, { #[cfg(windows)] if self == Self::Unix { use yazi_shared::strand::StrandCow; return match s.as_strand().backslash_to_slash() { StrandCow::Borrowed(s) => s.encoded_bytes().into(), StrandCow::Owned(s) => s.into_encoded_bytes().into(), }; } Cow::Borrowed(s.as_strand().encoded_bytes()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/paste.rs
yazi-parser/src/mgr/paste.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct PasteOpt { pub force: bool, pub follow: bool, } impl From<CmdCow> for PasteOpt { fn from(c: CmdCow) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } } impl FromLua for PasteOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for PasteOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/upload.rs
yazi-parser/src/mgr/upload.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlCow}; #[derive(Debug, Default)] pub struct UploadOpt { pub urls: Vec<UrlCow<'static>>, } impl From<CmdCow> for UploadOpt { fn from(mut c: CmdCow) -> Self { Self { urls: c.take_seq() } } } impl FromLua for UploadOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for UploadOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/mod.rs
yazi-parser/src/mgr/mod.rs
yazi_macro::mod_flat!( cd close copy create displace_do download escape filter find find_arrow find_do hardlink hidden hover linemode link open open_do paste peek quit remove rename reveal search seek shell sort spot stash tab_close tab_create tab_switch toggle toggle_all update_files update_mimes update_paged update_peeked update_spotted update_yanked upload visual_mode yank );
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/visual_mode.rs
yazi-parser/src/mgr/visual_mode.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct VisualModeOpt { pub unset: bool, } impl From<CmdCow> for VisualModeOpt { fn from(c: CmdCow) -> Self { Self { unset: c.bool("unset") } } } impl FromLua for VisualModeOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for VisualModeOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/find_do.rs
yazi-parser/src/mgr/find_do.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_fs::FilterCase; use yazi_shared::{SStr, event::CmdCow}; #[derive(Debug)] pub struct FindDoOpt { pub query: SStr, pub prev: bool, pub case: FilterCase, } impl TryFrom<CmdCow> for FindDoOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { return opt; } let Ok(query) = c.take_first() else { bail!("'query' is required for FindDoOpt"); }; Ok(Self { query, prev: c.bool("previous"), case: FilterCase::from(&*c) }) } } impl FromLua for FindDoOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for FindDoOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/tab_create.rs
yazi-parser/src/mgr/tab_create.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_boot::BOOT; use yazi_fs::path::{clean_url, expand_url}; use yazi_shared::{event::CmdCow, url::UrlCow}; use yazi_vfs::provider; #[derive(Debug)] pub struct TabCreateOpt { pub url: Option<UrlCow<'static>>, } impl From<CmdCow> for TabCreateOpt { fn from(mut c: CmdCow) -> Self { if c.bool("current") { return Self { url: None }; } let Ok(mut url) = c.take_first() else { return Self { url: Some(UrlCow::from(&BOOT.cwds[0])) }; }; if !c.bool("raw") { url = expand_url(url); } if let Some(u) = provider::try_absolute(&url) && u.is_owned() { url = u.into_static(); } Self { url: Some(clean_url(url).into()) } } } impl FromLua for TabCreateOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for TabCreateOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/hidden.rs
yazi-parser/src/mgr/hidden.rs
use std::str::FromStr; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use serde::{Deserialize, Serialize}; use yazi_shared::event::CmdCow; #[derive(Debug, Default)] pub struct HiddenOpt { pub state: HiddenOptState, } impl TryFrom<CmdCow> for HiddenOpt { type Error = anyhow::Error; fn try_from(c: CmdCow) -> Result<Self, Self::Error> { Ok(Self { state: c.str(0).parse().unwrap_or_default() }) } } impl FromLua for HiddenOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for HiddenOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } } // --- State #[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] #[serde(rename_all = "kebab-case")] pub enum HiddenOptState { #[default] None, Show, Hide, Toggle, } impl FromStr for HiddenOptState { type Err = serde::de::value::Error; fn from_str(s: &str) -> Result<Self, Self::Err> { Self::deserialize(serde::de::value::StrDeserializer::new(s)) } } impl HiddenOptState { pub fn bool(self, old: bool) -> bool { match self { Self::None => old, Self::Show => true, Self::Hide => false, Self::Toggle => !old, } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/update_paged.rs
yazi-parser/src/mgr/update_paged.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlCow}; #[derive(Debug, Default)] pub struct UpdatePagedOpt { pub page: Option<usize>, pub only_if: Option<UrlCow<'static>>, } impl From<CmdCow> for UpdatePagedOpt { fn from(mut c: CmdCow) -> Self { Self { page: c.first().ok(), only_if: c.take("only-if").ok() } } } impl From<()> for UpdatePagedOpt { fn from(_: ()) -> Self { Self::default() } } impl FromLua for UpdatePagedOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for UpdatePagedOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/tab_switch.rs
yazi-parser/src/mgr/tab_switch.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct TabSwitchOpt { pub step: isize, pub relative: bool, } impl From<CmdCow> for TabSwitchOpt { fn from(c: CmdCow) -> Self { Self { step: c.first().unwrap_or(0), relative: c.bool("relative") } } } impl FromLua for TabSwitchOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for TabSwitchOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/update_peeked.rs
yazi-parser/src/mgr/update_peeked.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Table, Value}; use yazi_binding::{FileRef, elements::{Rect, Renderable}}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct UpdatePeekedOpt { pub lock: PreviewLock, } impl TryFrom<CmdCow> for UpdatePeekedOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { return opt; } let Some(lock) = c.take_any("lock") else { bail!("Invalid 'lock' argument in UpdatePeekedOpt"); }; Ok(Self { lock }) } } impl FromLua for UpdatePeekedOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for UpdatePeekedOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } } // --- Lock #[derive(Debug, Default)] pub struct PreviewLock { pub url: yazi_shared::url::UrlBuf, pub cha: yazi_fs::cha::Cha, pub mime: String, pub skip: usize, pub area: Rect, pub data: Vec<Renderable>, } impl TryFrom<Table> for PreviewLock { type Error = mlua::Error; fn try_from(t: Table) -> Result<Self, Self::Error> { let file: FileRef = t.raw_get("file")?; Ok(Self { url: file.url_owned(), cha: file.cha, mime: t.raw_get("mime")?, skip: t.raw_get("skip")?, area: t.raw_get("area")?, data: Default::default(), }) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/spot.rs
yazi-parser/src/mgr/spot.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug, Default)] pub struct SpotOpt { pub skip: Option<usize>, } impl From<CmdCow> for SpotOpt { fn from(c: CmdCow) -> Self { Self { skip: c.get("skip").ok() } } } impl From<usize> for SpotOpt { fn from(skip: usize) -> Self { Self { skip: Some(skip) } } } impl FromLua for SpotOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for SpotOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/escape.rs
yazi-parser/src/mgr/escape.rs
use bitflags::bitflags; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; bitflags! { #[derive(Debug)] pub struct EscapeOpt: u8 { const FIND = 0b00001; const VISUAL = 0b00010; const FILTER = 0b00100; const SELECT = 0b01000; const SEARCH = 0b10000; } } impl From<CmdCow> for EscapeOpt { fn from(c: CmdCow) -> Self { c.args.iter().fold(Self::empty(), |acc, (k, v)| { match (k.as_str().unwrap_or(""), v.try_into().unwrap_or(false)) { ("all", true) => Self::all(), ("find", true) => acc | Self::FIND, ("visual", true) => acc | Self::VISUAL, ("filter", true) => acc | Self::FILTER, ("select", true) => acc | Self::SELECT, ("search", true) => acc | Self::SEARCH, _ => acc, } }) } } impl FromLua for EscapeOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for EscapeOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/linemode.rs
yazi-parser/src/mgr/linemode.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{SStr, event::CmdCow}; #[derive(Debug)] pub struct LinemodeOpt { pub new: SStr, } impl TryFrom<CmdCow> for LinemodeOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { let Ok(new) = c.take_first::<SStr>() else { bail!("a string argument is required for LinemodeOpt"); }; if new.is_empty() || new.len() > 20 { bail!("Linemode must be between 1 and 20 characters long"); } Ok(Self { new }) } } impl FromLua for LinemodeOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for LinemodeOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/displace_do.rs
yazi-parser/src/mgr/displace_do.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlBuf}; #[derive(Debug)] pub struct DisplaceDoOpt { pub to: std::io::Result<UrlBuf>, pub from: UrlBuf, } impl TryFrom<CmdCow> for DisplaceDoOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { opt } else { bail!("'opt' is required for DisplaceDoOpt"); } } } impl FromLua for DisplaceDoOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for DisplaceDoOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/seek.rs
yazi-parser/src/mgr/seek.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct SeekOpt { pub units: i16, } impl From<CmdCow> for SeekOpt { fn from(c: CmdCow) -> Self { Self { units: c.first().unwrap_or(0) } } } impl FromLua for SeekOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for SeekOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/remove.rs
yazi-parser/src/mgr/remove.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{event::CmdCow, url::UrlBuf}; #[derive(Debug)] pub struct RemoveOpt { pub force: bool, pub permanently: bool, pub hovered: bool, pub targets: Vec<UrlBuf>, } impl From<CmdCow> for RemoveOpt { fn from(mut c: CmdCow) -> Self { Self { force: c.bool("force"), permanently: c.bool("permanently"), hovered: c.bool("hovered"), targets: c.take_any("targets").unwrap_or_default(), } } } impl FromLua for RemoveOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for RemoveOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/update_yanked.rs
yazi-parser/src/mgr/update_yanked.rs
use std::borrow::Cow; use anyhow::bail; use hashbrown::HashSet; use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, MetaMethod, MultiValue, ObjectLike, UserData, UserDataFields, UserDataMethods, Value}; use serde::{Deserialize, Serialize}; use yazi_binding::get_metatable; use yazi_shared::{event::CmdCow, url::UrlBufCov}; type Iter = yazi_binding::Iter< std::iter::Map<hashbrown::hash_set::IntoIter<UrlBufCov>, fn(UrlBufCov) -> yazi_binding::Url>, yazi_binding::Url, >; #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct UpdateYankedOpt<'a> { pub cut: bool, pub urls: Cow<'a, HashSet<UrlBufCov>>, } impl TryFrom<CmdCow> for UpdateYankedOpt<'_> { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { opt } else { bail!("'opt' is required for UpdateYankedOpt"); } } } impl FromLua for UpdateYankedOpt<'_> { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for UpdateYankedOpt<'_> { fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { let len = self.urls.len(); let iter = Iter::new(self.urls.into_owned().into_iter().map(yazi_binding::Url::new), Some(len)); UpdateYankedIter { cut: self.cut, len, inner: lua.create_userdata(iter)? }.into_lua(lua) } } // --- Iter pub struct UpdateYankedIter { cut: bool, len: usize, inner: AnyUserData, } impl UpdateYankedIter { pub fn into_opt(self, lua: &Lua) -> mlua::Result<UpdateYankedOpt<'static>> { Ok(UpdateYankedOpt { cut: self.cut, urls: Cow::Owned( self .inner .take::<Iter>()? .into_iter(lua) .map(|result| result.map(Into::into)) .collect::<mlua::Result<_>>()?, ), }) } } impl UserData for UpdateYankedIter { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { fields.add_field_method_get("cut", |_, me| Ok(me.cut)); } fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) { methods.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len)); methods.add_meta_method(MetaMethod::Pairs, |lua, me, ()| { get_metatable(lua, &me.inner)? .call_function::<MultiValue>(MetaMethod::Pairs.name(), me.inner.clone()) }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/close.rs
yazi-parser/src/mgr/close.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; use crate::mgr::QuitOpt; #[derive(Debug, Default)] pub struct CloseOpt(pub QuitOpt); impl From<CmdCow> for CloseOpt { fn from(c: CmdCow) -> Self { Self(c.into()) } } impl FromLua for CloseOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CloseOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/reveal.rs
yazi-parser/src/mgr/reveal.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_fs::path::{clean_url, expand_url}; use yazi_shared::{event::CmdCow, url::UrlBuf}; use yazi_vfs::provider; use crate::mgr::CdSource; #[derive(Debug)] pub struct RevealOpt { pub target: UrlBuf, pub source: CdSource, pub no_dummy: bool, } impl From<CmdCow> for RevealOpt { fn from(mut c: CmdCow) -> Self { let mut target = c.take_first().unwrap_or_default(); if !c.bool("raw") { target = expand_url(target); } if let Some(u) = provider::try_absolute(&target) && u.is_owned() { target = u.into_static(); } Self { target: clean_url(target), source: CdSource::Reveal, no_dummy: c.bool("no-dummy") } } } impl From<UrlBuf> for RevealOpt { fn from(target: UrlBuf) -> Self { Self { target, source: CdSource::Reveal, no_dummy: false } } } impl From<(UrlBuf, CdSource)> for RevealOpt { fn from((target, source): (UrlBuf, CdSource)) -> Self { Self { target, source, no_dummy: false } } } impl FromLua for RevealOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for RevealOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/mgr/create.rs
yazi-parser/src/mgr/create.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct CreateOpt { pub dir: bool, pub force: bool, } impl From<CmdCow> for CreateOpt { fn from(c: CmdCow) -> Self { Self { dir: c.bool("dir"), force: c.bool("force") } } } impl FromLua for CreateOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CreateOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/spot/copy.rs
yazi-parser/src/spot/copy.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{SStr, event::CmdCow}; #[derive(Debug)] pub struct CopyOpt { pub r#type: SStr, } impl From<CmdCow> for CopyOpt { fn from(mut c: CmdCow) -> Self { Self { r#type: c.take_first().unwrap_or_default() } } } impl FromLua for CopyOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CopyOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/spot/mod.rs
yazi-parser/src/spot/mod.rs
yazi_macro::mod_flat!(copy);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/complete.rs
yazi-parser/src/input/complete.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{Id, event::CmdCow}; use crate::cmp::CmpItem; #[derive(Debug)] pub struct CompleteOpt { pub item: CmpItem, pub ticket: Id, } impl TryFrom<CmdCow> for CompleteOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { let Some(item) = c.take_any("item") else { bail!("Invalid 'item' in CompleteOpt"); }; Ok(Self { item, ticket: c.get("ticket").unwrap_or_default() }) } } impl FromLua for CompleteOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CompleteOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/move.rs
yazi-parser/src/input/move.rs
use std::{num::ParseIntError, str::FromStr}; use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{data::Data, event::CmdCow}; #[derive(Debug, Default)] pub struct MoveOpt { pub step: MoveOptStep, pub in_operating: bool, } impl From<CmdCow> for MoveOpt { fn from(c: CmdCow) -> Self { Self { step: c.first().ok().unwrap_or_default(), in_operating: c.bool("in-operating") } } } impl From<isize> for MoveOpt { fn from(step: isize) -> Self { Self { step: step.into(), in_operating: false } } } impl FromLua for MoveOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for MoveOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } } // --- Step #[derive(Debug)] pub enum MoveOptStep { Offset(isize), Bol, Eol, FirstChar, } impl MoveOptStep { pub fn add(self, s: &str, cursor: usize) -> usize { match self { Self::Offset(n) if n <= 0 => cursor.saturating_add_signed(n), Self::Offset(n) => s.chars().count().min(cursor + n as usize), Self::Bol => 0, Self::Eol => s.chars().count(), Self::FirstChar => { s.chars().enumerate().find(|(_, c)| !c.is_whitespace()).map_or(0, |(i, _)| i) } } } } impl Default for MoveOptStep { fn default() -> Self { 0.into() } } impl FromStr for MoveOptStep { type Err = ParseIntError; fn from_str(s: &str) -> Result<Self, Self::Err> { Ok(match s { "bol" => Self::Bol, "eol" => Self::Eol, "first-char" => Self::FirstChar, s => Self::Offset(s.parse()?), }) } } impl From<isize> for MoveOptStep { fn from(value: isize) -> Self { Self::Offset(value) } } impl TryFrom<&Data> for MoveOptStep { type Error = anyhow::Error; fn try_from(value: &Data) -> Result<Self, Self::Error> { Ok(match value { Data::String(s) => s.parse()?, Data::Integer(i) => Self::from(*i as isize), _ => bail!("Invalid MoveOptStep data type: {value:?}"), }) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/casefy.rs
yazi-parser/src/input/casefy.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct CasefyOpt { pub upper: bool, } impl From<CmdCow> for CasefyOpt { fn from(c: CmdCow) -> Self { Self { upper: c.str(0) == "upper" } } } impl FromLua for CasefyOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CasefyOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } } impl CasefyOpt { pub fn transform(&self, s: &str) -> String { if self.upper { s.to_ascii_uppercase() } else { s.to_ascii_lowercase() } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/insert.rs
yazi-parser/src/input/insert.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct InsertOpt { pub append: bool, } impl From<CmdCow> for InsertOpt { fn from(c: CmdCow) -> Self { Self { append: c.bool("append") } } } impl From<bool> for InsertOpt { fn from(append: bool) -> Self { Self { append } } } impl FromLua for InsertOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for InsertOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/kill.rs
yazi-parser/src/input/kill.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{SStr, event::CmdCow}; #[derive(Debug)] pub struct KillOpt { pub kind: SStr, } impl From<CmdCow> for KillOpt { fn from(mut c: CmdCow) -> Self { Self { kind: c.take_first().unwrap_or_default() } } } impl FromLua for KillOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for KillOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/backspace.rs
yazi-parser/src/input/backspace.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug, Default)] pub struct BackspaceOpt { pub under: bool, } impl From<CmdCow> for BackspaceOpt { fn from(c: CmdCow) -> Self { Self { under: c.bool("under") } } } impl From<bool> for BackspaceOpt { fn from(under: bool) -> Self { Self { under } } } impl FromLua for BackspaceOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for BackspaceOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/paste.rs
yazi-parser/src/input/paste.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct PasteOpt { pub before: bool, } impl From<CmdCow> for PasteOpt { fn from(c: CmdCow) -> Self { Self { before: c.bool("before") } } } impl FromLua for PasteOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for PasteOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/mod.rs
yazi-parser/src/input/mod.rs
yazi_macro::mod_flat!(backspace backward casefy close complete delete forward insert kill paste r#move show);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/backward.rs
yazi-parser/src/input/backward.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct BackwardOpt { pub far: bool, } impl From<CmdCow> for BackwardOpt { fn from(c: CmdCow) -> Self { Self { far: c.bool("far") } } } impl FromLua for BackwardOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for BackwardOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/show.rs
yazi-parser/src/input/show.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use tokio::sync::mpsc; use yazi_config::popup::InputCfg; use yazi_shared::{errors::InputError, event::CmdCow}; #[derive(Debug)] pub struct ShowOpt { pub cfg: InputCfg, pub tx: mpsc::UnboundedSender<Result<String, InputError>>, } impl TryFrom<CmdCow> for ShowOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { let Some(cfg) = c.take_any("cfg") else { bail!("Invalid 'cfg' argument in ShowOpt"); }; let Some(tx) = c.take_any("tx") else { bail!("Invalid 'tx' argument in ShowOpt"); }; Ok(Self { cfg, tx }) } } impl FromLua for ShowOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ShowOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/forward.rs
yazi-parser/src/input/forward.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct ForwardOpt { pub far: bool, pub end_of_word: bool, } impl From<CmdCow> for ForwardOpt { fn from(c: CmdCow) -> Self { Self { far: c.bool("far"), end_of_word: c.bool("end-of-word") } } } impl FromLua for ForwardOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ForwardOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/close.rs
yazi-parser/src/input/close.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug, Default)] pub struct CloseOpt { pub submit: bool, } impl From<CmdCow> for CloseOpt { fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } } impl From<bool> for CloseOpt { fn from(submit: bool) -> Self { Self { submit } } } impl FromLua for CloseOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CloseOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/input/delete.rs
yazi-parser/src/input/delete.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct DeleteOpt { pub cut: bool, pub insert: bool, } impl From<CmdCow> for DeleteOpt { fn from(c: CmdCow) -> Self { Self { cut: c.bool("cut"), insert: c.bool("insert") } } } impl FromLua for DeleteOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for DeleteOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/pick/mod.rs
yazi-parser/src/pick/mod.rs
yazi_macro::mod_flat!(close show);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/pick/show.rs
yazi-parser/src/pick/show.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use tokio::sync::oneshot; use yazi_config::popup::PickCfg; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct ShowOpt { pub cfg: PickCfg, pub tx: oneshot::Sender<anyhow::Result<usize>>, } impl TryFrom<CmdCow> for ShowOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { let Some(cfg) = c.take_any("cfg") else { bail!("Missing 'cfg' argument in ShowOpt"); }; let Some(tx) = c.take_any("tx") else { bail!("Missing 'tx' argument in ShowOpt"); }; Ok(Self { cfg, tx }) } } impl FromLua for ShowOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ShowOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/pick/close.rs
yazi-parser/src/pick/close.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug, Default)] pub struct CloseOpt { pub submit: bool, } impl From<CmdCow> for CloseOpt { fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } } impl From<bool> for CloseOpt { fn from(submit: bool) -> Self { Self { submit } } } impl FromLua for CloseOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CloseOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/cmp/trigger.rs
yazi-parser/src/cmp/trigger.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{Id, SStr, event::CmdCow}; #[derive(Debug)] pub struct TriggerOpt { pub word: SStr, pub ticket: Option<Id>, } impl From<CmdCow> for TriggerOpt { fn from(mut c: CmdCow) -> Self { Self { word: c.take_first().unwrap_or_default(), ticket: c.get("ticket").ok() } } } impl FromLua for TriggerOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for TriggerOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/cmp/mod.rs
yazi-parser/src/cmp/mod.rs
yazi_macro::mod_flat!(close show trigger);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/cmp/show.rs
yazi-parser/src/cmp/show.rs
use std::path::MAIN_SEPARATOR_STR; use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::{Id, event::CmdCow, path::PathBufDyn, strand::{StrandBuf, StrandLike}, url::UrlBuf}; #[derive(Debug)] pub struct ShowOpt { pub cache: Vec<CmpItem>, pub cache_name: UrlBuf, pub word: PathBufDyn, pub ticket: Id, } impl TryFrom<CmdCow> for ShowOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { opt } else { bail!("missing 'opt' argument"); } } } impl FromLua for ShowOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ShowOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } } // --- Item #[derive(Debug, Clone)] pub struct CmpItem { pub name: StrandBuf, pub is_dir: bool, } impl CmpItem { pub fn completable(&self) -> String { format!("{}{}", self.name.to_string_lossy(), if self.is_dir { MAIN_SEPARATOR_STR } else { "" }) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/cmp/close.rs
yazi-parser/src/cmp/close.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug, Default)] pub struct CloseOpt { pub submit: bool, } impl From<CmdCow> for CloseOpt { fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } } impl From<bool> for CloseOpt { fn from(submit: bool) -> Self { Self { submit } } } impl FromLua for CloseOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CloseOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/confirm/mod.rs
yazi-parser/src/confirm/mod.rs
yazi_macro::mod_flat!(close show);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/confirm/show.rs
yazi-parser/src/confirm/show.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use tokio::sync::oneshot; use yazi_config::popup::ConfirmCfg; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct ShowOpt { pub cfg: ConfirmCfg, pub tx: oneshot::Sender<bool>, } impl TryFrom<CmdCow> for ShowOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { let Some(cfg) = c.take_any("cfg") else { bail!("Invalid 'cfg' argument in ShowOpt"); }; let Some(tx) = c.take_any("tx") else { bail!("Invalid 'tx' argument in ShowOpt"); }; Ok(Self { cfg, tx }) } } impl From<Box<Self>> for ShowOpt { fn from(value: Box<Self>) -> Self { *value } } impl FromLua for ShowOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ShowOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/confirm/close.rs
yazi-parser/src/confirm/close.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug, Default)] pub struct CloseOpt { pub submit: bool, } impl From<CmdCow> for CloseOpt { fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } } impl From<bool> for CloseOpt { fn from(submit: bool) -> Self { Self { submit } } } impl FromLua for CloseOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CloseOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/notify/mod.rs
yazi-parser/src/notify/mod.rs
yazi_macro::mod_flat!(tick);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/notify/tick.rs
yazi-parser/src/notify/tick.rs
use std::time::Duration; use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct TickOpt { pub interval: Duration, } impl TryFrom<CmdCow> for TickOpt { type Error = anyhow::Error; fn try_from(c: CmdCow) -> Result<Self, Self::Error> { let Ok(interval) = c.first() else { bail!("Invalid 'interval' argument in TickOpt"); }; if interval < 0.0 { bail!("'interval' must be non-negative in TickOpt"); } Ok(Self { interval: Duration::from_secs_f64(interval) }) } } impl FromLua for TickOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for TickOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/which/callback.rs
yazi-parser/src/which/callback.rs
use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use tokio::sync::mpsc; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct CallbackOpt { pub tx: mpsc::Sender<usize>, pub idx: usize, } impl TryFrom<CmdCow> for CallbackOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { let Some(tx) = c.take_any("tx") else { bail!("Invalid 'tx' argument in CallbackOpt"); }; let Ok(idx) = c.first() else { bail!("Invalid 'idx' argument in CallbackOpt"); }; Ok(Self { tx, idx }) } } impl FromLua for CallbackOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for CallbackOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/which/mod.rs
yazi-parser/src/which/mod.rs
yazi_macro::mod_flat!(callback show);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-parser/src/which/show.rs
yazi-parser/src/which/show.rs
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_config::keymap::Chord; use yazi_shared::event::CmdCow; #[derive(Debug)] pub struct ShowOpt { pub cands: Vec<Chord>, pub silent: bool, } impl TryFrom<CmdCow> for ShowOpt { type Error = anyhow::Error; fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> { if let Some(opt) = c.take_any2("opt") { return opt; } Ok(Self { cands: c.take_any("candidates").unwrap_or_default(), silent: c.bool("silent") }) } } impl FromLua for ShowOpt { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) } } impl IntoLua for ShowOpt { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-build/build.rs
yazi-build/build.rs
use std::{env, error::Error, io::{BufRead, BufReader, Read, Write}, process::{Command, Stdio}, thread}; use yazi_term::tty::TTY; fn main() -> Result<(), Box<dyn Error>> { yazi_term::init(); let manifest = env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().replace(r"\", "/"); let crates = if manifest.contains("/git/checkouts/yazi-") { &["--git", "https://github.com/sxyazi/yazi.git", "yazi-fm", "yazi-cli"] } else if manifest.contains("/registry/src/index.crates.io-") { &["yazi-fm", "yazi-cli"][..] } else { return Ok(()); }; let target = env::var("TARGET").unwrap(); let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); unsafe { env::set_var("VERGEN_GIT_SHA", "Crates.io"); env::set_var("YAZI_CRATE_BUILD", "1"); env::set_var("JEMALLOC_SYS_WITH_LG_PAGE", "16"); env::set_var("JEMALLOC_SYS_WITH_MALLOC_CONF", "narenas:1"); env::set_var( "MACOSX_DEPLOYMENT_TARGET", if target == "aarch64-apple-darwin" { "11.0" } else { "10.12" }, ); if target == "aarch64-apple-darwin" { env::set_var("RUSTFLAGS", "-Ctarget-cpu=apple-m1"); } }; let profile = if target_os == "windows" { &["--profile", "release-windows"][..] } else { &[] }; let mut child = Command::new(env::var_os("CARGO").unwrap()) .args(["install", "--force", "--locked"]) .args(profile) .args(crates) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn()?; let out = flash(child.stdout.take().unwrap()); let err = flash(child.stderr.take().unwrap()); child.wait()?; out.join().ok(); err.join().ok(); Ok(()) } fn flash<R: Read + Send + 'static>(src: R) -> thread::JoinHandle<()> { thread::spawn(move || { let reader = BufReader::new(src); for part in reader.split(b'\n') { match part { Ok(mut bytes) => { bytes.push(b'\n'); let mut out = TTY.lockout(); out.write_all(&bytes).ok(); out.flush().ok(); } Err(_) => break, } } }) }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-build/src/main.rs
yazi-build/src/main.rs
fn main() { println!("See https://yazi-rs.github.io/docs/installation#crates on how to install Yazi."); }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/build.rs
yazi-cli/build.rs
#[path = "src/args.rs"] mod args; use std::{env, error::Error}; use clap::CommandFactory; use clap_complete::{Shell, generate_to}; use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder}; fn main() -> Result<(), Box<dyn Error>> { let manifest = env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().replace(r"\", "/"); if env::var_os("YAZI_CRATE_BUILD").is_none() && (manifest.contains("/git/checkouts/yazi-") || manifest.contains("/registry/src/index.crates.io-")) { panic!( "Due to Cargo's limitations, the `yazi-fm` and `yazi-cli` crates on crates.io must be built with `cargo install --force yazi-build`" ); } generate() } fn generate() -> Result<(), Box<dyn Error>> { Emitter::default() .add_instructions(&BuildBuilder::default().build_date(true).build()?)? .add_instructions(&GitclBuilder::default().commit_date(true).sha(true).build()?)? .emit()?; if env::var_os("YAZI_GEN_COMPLETIONS").is_none() { return Ok(()); } let cmd = &mut args::Args::command(); let bin = "ya"; let out = "completions"; std::fs::create_dir_all(out)?; for sh in [Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] { generate_to(sh, cmd, bin, out)?; } generate_to(clap_complete_nushell::Nushell, cmd, bin, out)?; generate_to(clap_complete_fig::Fig, cmd, bin, out)?; Ok(()) }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/args.rs
yazi-cli/src/args.rs
use std::{borrow::Cow, ffi::OsString}; use anyhow::{Result, bail}; use clap::{Parser, Subcommand}; use yazi_shared::{Either, Id}; #[derive(Parser)] #[command(name = "Ya", about, long_about = None)] pub(super) struct Args { #[command(subcommand)] pub(super) command: Command, /// Print version #[arg(short = 'V', long)] pub(super) version: bool, } #[derive(Subcommand)] pub(super) enum Command { /// Emit a command to be executed by the current instance. Emit(CommandEmit), /// Emit a command to be executed by the specified instance. EmitTo(CommandEmitTo), /// Manage packages. #[command(subcommand)] Pkg(CommandPkg), /// Publish a message to the current instance. Pub(CommandPub), /// Publish a message to the specified instance. PubTo(CommandPubTo), /// Subscribe to messages from all remote instances. Sub(CommandSub), } #[derive(clap::Args)] pub(super) struct CommandEmit { /// Name of the command. pub(super) name: String, /// Arguments of the command. #[arg(allow_hyphen_values = true, trailing_var_arg = true)] pub(super) args: Vec<OsString>, } #[derive(clap::Args)] pub(super) struct CommandEmitTo { /// Receiver ID. pub(super) receiver: Id, /// Name of the command. pub(super) name: String, /// Arguments of the command. #[arg(allow_hyphen_values = true, trailing_var_arg = true)] pub(super) args: Vec<OsString>, } #[derive(Subcommand)] pub(super) enum CommandPkg { /// Add packages. #[command(arg_required_else_help = true)] Add { /// Packages to add. #[arg(index = 1, num_args = 1..)] ids: Vec<String>, }, /// Delete packages. #[command(arg_required_else_help = true)] Delete { /// Packages to delete. #[arg(index = 1, num_args = 1..)] ids: Vec<String>, }, /// Install all packages. Install, /// List all packages. List, /// Upgrade all packages. Upgrade { /// Packages to upgrade, upgrade all if unspecified. #[arg(index = 1, num_args = 0..)] ids: Vec<String>, }, } #[derive(clap::Args)] pub(super) struct CommandPub { /// Kind of message. #[arg(index = 1)] pub(super) kind: String, /// Send the message with a string body. #[arg(long)] pub(super) str: Option<String>, /// Send the message with a JSON body. #[arg(long)] pub(super) json: Option<String>, /// Send the message as a list of strings. #[arg(long, num_args = 0..)] pub(super) list: Vec<String>, } impl CommandPub { #[allow(dead_code)] pub(super) fn receiver() -> Result<Id> { if let Some(s) = std::env::var("YAZI_PID").ok().filter(|s| !s.is_empty()) { Ok(s.parse()?) } else { bail!("No `YAZI_ID` environment variable found.") } } } #[derive(clap::Args)] pub(super) struct CommandPubTo { /// Receiver ID. #[arg(index = 1)] pub(super) receiver: Id, /// Kind of message. #[arg(index = 2)] pub(super) kind: String, /// Send the message with a string body. #[arg(long)] pub(super) str: Option<String>, /// Send the message with a JSON body. #[arg(long)] pub(super) json: Option<String>, /// Send the message as a list of strings. #[arg(long, num_args = 0..)] pub(super) list: Vec<String>, } #[derive(clap::Args)] pub(super) struct CommandSub { /// Kind of messages to subscribe to, separated by commas if multiple. #[arg(index = 1)] pub(super) kinds: String, } // --- Macros macro_rules! impl_emit_body { ($name:ident) => { impl $name { #[allow(dead_code)] pub(super) fn body(self) -> Result<String> { let cmd: Vec<_> = [Either::Left(self.name)] .into_iter() .chain(self.args.into_iter().map(|s| Either::Right(s.into_encoded_bytes()))) .collect(); Ok(serde_json::to_string(&cmd)?) } } }; } macro_rules! impl_pub_body { ($name:ident) => { impl $name { #[allow(dead_code)] pub(super) fn body(&self) -> Result<Cow<'_, str>> { Ok(if let Some(json) = &self.json { json.into() } else if let Some(str) = &self.str { serde_json::to_string(str)?.into() } else if !self.list.is_empty() { serde_json::to_string(&self.list)?.into() } else { "".into() }) } } }; } impl_emit_body!(CommandEmit); impl_emit_body!(CommandEmitTo); impl_pub_body!(CommandPub); impl_pub_body!(CommandPubTo);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/main.rs
yazi-cli/src/main.rs
yazi_macro::mod_pub!(package shared); yazi_macro::mod_flat!(args); use std::process::ExitCode; use clap::Parser; use yazi_macro::{errln, outln}; use yazi_shared::LOCAL_SET; #[tokio::main] async fn main() -> ExitCode { yazi_shared::init(); yazi_fs::init(); match LOCAL_SET.run_until(run()).await { Ok(()) => ExitCode::SUCCESS, Err(e) => { for cause in e.chain() { if let Some(ioerr) = cause.downcast_ref::<std::io::Error>() && ioerr.kind() == std::io::ErrorKind::BrokenPipe { return ExitCode::from(0); } } errln!("{e:#}").ok(); ExitCode::FAILURE } } } async fn run() -> anyhow::Result<()> { if std::env::args_os().nth(1).is_some_and(|s| s == "-V" || s == "--version") { outln!( "Ya {} ({} {})", env!("CARGO_PKG_VERSION"), env!("VERGEN_GIT_SHA"), env!("VERGEN_BUILD_DATE") )?; return Ok(()); } match Args::parse().command { Command::Emit(cmd) => { yazi_boot::init_default(); yazi_dds::init(); if let Err(e) = yazi_dds::Client::shot("dds-emit", CommandPub::receiver()?, &cmd.body()?).await { errln!("Cannot emit command: {e}")?; std::process::exit(1); } } Command::EmitTo(cmd) => { yazi_boot::init_default(); yazi_dds::init(); if let Err(e) = yazi_dds::Client::shot("dds-emit", cmd.receiver, &cmd.body()?).await { errln!("Cannot emit command: {e}")?; std::process::exit(1); } } Command::Pkg(cmd) => { package::init()?; let mut pkg = package::Package::load().await?; match cmd { CommandPkg::Add { ids } => pkg.add_many(&ids).await?, CommandPkg::Delete { ids } => pkg.delete_many(&ids).await?, CommandPkg::Install => pkg.install().await?, CommandPkg::List => pkg.print()?, CommandPkg::Upgrade { ids } => pkg.upgrade_many(&ids).await?, } } Command::Pub(cmd) => { yazi_boot::init_default(); yazi_dds::init(); if let Err(e) = yazi_dds::Client::shot(&cmd.kind, CommandPub::receiver()?, &cmd.body()?).await { errln!("Cannot send message: {e}")?; std::process::exit(1); } } Command::PubTo(cmd) => { yazi_boot::init_default(); yazi_dds::init(); if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, &cmd.body()?).await { errln!("Cannot send message: {e}")?; std::process::exit(1); } } Command::Sub(cmd) => { yazi_boot::init_default(); yazi_dds::init(); yazi_dds::Client::draw(cmd.kinds.split(',').collect()).await?; tokio::signal::ctrl_c().await?; } } Ok(()) }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/dependency.rs
yazi-cli/src/package/dependency.rs
use std::{io::BufWriter, path::{Path, PathBuf}, str::FromStr}; use anyhow::{Result, bail}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use twox_hash::XxHash3_128; use yazi_fs::Xdg; use yazi_macro::ok_or_not_found; use yazi_shared::BytesExt; #[derive(Clone, Default)] pub(crate) struct Dependency { pub(crate) r#use: String, // owner/repo:child pub(crate) name: String, // child.yazi pub(crate) parent: String, // owner/repo pub(crate) child: String, // child.yazi pub(crate) rev: String, pub(crate) hash: String, pub(super) is_flavor: bool, } impl Dependency { pub(super) fn local(&self) -> PathBuf { Xdg::state_dir() .join("packages") .join(format!("{:x}", XxHash3_128::oneshot(self.remote().as_bytes()))) } pub(super) fn remote(&self) -> String { // Support more Git hosting services in the future format!("https://github.com/{}.git", self.parent) } pub(super) fn target(&self) -> PathBuf { if self.is_flavor { Xdg::config_dir().join(format!("flavors/{}", self.name)) } else { Xdg::config_dir().join(format!("plugins/{}", self.name)) } } pub(super) fn identical(&self, other: &Self) -> bool { self.parent == other.parent && self.child == other.child } pub(super) fn header(&self, s: &str) -> Result<()> { use crossterm::style::{Attribute, Print, SetAttributes}; crossterm::execute!( BufWriter::new(std::io::stdout()), Print("\n"), SetAttributes(Attribute::Reverse.into()), SetAttributes(Attribute::Bold.into()), Print(" "), Print(s.replacen("{name}", &self.name, 1)), Print(" "), SetAttributes(Attribute::Reset.into()), Print("\n\n"), )?; Ok(()) } pub(super) async fn plugin_files(dir: &Path) -> std::io::Result<Vec<String>> { let mut it = ok_or_not_found!(tokio::fs::read_dir(dir).await, return Ok(vec![])); let mut files: Vec<String> = ["LICENSE", "README.md", "main.lua"].into_iter().map(Into::into).collect(); while let Some(entry) = it.next_entry().await? { if let Ok(name) = entry.file_name().into_string() && let Some(stripped) = name.strip_suffix(".lua") && stripped != "main" && stripped.as_bytes().kebab_cased() { files.push(name); } } files.sort_unstable(); Ok(files) } pub(super) fn flavor_files() -> Vec<String> { ["LICENSE", "LICENSE-tmtheme", "README.md", "flavor.toml", "preview.png", "tmtheme.xml"] .into_iter() .map(Into::into) .collect() } } impl FromStr for Dependency { type Err = anyhow::Error; fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { let mut parts = s.splitn(2, ':'); let Some(parent) = parts.next() else { bail!("Package URL cannot be empty") }; let child = parts.next().unwrap_or_default(); let Some((_, repo)) = parent.split_once('/') else { bail!("Package URL `{parent}` must be in the format `owner/repository`") }; let name = if child.is_empty() { repo } else { child }; if !name.as_bytes().kebab_cased() { bail!("Package name `{name}` must be in kebab-case") } Ok(Self { r#use: s.to_owned(), name: format!("{name}.yazi"), parent: format!("{parent}{}", if child.is_empty() { ".yazi" } else { "" }), child: if child.is_empty() { String::new() } else { format!("{child}.yazi") }, ..Default::default() }) } } impl<'de> Deserialize<'de> for Dependency { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de>, { #[derive(Deserialize)] struct Shadow { r#use: String, #[serde(default)] rev: String, #[serde(default)] hash: String, } let outer = Shadow::deserialize(deserializer)?; Ok(Self { rev: outer.rev, hash: outer.hash, ..Self::from_str(&outer.r#use).map_err(serde::de::Error::custom)? }) } } impl Serialize for Dependency { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer, { #[derive(Serialize)] struct Shadow<'a> { r#use: &'a str, rev: &'a str, hash: &'a str, } Shadow { r#use: &self.r#use, rev: &self.rev, hash: &self.hash }.serialize(serializer) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/git.rs
yazi-cli/src/package/git.rs
use std::path::Path; use anyhow::{Context, Result, bail}; use tokio::process::Command; use yazi_shared::strip_trailing_newline; pub(super) struct Git; impl Git { pub(super) async fn clone(url: &str, path: &Path) -> Result<()> { Self::exec(|c| c.args(["clone", url]).arg(path)).await } pub(super) async fn fetch(path: &Path) -> Result<()> { Self::exec(|c| c.arg("fetch").current_dir(path)).await } pub(super) async fn checkout(path: &Path, rev: &str) -> Result<()> { Self::exec(|c| c.args(["checkout", rev, "--force"]).current_dir(path)).await } pub(super) async fn pull(path: &Path) -> Result<()> { Self::fetch(path).await?; Self::checkout(path, "origin/HEAD").await?; Ok(()) } pub(super) async fn revision(path: &Path) -> Result<String> { let output = Command::new("git") .args(["rev-parse", "--short", "HEAD"]) .current_dir(path) .output() .await .context("Failed to get current revision")?; if !output.status.success() { bail!("Getting revision failed: {}", output.status); } Ok(strip_trailing_newline( String::from_utf8(output.stdout).context("Failed to parse revision")?, )) } async fn exec(f: impl FnOnce(&mut Command) -> &mut Command) -> Result<()> { let status = f(Command::new("git").args(["-c", "advice.detachedHead=false"])) .status() .await .context("Failed to execute `git` command")?; if !status.success() { bail!("`git` command failed: {status}"); } Ok(()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/deploy.rs
yazi-cli/src/package/deploy.rs
use std::path::{Path, PathBuf}; use anyhow::{Context, Result}; use yazi_fs::provider::{Provider, local::Local}; use yazi_macro::outln; use super::Dependency; use crate::shared::{copy_and_seal, maybe_exists}; impl Dependency { pub(super) async fn deploy(&mut self) -> Result<()> { let from = self.local().join(&self.child); self.header("Deploying package `{name}`")?; self.is_flavor = maybe_exists(&from.join("flavor.toml")).await; let to = self.target(); let exists = maybe_exists(&to).await; if exists { self.hash_check().await?; } Local::regular(&to).create_dir_all().await?; self.delete_assets().await?; let res1 = Self::deploy_assets(from.join("assets"), to.join("assets")).await; let res2 = Self::deploy_sources(&from, &to, self.is_flavor).await; if !exists && (res2.is_err() || res1.is_err()) { self.delete_assets().await?; self.delete_sources().await?; } Local::regular(&to).remove_dir_clean().await; self.hash = self.hash().await?; res2?; res1?; outln!("Done!")?; Ok(()) } async fn deploy_assets(from: PathBuf, to: PathBuf) -> Result<()> { match tokio::fs::read_dir(&from).await { Ok(mut it) => { Local::regular(&to).create_dir_all().await?; while let Some(entry) = it.next_entry().await? { let (src, dist) = (entry.path(), to.join(entry.file_name())); copy_and_seal(&src, &dist).await.with_context(|| { format!("failed to copy `{}` to `{}`", src.display(), dist.display()) })?; } } Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} Err(e) => Err(e).context(format!("failed to read `{}`", from.display()))?, } Ok(()) } async fn deploy_sources(from: &Path, to: &Path, is_flavor: bool) -> Result<()> { let files = if is_flavor { Self::flavor_files() } else { Self::plugin_files(from).await? }; for file in files { let (from, to) = (from.join(&file), to.join(&file)); copy_and_seal(&from, &to) .await .with_context(|| format!("failed to copy `{}` to `{}`", from.display(), to.display()))?; } Ok(()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/install.rs
yazi-cli/src/package/install.rs
use anyhow::Result; use super::{Dependency, Git}; use crate::shared::must_exists; impl Dependency { pub(super) async fn install(&mut self) -> Result<()> { self.header("Fetching package `{name}`")?; let path = self.local(); if must_exists(&path).await { Git::fetch(&path).await?; } else { Git::clone(&self.remote(), &path).await?; }; if !self.rev.is_empty() { Git::checkout(&path, self.rev.trim_start_matches('=')).await?; } self.deploy().await?; if self.rev.is_empty() { self.rev = Git::revision(&path).await?; } Ok(()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/upgrade.rs
yazi-cli/src/package/upgrade.rs
use anyhow::Result; use super::Dependency; impl Dependency { pub(super) async fn upgrade(&mut self) -> Result<()> { if self.rev.starts_with('=') { Ok(()) } else { self.add().await } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/mod.rs
yazi-cli/src/package/mod.rs
yazi_macro::mod_flat!(add delete dependency deploy git hash install package upgrade); use anyhow::Context; use yazi_fs::Xdg; pub(super) fn init() -> anyhow::Result<()> { let packages_dir = Xdg::state_dir().join("packages"); std::fs::create_dir_all(&packages_dir) .with_context(|| format!("failed to create packages directory: {packages_dir:?}"))?; let config_dir = Xdg::config_dir(); std::fs::create_dir_all(&config_dir) .with_context(|| format!("failed to create config directory: {config_dir:?}"))?; Ok(()) }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/hash.rs
yazi-cli/src/package/hash.rs
use anyhow::{Context, Result, bail}; use twox_hash::XxHash3_128; use yazi_fs::provider::local::Local; use yazi_macro::ok_or_not_found; use super::Dependency; impl Dependency { pub(crate) async fn hash(&self) -> Result<String> { let dir = self.target(); let files = if self.is_flavor { Self::flavor_files() } else { Self::plugin_files(&dir).await? }; let mut h = XxHash3_128::new(); for file in files { h.write(file.as_bytes()); h.write(b"VpvFw9Atb7cWGOdqhZCra634CcJJRlsRl72RbZeV0vpG1\0"); h.write(&ok_or_not_found!(Local::regular(&dir.join(file)).read().await)); } let mut assets = vec![]; match tokio::fs::read_dir(dir.join("assets")).await { Ok(mut it) => { while let Some(entry) = it.next_entry().await? { let Ok(name) = entry.file_name().into_string() else { bail!("asset path is not valid UTF-8: {}", entry.path().display()); }; assets.push((name, Local::regular(&entry.path()).read().await?)); } } Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} Err(e) => Err(e).context(format!("failed to read `{}`", dir.join("assets").display()))?, } assets.sort_unstable_by(|(a, _), (b, _)| a.cmp(b)); for (name, data) in assets { h.write(name.as_bytes()); h.write(b"pQU2in0xcsu97Y77Nuq2LnT8mczMlFj22idcYRmMrglqU\0"); h.write(&data); } Ok(format!("{:x}", h.finish_128())) } pub(super) async fn hash_check(&self) -> Result<()> { if self.hash != self.hash().await? { bail!( "You have modified the contents of the `{}` {}. For safety, the operation has been aborted. Please manually delete it from `{}` and re-run the command.", self.name, if self.is_flavor { "flavor" } else { "plugin" }, self.target().display() ); } Ok(()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/package.rs
yazi-cli/src/package/package.rs
use std::{path::PathBuf, str::FromStr}; use anyhow::{Context, Result, bail}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use yazi_fs::{Xdg, provider::{Provider, local::Local}}; use yazi_macro::{ok_or_not_found, outln}; use super::Dependency; #[derive(Default)] pub(crate) struct Package { pub(crate) plugins: Vec<Dependency>, pub(crate) flavors: Vec<Dependency>, } impl Package { pub(crate) async fn load() -> Result<Self> { let s = ok_or_not_found!(Local::regular(&Self::toml()).read_to_string().await); Ok(toml::from_str(&s)?) } pub(crate) async fn add_many(&mut self, uses: &[String]) -> Result<()> { for u in uses { let r = self.add(u).await; self.save().await?; r?; } Ok(()) } pub(crate) async fn delete_many(&mut self, uses: &[String]) -> Result<()> { for u in uses { let r = self.delete(u).await; self.save().await?; r?; } Ok(()) } pub(crate) async fn install(&mut self) -> Result<()> { macro_rules! go { ($dep:expr) => { let r = $dep.install().await; self.save().await?; r?; }; } for i in 0..self.plugins.len() { go!(self.plugins[i]); } for i in 0..self.flavors.len() { go!(self.flavors[i]); } Ok(()) } pub(crate) async fn upgrade_many(&mut self, uses: &[String]) -> Result<()> { macro_rules! go { ($dep:expr) => { if uses.is_empty() || uses.contains(&$dep.r#use) { let r = $dep.upgrade().await; self.save().await?; r?; } }; } for i in 0..self.plugins.len() { go!(self.plugins[i]); } for i in 0..self.flavors.len() { go!(self.flavors[i]); } Ok(()) } pub(crate) fn print(&self) -> Result<()> { outln!("Plugins:")?; for d in &self.plugins { if d.rev.is_empty() { outln!("\t{}", d.r#use)?; } else { outln!("\t{} ({})", d.r#use, d.rev)?; } } outln!("Flavors:")?; for d in &self.flavors { if d.rev.is_empty() { outln!("\t{}", d.r#use)?; } else { outln!("\t{} ({})", d.r#use, d.rev)?; } } Ok(()) } async fn add(&mut self, r#use: &str) -> Result<()> { let mut dep = Dependency::from_str(r#use)?; if let Some(d) = self.identical(&dep) { bail!( "{} `{}` already exists in package.toml", if d.is_flavor { "Flavor" } else { "Plugin" }, dep.name ) } dep.add().await?; if dep.is_flavor { self.flavors.push(dep); } else { self.plugins.push(dep); } Ok(()) } async fn delete(&mut self, r#use: &str) -> Result<()> { let Some(dep) = self.identical(&Dependency::from_str(r#use)?).cloned() else { bail!("`{}` was not found in package.toml", r#use) }; dep.delete().await?; if dep.is_flavor { self.flavors.retain(|d| !d.identical(&dep)); } else { self.plugins.retain(|d| !d.identical(&dep)); } Ok(()) } async fn save(&self) -> Result<()> { let s = toml::to_string_pretty(self)?; Local::regular(&Self::toml()).write(s).await.context("Failed to write package.toml") } fn toml() -> PathBuf { Xdg::config_dir().join("package.toml") } fn identical(&self, other: &Dependency) -> Option<&Dependency> { self.plugins.iter().chain(&self.flavors).find(|d| d.identical(other)) } } impl<'de> Deserialize<'de> for Package { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de>, { #[derive(Deserialize)] struct Outer { #[serde(default)] plugin: Shadow, #[serde(default)] flavor: Shadow, } #[derive(Default, Deserialize)] struct Shadow { deps: Vec<Dependency>, } let mut outer = Outer::deserialize(deserializer)?; outer.flavor.deps.iter_mut().for_each(|d| d.is_flavor = true); Ok(Self { plugins: outer.plugin.deps, flavors: outer.flavor.deps }) } } impl Serialize for Package { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer, { #[derive(Serialize)] struct Outer<'a> { plugin: Shadow<'a>, flavor: Shadow<'a>, } #[derive(Serialize)] struct Shadow<'a> { deps: &'a [Dependency], } Outer { plugin: Shadow { deps: &self.plugins }, flavor: Shadow { deps: &self.flavors } } .serialize(serializer) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/add.rs
yazi-cli/src/package/add.rs
use anyhow::Result; use super::{Dependency, Git}; use crate::shared::must_exists; impl Dependency { pub(super) async fn add(&mut self) -> Result<()> { self.header("Upgrading package `{name}`")?; let path = self.local(); if must_exists(&path).await { Git::pull(&path).await?; } else { Git::clone(&self.remote(), &path).await?; }; self.deploy().await?; self.rev = Git::revision(&path).await?; Ok(()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/package/delete.rs
yazi-cli/src/package/delete.rs
use anyhow::{Context, Result}; use yazi_fs::{ok_or_not_found, provider::{Provider, local::Local}}; use yazi_macro::outln; use super::Dependency; use crate::shared::{maybe_exists, remove_sealed}; impl Dependency { pub(super) async fn delete(&self) -> Result<()> { self.header("Deleting package `{name}`")?; let dir = self.target(); if !maybe_exists(&dir).await { return Ok(outln!("Not found, skipping")?); } self.hash_check().await?; self.delete_assets().await?; self.delete_sources().await?; Ok(()) } pub(super) async fn delete_assets(&self) -> Result<()> { let assets = self.target().join("assets"); match tokio::fs::read_dir(&assets).await { Ok(mut it) => { while let Some(entry) = it.next_entry().await? { remove_sealed(&entry.path()) .await .with_context(|| format!("failed to remove `{}`", entry.path().display()))?; } } Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} Err(e) => Err(e).context(format!("failed to read `{}`", assets.display()))?, }; Local::regular(&assets).remove_dir_clean().await; Ok(()) } pub(super) async fn delete_sources(&self) -> Result<()> { let dir = self.target(); let files = if self.is_flavor { Self::flavor_files() } else { Self::plugin_files(&dir).await? }; for path in files.iter().map(|s| dir.join(s)) { ok_or_not_found(remove_sealed(&path).await) .with_context(|| format!("failed to delete `{}`", path.display()))?; } if ok_or_not_found(Local::regular(&dir).remove_dir().await).is_ok() { outln!("Done!")?; } else { outln!( "Done! For safety, user data has been preserved, please manually delete them within: {}", dir.display() )?; } Ok(()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/shared/mod.rs
yazi-cli/src/shared/mod.rs
yazi_macro::mod_flat!(shared);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-cli/src/shared/shared.rs
yazi-cli/src/shared/shared.rs
use std::{io, path::Path}; use tokio::io::AsyncWriteExt; use yazi_fs::provider::{FileBuilder, Provider, local::{Gate, Local}}; use yazi_macro::ok_or_not_found; #[inline] pub async fn must_exists(path: impl AsRef<Path>) -> bool { Local::regular(&path).symlink_metadata().await.is_ok() } #[inline] pub async fn maybe_exists(path: impl AsRef<Path>) -> bool { match Local::regular(&path).symlink_metadata().await { Ok(_) => true, Err(e) => e.kind() != std::io::ErrorKind::NotFound, } } pub async fn copy_and_seal(from: &Path, to: &Path) -> io::Result<()> { let b = Local::regular(from).read().await?; ok_or_not_found!(remove_sealed(to).await); let mut file = Gate::default().create_new(true).write(true).truncate(true).open(to).await?; file.write_all(&b).await?; let mut perm = file.metadata().await?.permissions(); perm.set_readonly(true); file.set_permissions(perm).await?; Ok(()) } pub async fn remove_sealed(p: &Path) -> io::Result<()> { #[cfg(windows)] { let mut perm = tokio::fs::metadata(p).await?.permissions(); perm.set_readonly(false); tokio::fs::set_permissions(p, perm).await?; } Local::regular(p).remove_file().await }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-shim/src/lib.rs
yazi-shim/src/lib.rs
yazi_macro::mod_flat!(twox);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-shim/src/twox.rs
yazi-shim/src/twox.rs
use std::hash::Hasher; pub struct Twox128(twox_hash::XxHash3_128); impl Default for Twox128 { fn default() -> Self { Self(twox_hash::XxHash3_128::new()) } } impl Twox128 { pub fn finish_128(self) -> u128 { self.0.finish_128() } } impl Hasher for Twox128 { fn write(&mut self, bytes: &[u8]) { self.0.write(bytes) } fn finish(&self) -> u64 { unimplemented!() } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-scheduler/src/ongoing.rs
yazi-scheduler/src/ongoing.rs
use hashbrown::{HashMap, hash_map::RawEntryMut}; use ordered_float::OrderedFloat; use yazi_config::YAZI; use yazi_parser::app::TaskSummary; use yazi_shared::{CompletionToken, Id, Ids}; use super::Task; use crate::{TaskIn, TaskProg}; #[derive(Default)] pub struct Ongoing { inner: HashMap<Id, Task>, } impl Ongoing { pub(super) fn add<T>(&mut self, name: String) -> &mut Task where T: Into<TaskProg> + Default, { static IDS: Ids = Ids::new(); let id = IDS.next(); self.inner.entry(id).insert(Task::new::<T>(id, name)).into_mut() } pub(super) fn cancel(&mut self, id: Id) -> Option<TaskIn> { match self.inner.raw_entry_mut().from_key(&id) { RawEntryMut::Occupied(mut oe) => { let task = oe.get_mut(); task.done.complete(false); if let Some(hook) = task.hook.take() { return Some(hook); } oe.remove(); } RawEntryMut::Vacant(_) => {} } None } pub(super) fn fulfill(&mut self, id: Id) -> Option<Task> { let task = self.inner.remove(&id)?; task.done.complete(true); Some(task) } #[inline] pub fn get_mut(&mut self, id: Id) -> Option<&mut Task> { self.inner.get_mut(&id) } pub fn get_id(&self, idx: usize) -> Option<Id> { self.values().nth(idx).map(|t| t.id) } #[inline] pub fn get_token(&self, id: Id) -> Option<CompletionToken> { self.inner.get(&id).map(|t| t.done.clone()) } pub fn len(&self) -> usize { if YAZI.tasks.suppress_preload { self.inner.values().filter(|&t| t.prog.is_user()).count() } else { self.inner.len() } } #[inline] pub fn exists(&self, id: Id) -> bool { self.inner.contains_key(&id) } #[inline] pub fn intact(&self, id: Id) -> bool { self.inner.get(&id).is_some_and(|t| t.done.completed() != Some(false)) } pub fn values(&self) -> Box<dyn Iterator<Item = &Task> + '_> { if YAZI.tasks.suppress_preload { Box::new(self.inner.values().filter(|&t| t.prog.is_user())) } else { Box::new(self.inner.values()) } } #[inline] pub fn is_empty(&self) -> bool { self.len() == 0 } pub fn summary(&self) -> TaskSummary { let mut summary = TaskSummary::default(); let mut percent_sum = 0.0f64; let mut percent_count = 0; for task in self.values() { let s: TaskSummary = task.prog.into(); if s.total == 0 && !task.prog.failed() { continue; } summary.total += 1; if let Some(p) = s.percent { percent_sum += p.0 as f64; percent_count += 1; } if task.prog.running() { continue; } else if task.prog.success() { summary.success += 1; } else { summary.failed += 1; } } summary.percent = if percent_count == 0 { None } else { Some(OrderedFloat((percent_sum / percent_count as f64) as f32)) }; summary } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-scheduler/src/op.rs
yazi-scheduler/src/op.rs
use tokio::sync::mpsc; use yazi_shared::Id; use crate::TaskOut; #[derive(Debug)] pub(crate) struct TaskOp { pub(crate) id: Id, pub(crate) out: TaskOut, } // --- Ops #[derive(Clone)] pub struct TaskOps(pub(super) mpsc::UnboundedSender<TaskOp>); impl From<&mpsc::UnboundedSender<TaskOp>> for TaskOps { fn from(tx: &mpsc::UnboundedSender<TaskOp>) -> Self { Self(tx.clone()) } } impl TaskOps { #[inline] pub(crate) fn out(&self, id: Id, out: impl Into<TaskOut>) { _ = self.0.send(TaskOp { id, out: out.into() }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-scheduler/src/lib.rs
yazi-scheduler/src/lib.rs
mod macros; yazi_macro::mod_pub!(file hook plugin prework process); yazi_macro::mod_flat!(ongoing op out progress r#in runner scheduler snap task); const LOW: u8 = yazi_config::Priority::Low as u8; const NORMAL: u8 = yazi_config::Priority::Normal as u8; const HIGH: u8 = yazi_config::Priority::High as u8;
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-scheduler/src/runner.rs
yazi-scheduler/src/runner.rs
use std::sync::Arc; use crate::{TaskIn, TaskOut, file::File, hook::Hook, plugin::Plugin, prework::Prework, process::Process}; #[derive(Clone)] pub struct Runner { pub(super) file: Arc<File>, pub(super) plugin: Arc<Plugin>, pub prework: Arc<Prework>, pub(super) process: Arc<Process>, pub(super) hook: Arc<Hook>, } impl Runner { pub(super) async fn micro(&self, r#in: TaskIn) -> Result<(), TaskOut> { match r#in { // File TaskIn::FileCopy(r#in) => self.file.copy(r#in).await.map_err(Into::into), TaskIn::FileCut(r#in) => self.file.cut(r#in).await.map_err(Into::into), TaskIn::FileLink(r#in) => self.file.link(r#in).await.map_err(Into::into), TaskIn::FileHardlink(r#in) => self.file.hardlink(r#in).await.map_err(Into::into), TaskIn::FileDelete(r#in) => self.file.delete(r#in).await.map_err(Into::into), TaskIn::FileTrash(r#in) => self.file.trash(r#in).await.map_err(Into::into), TaskIn::FileDownload(r#in) => self.file.download(r#in).await.map_err(Into::into), TaskIn::FileUpload(r#in) => self.file.upload(r#in).await.map_err(Into::into), // Plugin TaskIn::PluginEntry(r#in) => self.plugin.entry(r#in).await.map_err(Into::into), // Prework TaskIn::PreworkFetch(r#in) => self.prework.fetch(r#in).await.map_err(Into::into), TaskIn::PreworkLoad(r#in) => self.prework.load(r#in).await.map_err(Into::into), TaskIn::PreworkSize(r#in) => self.prework.size(r#in).await.map_err(Into::into), // Process TaskIn::ProcessBlock(r#in) => self.process.block(r#in).await.map_err(Into::into), TaskIn::ProcessOrphan(r#in) => self.process.orphan(r#in).await.map_err(Into::into), TaskIn::ProcessBg(r#in) => self.process.bg(r#in).await.map_err(Into::into), // Hook TaskIn::HookCopy(r#in) => Ok(self.hook.copy(r#in).await), TaskIn::HookCut(r#in) => Ok(self.hook.cut(r#in).await), TaskIn::HookDelete(r#in) => Ok(self.hook.delete(r#in).await), TaskIn::HookTrash(r#in) => Ok(self.hook.trash(r#in).await), TaskIn::HookDownload(r#in) => Ok(self.hook.download(r#in).await), } } pub(super) async fn r#macro(&self, r#in: TaskIn) -> Result<(), TaskOut> { match r#in { // File TaskIn::FileCopy(r#in) => self.file.copy_do(r#in).await.map_err(Into::into), TaskIn::FileCut(r#in) => self.file.cut_do(r#in).await.map_err(Into::into), TaskIn::FileLink(r#in) => self.file.link_do(r#in).await.map_err(Into::into), TaskIn::FileHardlink(r#in) => self.file.hardlink_do(r#in).await.map_err(Into::into), TaskIn::FileDelete(r#in) => self.file.delete_do(r#in).await.map_err(Into::into), TaskIn::FileTrash(r#in) => self.file.trash_do(r#in).await.map_err(Into::into), TaskIn::FileDownload(r#in) => self.file.download_do(r#in).await.map_err(Into::into), TaskIn::FileUpload(r#in) => self.file.upload_do(r#in).await.map_err(Into::into), // Plugin TaskIn::PluginEntry(r#in) => self.plugin.entry_do(r#in).await.map_err(Into::into), // Prework TaskIn::PreworkFetch(r#in) => self.prework.fetch_do(r#in).await.map_err(Into::into), TaskIn::PreworkLoad(r#in) => self.prework.load_do(r#in).await.map_err(Into::into), TaskIn::PreworkSize(r#in) => self.prework.size_do(r#in).await.map_err(Into::into), // Process TaskIn::ProcessBlock(_in) => unreachable!(), TaskIn::ProcessOrphan(_in) => unreachable!(), TaskIn::ProcessBg(_in) => unreachable!(), // Hook TaskIn::HookCopy(_in) => unreachable!(), TaskIn::HookCut(_in) => unreachable!(), TaskIn::HookDelete(_in) => unreachable!(), TaskIn::HookTrash(_in) => unreachable!(), TaskIn::HookDownload(_in) => unreachable!(), } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false