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-actor/src/mgr/search.rs
yazi-actor/src/mgr/search.rs
use std::{borrow::Cow, time::Duration}; use anyhow::Result; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; use yazi_config::popup::InputCfg; use yazi_fs::{FilesOp, cha::Cha}; use yazi_macro::{act, succ}; use yazi_parser::{VoidOpt, mgr::{CdSource, SearchOpt, SearchOptVia}}; use yazi_plugin::external; use yazi_proxy::{AppProxy, InputProxy, MgrProxy}; use yazi_shared::{data::Data, url::UrlLike}; use crate::{Actor, Ctx}; pub struct Search; impl Actor for Search { type Options = SearchOpt; const NAME: &str = "search"; fn act(cx: &mut Ctx, mut opt: Self::Options) -> Result<Data> { if let Some(handle) = cx.tab_mut().search.take() { handle.abort(); } let mut input = InputProxy::show(InputCfg::search(opt.via.into_str()).with_value(&*opt.subject)); tokio::spawn(async move { if let Some(Ok(subject)) = input.recv().await { opt.subject = Cow::Owned(subject); MgrProxy::search_do(opt); } }); succ!(); } } // --- Do pub struct SearchDo; impl Actor for SearchDo { type Options = SearchOpt; const NAME: &str = "search_do"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let tab = cx.tab_mut(); if let Some(handle) = tab.search.take() { handle.abort(); } let hidden = tab.pref.show_hidden; let Ok(cwd) = tab.cwd().to_search(&opt.subject) else { succ!(AppProxy::notify_warn("Search", "Only local filesystem searches are supported")); }; tab.search = Some(tokio::spawn(async move { let rx = match opt.via { SearchOptVia::Rg => external::rg(external::RgOpt { cwd: cwd.clone(), hidden, subject: opt.subject.into_owned(), args: opt.args, }), SearchOptVia::Rga => external::rga(external::RgaOpt { cwd: cwd.clone(), hidden, subject: opt.subject.into_owned(), args: opt.args, }), SearchOptVia::Fd => external::fd(external::FdOpt { cwd: cwd.clone(), hidden, subject: opt.subject.into_owned(), args: opt.args, }), }?; let rx = UnboundedReceiverStream::new(rx).chunks_timeout(5000, Duration::from_millis(500)); pin!(rx); let ((), ticket) = (MgrProxy::cd(&cwd), FilesOp::prepare(&cwd)); while let Some(chunk) = rx.next().await { FilesOp::Part(cwd.clone(), chunk, ticket).emit(); } FilesOp::Done(cwd, Cha::default(), ticket).emit(); Ok(()) })); succ!(); } } // --- Stop pub struct SearchStop; impl Actor for SearchStop { type Options = VoidOpt; const NAME: &str = "search_stop"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { let tab = cx.tab_mut(); if let Some(handle) = tab.search.take() { handle.abort(); } if tab.cwd().is_search() { act!(mgr:cd, cx, (tab.cwd().to_regular()?, CdSource::Escape))?; } succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/find.rs
yazi-actor/src/mgr/find.rs
use std::time::Duration; use anyhow::Result; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; use yazi_config::popup::InputCfg; use yazi_macro::succ; use yazi_parser::mgr::{FindDoOpt, FindOpt}; use yazi_proxy::{InputProxy, MgrProxy}; use yazi_shared::{Debounce, data::Data, errors::InputError}; use crate::{Actor, Ctx}; pub struct Find; impl Actor for Find { type Options = FindOpt; const NAME: &str = "find"; fn act(_: &mut Ctx, opt: Self::Options) -> Result<Data> { let input = InputProxy::show(InputCfg::find(opt.prev)); tokio::spawn(async move { let rx = Debounce::new(UnboundedReceiverStream::new(input), Duration::from_millis(50)); pin!(rx); while let Some(Ok(s)) | Some(Err(InputError::Typed(s))) = rx.next().await { MgrProxy::find_do(FindDoOpt { query: s.into(), prev: opt.prev, case: opt.case }); } }); succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/back.rs
yazi-actor/src/mgr/back.rs
use anyhow::Result; use yazi_macro::{act, succ}; use yazi_parser::{VoidOpt, mgr::CdSource}; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Back; impl Actor for Back { type Options = VoidOpt; const NAME: &str = "back"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { if let Some(u) = cx.tab_mut().backstack.shift_backward().cloned() { act!(mgr:cd, cx, (u, CdSource::Back))?; } succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/quit.rs
yazi-actor/src/mgr/quit.rs
use std::time::Duration; use anyhow::Result; use tokio::{select, time}; use yazi_config::popup::ConfirmCfg; use yazi_dds::spark::SparkKind; use yazi_macro::{emit, succ}; use yazi_parser::mgr::QuitOpt; use yazi_proxy::ConfirmProxy; use yazi_shared::{data::Data, event::EventQuit, strand::{Strand, StrandLike, ToStrandJoin}, url::AsUrl}; use crate::{Actor, Ctx}; pub struct Quit; impl Actor for Quit { type Options = QuitOpt; const NAME: &str = "quit"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let event = opt.into(); let ongoing = cx.tasks().ongoing().clone(); let (left, left_names) = { let ongoing = ongoing.lock(); (ongoing.len(), ongoing.values().take(11).map(|t| t.name.clone()).collect()) }; if left == 0 { succ!(emit!(Quit(event))); } tokio::spawn(async move { let mut i = 0; let mut rx = ConfirmProxy::show_rx(ConfirmCfg::quit(left, left_names)); loop { select! { _ = time::sleep(Duration::from_millis(50)) => { i += 1; if i > 40 { break } else if ongoing.lock().is_empty() { emit!(Quit(event)); return; } } b = &mut rx => { if b.unwrap_or(false) { emit!(Quit(event)); } return; } } } if rx.await.unwrap_or(false) { emit!(Quit(event)); } }); succ!(); } fn hook(cx: &Ctx, _opt: &Self::Options) -> Option<SparkKind> { Some(SparkKind::KeyQuit).filter(|_| cx.source().is_key()) } } impl Quit { pub(super) fn with_selected<I>(selected: I) where I: IntoIterator, I::Item: AsUrl, { let paths = selected.into_iter().join(Strand::Utf8("\n")); if !paths.is_empty() { emit!(Quit(EventQuit { selected: Some(paths), ..Default::default() })); } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/find_arrow.rs
yazi-actor/src/mgr/find_arrow.rs
use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_parser::mgr::FindArrowOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct FindArrow; impl Actor for FindArrow { type Options = FindArrowOpt; const NAME: &str = "find_arrow"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let tab = cx.tab_mut(); let Some(finder) = &mut tab.finder else { succ!() }; render!(finder.catchup(&tab.current)); let offset = if opt.prev { finder.prev(&tab.current.files, tab.current.cursor, false) } else { finder.next(&tab.current.files, tab.current.cursor, false) }; if let Some(offset) = offset { act!(mgr:arrow, cx, offset)?; } succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/watch.rs
yazi-actor/src/mgr/watch.rs
use std::iter; use anyhow::Result; use yazi_macro::succ; use yazi_parser::VoidOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Watch; impl Actor for Watch { type Options = VoidOpt; const NAME: &str = "watch"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { let it = iter::once(cx.core.mgr.tabs.active().cwd()) .chain(cx.core.mgr.tabs.parent().map(|p| &p.url)) .chain(cx.core.mgr.tabs.hovered().filter(|h| h.is_dir()).map(|h| &h.url)); cx.core.mgr.watcher.watch(it); succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/copy.rs
yazi-actor/src/mgr/copy.rs
use anyhow::{Result, bail}; use yazi_macro::{act, succ}; use yazi_parser::mgr::CopyOpt; use yazi_shared::{data::Data, strand::ToStrand, url::UrlLike}; use yazi_widgets::CLIPBOARD; use crate::{Actor, Ctx}; pub struct Copy; impl Actor for Copy { type Options = CopyOpt; const NAME: &str = "copy"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { act!(mgr:escape_visual, cx)?; let mut s = Vec::<u8>::new(); let mut it = if opt.hovered { Box::new(cx.hovered().map(|h| &h.url).into_iter()) } else { cx.tab().selected_or_hovered() } .peekable(); while let Some(u) = it.next() { match opt.r#type.as_ref() { // TODO: rename to "url" "path" => { s.extend_from_slice(&opt.separator.transform(&u.to_strand())); } "dirname" => { if let Some(p) = u.parent() { s.extend_from_slice(&opt.separator.transform(&p.to_strand())); } } "filename" => { s.extend_from_slice(&opt.separator.transform(&u.name().unwrap_or_default())); } "name_without_ext" => { s.extend_from_slice(&opt.separator.transform(&u.stem().unwrap_or_default())); } _ => bail!("Unknown copy type: {}", opt.r#type), }; if it.peek().is_some() { s.push(b'\n'); } } // Copy the CWD path regardless even if the directory is empty if s.is_empty() && opt.r#type == "dirname" { s.extend_from_slice(&opt.separator.transform(&cx.cwd().to_strand())); } futures::executor::block_on(CLIPBOARD.set(s)); succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/paste.rs
yazi-actor/src/mgr/paste.rs
use anyhow::Result; use yazi_macro::{act, succ}; use yazi_parser::mgr::PasteOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Paste; impl Actor for Paste { type Options = PasteOpt; const NAME: &str = "paste"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let mgr = &mut cx.core.mgr; let tab = &mgr.tabs[cx.tab]; let dest = tab.cwd(); if mgr.yanked.cut { cx.core.tasks.file_cut(&mgr.yanked, dest, opt.force); mgr.tabs.iter_mut().for_each(|t| _ = t.selected.remove_many(mgr.yanked.iter())); act!(mgr:unyank, cx) } else { succ!(cx.core.tasks.file_copy(&mgr.yanked, dest, opt.force, opt.follow)); } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/upload.rs
yazi-actor/src/mgr/upload.rs
use anyhow::Result; use yazi_macro::succ; use yazi_parser::mgr::UploadOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Upload; impl Actor for Upload { type Options = UploadOpt; const NAME: &str = "upload"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { for url in opt.urls { cx.tasks.scheduler.file_upload(url.into_owned()); } succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/displace.rs
yazi-actor/src/mgr/displace.rs
use anyhow::Result; use yazi_macro::succ; use yazi_parser::{VoidOpt, mgr::DisplaceDoOpt}; use yazi_proxy::MgrProxy; use yazi_shared::{data::Data, url::UrlLike}; use yazi_vfs::provider; use crate::{Actor, Ctx}; pub struct Displace; impl Actor for Displace { type Options = VoidOpt; const NAME: &str = "displace"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { if cx.cwd().is_absolute() { succ!(); } let tab = cx.tab().id; let from = cx.cwd().to_owned(); tokio::spawn(async move { MgrProxy::displace_do(tab, DisplaceDoOpt { to: provider::canonicalize(&from).await, from }); }); succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/mod.rs
yazi-actor/src/mgr/mod.rs
yazi_macro::mod_flat!( arrow back bulk_rename cd close copy create displace displace_do download enter escape filter filter_do find find_arrow find_do follow forward hardlink hidden hover leave linemode link open open_do paste peek quit refresh remove rename reveal search seek shell sort spot stash suspend tab_close tab_create tab_swap tab_switch toggle toggle_all unyank update_files update_mimes update_paged update_peeked update_spotted update_yanked upload visual_mode watch yank );
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/visual_mode.rs
yazi-actor/src/mgr/visual_mode.rs
use std::collections::BTreeSet; use anyhow::Result; use yazi_core::tab::Mode; use yazi_macro::{render, succ}; use yazi_parser::mgr::VisualModeOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct VisualMode; impl Actor for VisualMode { type Options = VisualModeOpt; const NAME: &str = "visual_mode"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let tab = cx.tab_mut(); let idx = tab.current.cursor; if opt.unset { tab.mode = Mode::Unset(idx, BTreeSet::from([idx])); } else { tab.mode = Mode::Select(idx, BTreeSet::from([idx])); }; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/find_do.rs
yazi-actor/src/mgr/find_do.rs
use anyhow::Result; use yazi_core::tab::Finder; use yazi_macro::{act, render, succ}; use yazi_parser::mgr::FindDoOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct FindDo; impl Actor for FindDo { type Options = FindDoOpt; const NAME: &str = "find_do"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { if opt.query.is_empty() { return act!(mgr:escape_find, cx); } let finder = Finder::new(&opt.query, opt.case)?; if matches!(&cx.tab().finder, Some(f) if f.filter == finder.filter) { succ!(); } let step = if opt.prev { finder.prev(&cx.current().files, cx.current().cursor, true) } else { finder.next(&cx.current().files, cx.current().cursor, true) }; if let Some(step) = step { act!(mgr:arrow, cx, step)?; } cx.tab_mut().finder = Some(finder); succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/enter.rs
yazi-actor/src/mgr/enter.rs
use anyhow::Result; use yazi_macro::{act, succ}; use yazi_parser::{VoidOpt, mgr::CdSource}; use yazi_shared::{data::Data, url::UrlLike}; use crate::{Actor, Ctx}; pub struct Enter; impl Actor for Enter { type Options = VoidOpt; const NAME: &str = "enter"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { let Some(h) = cx.hovered().filter(|h| h.is_dir()) else { succ!() }; let url = if h.url.is_search() { h.url.to_regular()? } else { h.url.clone() }; act!(mgr:cd, cx, (url, CdSource::Enter)) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/unyank.rs
yazi-actor/src/mgr/unyank.rs
use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_parser::VoidOpt; use yazi_shared::data::Data; use crate::Actor; pub struct Unyank; impl Actor for Unyank { type Options = VoidOpt; const NAME: &str = "unyank"; fn act(cx: &mut crate::Ctx, _: Self::Options) -> Result<Data> { let repeek = cx.hovered().is_some_and(|f| f.is_dir() && cx.mgr.yanked.contains_in(&f.url)); cx.mgr.yanked.clear(); render!(cx.mgr.yanked.catchup_revision(false)); if repeek { act!(mgr:peek, cx, true)?; } succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/tab_create.rs
yazi-actor/src/mgr/tab_create.rs
use anyhow::Result; use yazi_core::tab::Tab; use yazi_macro::{act, render, succ}; use yazi_parser::mgr::{CdSource, TabCreateOpt}; use yazi_proxy::AppProxy; use yazi_shared::{data::Data, url::UrlLike}; use crate::{Actor, Ctx}; const MAX_TABS: usize = 9; pub struct TabCreate; impl Actor for TabCreate { type Options = TabCreateOpt; const NAME: &str = "tab_create"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { if cx.tabs().len() >= MAX_TABS { succ!(AppProxy::notify_warn( "Too many tabs", "You can only open up to 9 tabs at the same time." )); } let mut tab = Tab::default(); let (cd, url) = if let Some(wd) = opt.url { (true, wd.into_owned()) } else if let Some(h) = cx.hovered() { tab.pref = cx.tab().pref.clone(); (false, h.url.clone()) } else if cx.cwd().is_search() { tab.pref = cx.tab().pref.clone(); (true, cx.cwd().to_regular()?) } else { tab.pref = cx.tab().pref.clone(); (true, cx.cwd().clone()) }; let tabs = &mut cx.mgr.tabs; tabs.items.insert(tabs.cursor + 1, tab); tabs.set_idx(tabs.cursor + 1); let cx = &mut Ctx::renew(cx); if cd { act!(mgr:cd, cx, (url, CdSource::Tab))?; } else { act!(mgr:reveal, cx, (url, CdSource::Tab))?; } act!(mgr:refresh, cx)?; act!(mgr:peek, cx, true)?; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/hidden.rs
yazi-actor/src/mgr/hidden.rs
use anyhow::Result; use yazi_core::tab::Folder; use yazi_fs::FolderStage; use yazi_macro::{act, render, render_and, succ}; use yazi_parser::mgr::HiddenOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Hidden; impl Actor for Hidden { type Options = HiddenOpt; const NAME: &str = "hidden"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let state = opt.state.bool(cx.tab().pref.show_hidden); cx.tab_mut().pref.show_hidden = state; let hovered = cx.hovered().map(|f| f.urn().to_owned()); let apply = |f: &mut Folder| { if f.stage == FolderStage::Loading { render!(); false } else { f.files.set_show_hidden(state); render_and!(f.files.catchup_revision()) } }; // Apply to CWD and parent if let (a, Some(b)) = (apply(cx.current_mut()), cx.parent_mut().map(apply)) && (a | b) { act!(mgr:hover, cx)?; act!(mgr:update_paged, cx)?; } // Apply to hovered if let Some(h) = cx.hovered_folder_mut() && apply(h) { render!(h.repos(None)); act!(mgr:peek, cx, true)?; } else if cx.hovered().map(|f| f.urn()) != hovered.as_ref().map(Into::into) { act!(mgr:peek, cx)?; act!(mgr:watch, cx)?; } succ!() } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/update_paged.rs
yazi-actor/src/mgr/update_paged.rs
use anyhow::Result; use yazi_macro::succ; use yazi_parser::mgr::UpdatePagedOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct UpdatePaged; impl Actor for UpdatePaged { type Options = UpdatePagedOpt; const NAME: &str = "update_paged"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { if opt.only_if.is_some_and(|u| u != *cx.cwd()) { succ!(); } let targets = cx.current().paginate(opt.page.unwrap_or(cx.current().page)); if !targets.is_empty() { cx.tasks().fetch_paged(targets, &cx.mgr.mimetype); cx.tasks().preload_paged(targets, &cx.mgr.mimetype); } succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/tab_switch.rs
yazi-actor/src/mgr/tab_switch.rs
use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_parser::mgr::TabSwitchOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct TabSwitch; impl Actor for TabSwitch { type Options = TabSwitchOpt; const NAME: &str = "tab_switch"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let tabs = cx.tabs_mut(); let idx = if opt.relative { opt.step.saturating_add_unsigned(tabs.cursor).rem_euclid(tabs.len() as _) as _ } else { opt.step as usize }; if idx == tabs.cursor || idx >= tabs.len() { succ!(); } tabs.set_idx(idx); let cx = &mut Ctx::renew(cx); act!(mgr:refresh, cx)?; act!(mgr:peek, cx, true)?; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/leave.rs
yazi-actor/src/mgr/leave.rs
use anyhow::Result; use yazi_macro::{act, succ}; use yazi_parser::{VoidOpt, mgr::CdSource}; use yazi_shared::{data::Data, url::UrlLike}; use crate::{Actor, Ctx}; pub struct Leave; impl Actor for Leave { type Options = VoidOpt; const NAME: &str = "leave"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { let url = cx .hovered() .and_then(|h| h.url.parent()) .filter(|u| u != cx.cwd()) .or_else(|| cx.cwd().parent()); let Some(mut url) = url else { succ!() }; if url.is_search() { url = url.as_regular()?; } act!(mgr:cd, cx, (url, CdSource::Leave)) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/update_peeked.rs
yazi-actor/src/mgr/update_peeked.rs
use anyhow::Result; use yazi_macro::{render, succ}; use yazi_parser::mgr::UpdatePeekedOpt; use yazi_shared::data::Data; use crate::Actor; pub struct UpdatePeeked; impl Actor for UpdatePeeked { type Options = UpdatePeekedOpt; const NAME: &str = "update_peeked"; fn act(cx: &mut crate::Ctx, opt: Self::Options) -> Result<Data> { let Some(hovered) = cx.hovered().map(|h| &h.url) else { succ!(cx.tab_mut().preview.reset()); }; if opt.lock.url == *hovered { cx.tab_mut().preview.lock = Some(opt.lock); render!(); } succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/tab_swap.rs
yazi-actor/src/mgr/tab_swap.rs
use anyhow::Result; use yazi_dds::Pubsub; use yazi_macro::{err, render, succ}; use yazi_parser::ArrowOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct TabSwap; impl Actor for TabSwap { type Options = ArrowOpt; const NAME: &str = "tab_swap"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let tabs = cx.tabs_mut(); let new = opt.step.add(tabs.cursor, tabs.len(), 0); if new == tabs.cursor { succ!(); } tabs.items.swap(tabs.cursor, new); tabs.cursor = new; err!(Pubsub::pub_after_tab(cx.active().id)); succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/spot.rs
yazi-actor/src/mgr/spot.rs
use anyhow::Result; use yazi_macro::succ; use yazi_parser::mgr::SpotOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Spot; impl Actor for Spot { type Options = SpotOpt; const NAME: &str = "spot"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let Some(hovered) = cx.hovered().cloned() else { succ!() }; let mime = cx.mgr.mimetype.owned(&hovered.url).unwrap_or_default(); // if !self.active().spot.same_file(&hovered, &mime) { // self.active_mut().spot.reset(); // } if let Some(skip) = opt.skip { cx.tab_mut().spot.skip = skip; } else if !cx.tab().spot.same_url(&hovered.url) { cx.tab_mut().spot.skip = 0; } cx.tab_mut().spot.go(hovered, mime); succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/escape.rs
yazi-actor/src/mgr/escape.rs
use anyhow::{Result, bail}; use yazi_macro::{act, render, render_and, succ}; use yazi_parser::{VoidOpt, mgr::EscapeOpt}; use yazi_proxy::AppProxy; use yazi_shared::{data::Data, url::UrlLike}; use crate::{Actor, Ctx}; pub struct Escape; impl Actor for Escape { type Options = EscapeOpt; const NAME: &str = "escape"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { if opt.is_empty() { _ = act!(mgr:escape_find, cx)? != false || act!(mgr:escape_visual, cx)? != false || act!(mgr:escape_filter, cx)? != false || act!(mgr:escape_select, cx)? != false || act!(mgr:escape_search, cx)? != false; succ!(); } if opt.contains(EscapeOpt::FIND) { act!(mgr:escape_find, cx)?; } if opt.contains(EscapeOpt::VISUAL) { act!(mgr:escape_visual, cx)?; } if opt.contains(EscapeOpt::FILTER) { act!(mgr:escape_filter, cx)?; } if opt.contains(EscapeOpt::SELECT) { act!(mgr:escape_select, cx)?; } if opt.contains(EscapeOpt::SEARCH) { act!(mgr:escape_search, cx)?; } succ!(); } } // --- Find pub struct EscapeFind; impl Actor for EscapeFind { type Options = VoidOpt; const NAME: &str = "escape_find"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { succ!(render_and!(cx.tab_mut().finder.take().is_some())) } } // --- Visual pub struct EscapeVisual; impl Actor for EscapeVisual { type Options = VoidOpt; const NAME: &str = "escape_visual"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { let tab = cx.tab_mut(); let select = tab.mode.is_select(); let Some((_, indices)) = tab.mode.take_visual() else { succ!(false) }; render!(); let urls: Vec<_> = indices.into_iter().filter_map(|i| tab.current.files.get(i)).map(|f| &f.url).collect(); if !select { tab.selected.remove_many(urls); } else if urls.len() != tab.selected.add_many(urls) { AppProxy::notify_warn( "Escape visual mode", "Some files cannot be selected, due to path nesting conflict.", ); bail!("Some files cannot be selected, due to path nesting conflict."); } succ!(true) } } // --- Filter pub struct EscapeFilter; impl Actor for EscapeFilter { type Options = VoidOpt; const NAME: &str = "escape_filter"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { if cx.current_mut().files.filter().is_none() { succ!(false); } act!(mgr:filter_do, cx)?; render!(); succ!(true); } } // --- Select pub struct EscapeSelect; impl Actor for EscapeSelect { type Options = VoidOpt; const NAME: &str = "escape_select"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { let tab = cx.tab_mut(); if tab.selected.is_empty() { succ!(false); } tab.selected.clear(); if tab.hovered().is_some_and(|h| h.is_dir()) { act!(mgr:peek, cx, true)?; } render!(); succ!(true); } } // --- Search pub struct EscapeSearch; impl Actor for EscapeSearch { type Options = VoidOpt; const NAME: &str = "escape_search"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { let b = cx.cwd().is_search(); act!(mgr:search_stop, cx)?; succ!(render_and!(b)); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/linemode.rs
yazi-actor/src/mgr/linemode.rs
use anyhow::Result; use yazi_macro::{render, succ}; use yazi_parser::mgr::LinemodeOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Linemode; impl Actor for Linemode { type Options = LinemodeOpt; const NAME: &str = "linemode"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let tab = cx.tab_mut(); if opt.new != tab.pref.linemode { tab.pref.linemode = opt.new.into_owned(); render!(); } succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/bulk_rename.rs
yazi-actor/src/mgr/bulk_rename.rs
use std::{hash::Hash, io::{Read, Write}, ops::Deref, path::Path}; use anyhow::{Result, anyhow}; use crossterm::{execute, style::Print}; use hashbrown::HashMap; use scopeguard::defer; use tokio::io::AsyncWriteExt; use yazi_binding::Permit; use yazi_config::{YAZI, opener::OpenerRule}; use yazi_dds::Pubsub; use yazi_fs::{File, FilesOp, Splatter, max_common_root, path::skip_url, provider::{FileBuilder, Provider, local::{Gate, Local}}}; use yazi_macro::{err, succ}; use yazi_parser::VoidOpt; use yazi_proxy::{AppProxy, HIDER, TasksProxy}; use yazi_shared::{data::Data, path::PathDyn, strand::{AsStrand, AsStrandJoin, Strand, StrandBuf, StrandLike}, terminal_clear, url::{AsUrl, UrlBuf, UrlCow, UrlLike}}; use yazi_term::tty::TTY; use yazi_vfs::{VfsFile, maybe_exists, provider}; use yazi_watcher::WATCHER; use crate::{Actor, Ctx}; pub struct BulkRename; impl Actor for BulkRename { type Options = VoidOpt; const NAME: &str = "bulk_rename"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { let Some(opener) = Self::opener() else { succ!(AppProxy::notify_warn("Bulk rename", "No text opener found")); }; let selected: Vec<_> = cx.tab().selected_or_hovered().cloned().collect(); if selected.is_empty() { succ!(AppProxy::notify_warn("Bulk rename", "No files selected")); } let root = max_common_root(&selected); let old: Vec<_> = selected.iter().enumerate().map(|(i, u)| Tuple::new(i, skip_url(u, root))).collect(); let cwd = cx.cwd().clone(); tokio::spawn(async move { let tmp = YAZI.preview.tmpfile("bulk"); Gate::default() .write(true) .create_new(true) .open(&tmp) .await? .write_all(old.join(Strand::Utf8("\n")).encoded_bytes()) .await?; defer! { let tmp = tmp.clone(); tokio::spawn(async move { Local::regular(&tmp).remove_file().await }); } TasksProxy::process_exec( cwd.into(), Splatter::new(&[UrlCow::default(), tmp.as_url().into()]).splat(&opener.run), vec![UrlCow::default(), UrlBuf::from(&tmp).into()], opener.block, opener.orphan, ) .await; let _permit = Permit::new(HIDER.acquire().await.unwrap(), AppProxy::resume()); AppProxy::stop().await; let new: Vec<_> = Local::regular(&tmp) .read_to_string() .await? .lines() .take(old.len()) .enumerate() .map(|(i, s)| Tuple::new(i, s)) .collect(); Self::r#do(root, old, new, selected).await }); succ!(); } } impl BulkRename { async fn r#do( root: usize, old: Vec<Tuple>, new: Vec<Tuple>, selected: Vec<UrlBuf>, ) -> Result<()> { terminal_clear(TTY.writer())?; if old.len() != new.len() { #[rustfmt::skip] let s = format!("Number of new and old file names mismatch (New: {}, Old: {}).\nPress <Enter> to exit...", new.len(), old.len()); execute!(TTY.writer(), Print(s))?; TTY.reader().read_exact(&mut [0])?; return Ok(()); } let (old, new) = old.into_iter().zip(new).filter(|(o, n)| o != n).unzip(); let todo = Self::prioritized_paths(old, new); if todo.is_empty() { return Ok(()); } { let mut w = TTY.lockout(); for (old, new) in &todo { writeln!(w, "{} -> {}", old.display(), new.display())?; } write!(w, "Continue to rename? (y/N): ")?; w.flush()?; } let mut buf = [0; 10]; _ = TTY.reader().read(&mut buf)?; if buf[0] != b'y' && buf[0] != b'Y' { return Ok(()); } let permit = WATCHER.acquire().await.unwrap(); let (mut failed, mut succeeded) = (Vec::new(), HashMap::with_capacity(todo.len())); for (o, n) in todo { let (Ok(old), Ok(new)) = (Self::replace_url(&selected[o.0], root, &o), Self::replace_url(&selected[n.0], root, &n)) else { failed.push((o, n, anyhow!("Invalid new or old file name"))); continue; }; if maybe_exists(&new).await && !provider::must_identical(&old, &new).await { failed.push((o, n, anyhow!("Destination already exists"))); } else if let Err(e) = provider::rename(&old, &new).await { failed.push((o, n, e.into())); } else if let Ok(f) = File::new(new).await { succeeded.insert(old, f); } else { failed.push((o, n, anyhow!("Failed to retrieve file info"))); } } if !succeeded.is_empty() { let it = succeeded.iter().map(|(o, n)| (o.as_url(), n.url.as_url())); err!(Pubsub::pub_after_bulk(it)); FilesOp::rename(succeeded); } drop(permit); if !failed.is_empty() { Self::output_failed(failed).await?; } Ok(()) } fn opener() -> Option<&'static OpenerRule> { YAZI.opener.block(YAZI.open.all(Path::new("bulk-rename.txt"), "text/plain")) } fn replace_url(url: &UrlBuf, take: usize, rep: &StrandBuf) -> Result<UrlBuf> { Ok(url.try_replace(take, PathDyn::with(url.kind(), rep)?)?.into_owned()) } async fn output_failed(failed: Vec<(Tuple, Tuple, anyhow::Error)>) -> Result<()> { let mut stdout = TTY.lockout(); terminal_clear(&mut *stdout)?; writeln!(stdout, "Failed to rename:")?; for (old, new, err) in failed { writeln!(stdout, "{} -> {}: {err}", old.display(), new.display())?; } writeln!(stdout, "\nPress ENTER to exit")?; stdout.flush()?; TTY.reader().read_exact(&mut [0])?; Ok(()) } fn prioritized_paths(old: Vec<Tuple>, new: Vec<Tuple>) -> Vec<(Tuple, Tuple)> { let orders: HashMap<_, _> = old.iter().enumerate().map(|(i, t)| (t, i)).collect(); let mut incomes: HashMap<_, _> = old.iter().map(|t| (t, false)).collect(); let mut todos: HashMap<_, _> = old .iter() .zip(new) .map(|(o, n)| { incomes.get_mut(&n).map(|b| *b = true); (o, n) }) .collect(); let mut sorted = Vec::with_capacity(old.len()); while !todos.is_empty() { // Paths that are non-incomes and don't need to be prioritized in this round let mut outcomes: Vec<_> = incomes.iter().filter(|&(_, b)| !b).map(|(&t, _)| t).collect(); outcomes.sort_unstable_by(|a, b| orders[b].cmp(&orders[a])); // If there're no outcomes, it means there are cycles in the renaming if outcomes.is_empty() { let mut remain: Vec<_> = todos.into_iter().map(|(o, n)| (o.clone(), n)).collect(); remain.sort_unstable_by(|(a, _), (b, _)| orders[a].cmp(&orders[b])); sorted.reverse(); sorted.extend(remain); return sorted; } for old in outcomes { let Some(new) = todos.remove(old) else { unreachable!() }; incomes.remove(&old); incomes.get_mut(&new).map(|b| *b = false); sorted.push((old.clone(), new)); } } sorted.reverse(); sorted } } // --- Tuple #[derive(Clone, Debug)] struct Tuple(usize, StrandBuf); impl Deref for Tuple { type Target = StrandBuf; fn deref(&self) -> &Self::Target { &self.1 } } impl PartialEq for Tuple { fn eq(&self, other: &Self) -> bool { self.1 == other.1 } } impl Eq for Tuple {} impl Hash for Tuple { fn hash<H: std::hash::Hasher>(&self, state: &mut H) { self.1.hash(state); } } impl AsStrand for &Tuple { fn as_strand(&self) -> Strand<'_> { self.1.as_strand() } } impl Tuple { fn new(index: usize, inner: impl Into<StrandBuf>) -> Self { Self(index, inner.into()) } } // --- Tests #[cfg(test)] mod tests { use super::*; #[test] fn test_sort() { fn cmp(input: &[(&str, &str)], expected: &[(&str, &str)]) { let sorted = BulkRename::prioritized_paths( input.iter().map(|&(o, _)| Tuple::new(0, o)).collect(), input.iter().map(|&(_, n)| Tuple::new(0, n)).collect(), ); let sorted: Vec<_> = sorted.iter().map(|(o, n)| (o.to_str().unwrap(), n.to_str().unwrap())).collect(); assert_eq!(sorted, expected); } #[rustfmt::skip] cmp( &[("2", "3"), ("1", "2"), ("3", "4")], &[("3", "4"), ("2", "3"), ("1", "2")] ); #[rustfmt::skip] cmp( &[("1", "3"), ("2", "3"), ("3", "4")], &[("3", "4"), ("1", "3"), ("2", "3")] ); #[rustfmt::skip] cmp( &[("2", "1"), ("1", "2")], &[("2", "1"), ("1", "2")] ); #[rustfmt::skip] cmp( &[("3", "2"), ("2", "1"), ("1", "3"), ("a", "b"), ("b", "c")], &[("b", "c"), ("a", "b"), ("3", "2"), ("2", "1"), ("1", "3")] ); #[rustfmt::skip] cmp( &[("b", "b_"), ("a", "a_"), ("c", "c_")], &[("b", "b_"), ("a", "a_"), ("c", "c_")], ); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/displace_do.rs
yazi-actor/src/mgr/displace_do.rs
use anyhow::{Result, bail}; use yazi_fs::FilesOp; use yazi_macro::{act, succ}; use yazi_parser::mgr::{CdSource, DisplaceDoOpt}; use yazi_shared::{data::Data, url::UrlLike}; use crate::{Actor, Ctx}; pub struct DisplaceDo; impl Actor for DisplaceDo { type Options = DisplaceDoOpt; const NAME: &str = "displace_do"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { if cx.cwd() != opt.from { succ!() } let to = match opt.to { Ok(url) => url, Err(e) => return act!(mgr:update_files, cx, FilesOp::IOErr(opt.from, e.into())), }; if !to.is_absolute() { bail!("Target URL must be absolute"); } else if let Some(hovered) = cx.hovered() && let Ok(url) = to.try_join(hovered.urn()) { act!(mgr:reveal, cx, (url, CdSource::Displace)) } else { act!(mgr:cd, cx, (to, CdSource::Displace)) } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/seek.rs
yazi-actor/src/mgr/seek.rs
use anyhow::Result; use yazi_config::YAZI; use yazi_macro::succ; use yazi_parser::mgr::SeekOpt; use yazi_plugin::isolate; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Seek; impl Actor for Seek { type Options = SeekOpt; const NAME: &str = "seek"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let Some(hovered) = cx.hovered() else { succ!(cx.tab_mut().preview.reset()); }; let Some(mime) = cx.mgr.mimetype.get(&hovered.url) else { succ!(cx.tab_mut().preview.reset()); }; let Some(previewer) = YAZI.plugin.previewer(hovered, mime) else { succ!(cx.tab_mut().preview.reset()); }; isolate::seek_sync(&previewer.run, hovered.clone(), opt.units); succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/remove.rs
yazi-actor/src/mgr/remove.rs
use anyhow::Result; use yazi_config::popup::ConfirmCfg; use yazi_macro::{act, succ}; use yazi_parser::mgr::RemoveOpt; use yazi_proxy::{ConfirmProxy, MgrProxy}; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Remove; impl Actor for Remove { type Options = RemoveOpt; const NAME: &str = "remove"; fn act(cx: &mut Ctx, mut opt: Self::Options) -> Result<Data> { act!(mgr:escape_visual, cx)?; opt.targets = if opt.hovered { cx.hovered().map_or(vec![], |h| vec![h.url.clone()]) } else { cx.tab().selected_or_hovered().cloned().collect() }; if opt.targets.is_empty() { succ!(); } else if opt.force { return act!(mgr:remove_do, cx, opt); } let confirm = ConfirmProxy::show(if opt.permanently { ConfirmCfg::delete(&opt.targets) } else { ConfirmCfg::trash(&opt.targets) }); tokio::spawn(async move { if confirm.await { MgrProxy::remove_do(opt.targets, opt.permanently); } }); succ!(); } } // --- Do pub struct RemoveDo; impl Actor for RemoveDo { type Options = RemoveOpt; const NAME: &str = "remove_do"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let mgr = &mut cx.mgr; mgr.tabs.iter_mut().for_each(|t| { t.selected.remove_many(&opt.targets); }); for u in &opt.targets { mgr.yanked.remove(u); } mgr.yanked.catchup_revision(false); cx.tasks.file_remove(opt.targets, opt.permanently); succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/update_yanked.rs
yazi-actor/src/mgr/update_yanked.rs
use anyhow::Result; use yazi_core::mgr::Yanked; use yazi_macro::{render, succ}; use yazi_parser::mgr::UpdateYankedOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct UpdateYanked; impl Actor for UpdateYanked { type Options = UpdateYankedOpt<'static>; const NAME: &str = "update_yanked"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { if opt.urls.is_empty() && cx.mgr.yanked.is_empty() { succ!(); } cx.mgr.yanked = Yanked::new(opt.cut, opt.urls.into_owned()); succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/forward.rs
yazi-actor/src/mgr/forward.rs
use anyhow::Result; use yazi_macro::{act, succ}; use yazi_parser::{VoidOpt, mgr::CdSource}; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Forward; impl Actor for Forward { type Options = VoidOpt; const NAME: &str = "forward"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { if let Some(u) = cx.tab_mut().backstack.shift_forward().cloned() { act!(mgr:cd, cx, (u, CdSource::Forward))?; } succ!() } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/close.rs
yazi-actor/src/mgr/close.rs
use anyhow::Result; use yazi_macro::act; use yazi_parser::mgr::CloseOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Close; impl Actor for Close { type Options = CloseOpt; const NAME: &str = "close"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { if cx.tabs().len() > 1 { act!(mgr:tab_close, cx, cx.tabs().cursor) } else { act!(mgr:quit, cx, opt.0) } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/follow.rs
yazi-actor/src/mgr/follow.rs
use anyhow::Result; use yazi_fs::path::clean_url; use yazi_macro::{act, succ}; use yazi_parser::{VoidOpt, mgr::CdSource}; use yazi_shared::{data::Data, url::UrlLike}; use crate::{Actor, Ctx}; pub struct Follow; impl Actor for Follow { type Options = VoidOpt; const NAME: &str = "follow"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { let Some(file) = cx.hovered() else { succ!() }; let Some(link_to) = &file.link_to else { succ!() }; let Some(parent) = file.url.parent() else { succ!() }; let Ok(joined) = parent.try_join(link_to) else { succ!() }; act!(mgr:reveal, cx, (clean_url(joined), CdSource::Follow)) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/reveal.rs
yazi-actor/src/mgr/reveal.rs
use anyhow::Result; use yazi_fs::{File, FilesOp}; use yazi_macro::{act, render, succ}; use yazi_parser::mgr::RevealOpt; use yazi_shared::{data::Data, url::UrlLike}; use crate::{Actor, Ctx}; pub struct Reveal; impl Actor for Reveal { type Options = RevealOpt; const NAME: &str = "reveal"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let Some((parent, child)) = opt.target.pair() else { succ!() }; // Cd to the parent directory act!(mgr:cd, cx, (parent, opt.source))?; // Try to hover over the child file let tab = cx.tab_mut(); render!(tab.current.hover(child)); // If the child is not hovered, which means it doesn't exist, // create a dummy file if !opt.no_dummy && tab.hovered().is_none_or(|f| child != f.urn()) { let op = FilesOp::Creating(parent.into(), vec![File::from_dummy(&opt.target, None)]); tab.current.update_pub(tab.id, op); } // Now, we can safely hover over the target act!(mgr:hover, cx, Some(child.into()))?; act!(mgr:peek, cx)?; act!(mgr:watch, cx)?; succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/create.rs
yazi-actor/src/mgr/create.rs
use anyhow::{Result, bail}; use yazi_config::popup::{ConfirmCfg, InputCfg}; use yazi_fs::{File, FilesOp}; use yazi_macro::{ok_or_not_found, succ}; use yazi_parser::mgr::CreateOpt; use yazi_proxy::{ConfirmProxy, InputProxy, MgrProxy}; use yazi_shared::{data::Data, url::{UrlBuf, UrlLike}}; use yazi_vfs::{VfsFile, maybe_exists, provider}; use yazi_watcher::WATCHER; use crate::{Actor, Ctx}; pub struct Create; impl Actor for Create { type Options = CreateOpt; const NAME: &str = "create"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let cwd = cx.cwd().to_owned(); let mut input = InputProxy::show(InputCfg::create(opt.dir)); tokio::spawn(async move { let Some(Ok(name)) = input.recv().await else { return }; if name.is_empty() { return; } let Ok(new) = cwd.try_join(&name) else { return; }; if !opt.force && maybe_exists(&new).await && !ConfirmProxy::show(ConfirmCfg::overwrite(&new)).await { return; } _ = Self::r#do(new, opt.dir || name.ends_with('/') || name.ends_with('\\')).await; }); succ!(); } } impl Create { async fn r#do(new: UrlBuf, dir: bool) -> Result<()> { let _permit = WATCHER.acquire().await.unwrap(); if dir { provider::create_dir_all(&new).await?; } else if let Ok(real) = provider::casefold(&new).await && let Some((parent, urn)) = real.pair() { ok_or_not_found!(provider::remove_file(&new).await); FilesOp::Deleting(parent.into(), [urn.into()].into()).emit(); provider::create(&new).await?; } else if let Some(parent) = new.parent() { provider::create_dir_all(parent).await.ok(); ok_or_not_found!(provider::remove_file(&new).await); provider::create(&new).await?; } else { bail!("Cannot create file at root"); } if let Ok(real) = provider::casefold(&new).await && let Some((parent, urn)) = real.pair() { let file = File::new(&real).await?; FilesOp::Upserting(parent.into(), [(urn.into(), file)].into()).emit(); MgrProxy::reveal(&real); } Ok(()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/mgr/refresh.rs
yazi-actor/src/mgr/refresh.rs
use anyhow::Result; use crossterm::{execute, terminal::SetTitle}; use yazi_config::YAZI; use yazi_core::tab::Folder; use yazi_fs::{CWD, Files, FilesOp, cha::Cha}; use yazi_macro::{act, succ}; use yazi_parser::VoidOpt; use yazi_proxy::MgrProxy; use yazi_shared::{data::Data, url::{UrlBuf, UrlLike}}; use yazi_term::tty::TTY; use yazi_vfs::{VfsFiles, VfsFilesOp}; use crate::{Actor, Ctx}; pub struct Refresh; impl Actor for Refresh { type Options = VoidOpt; const NAME: &str = "refresh"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { if let (_, Some(s)) = (CWD.set(cx.cwd(), Self::cwd_changed), YAZI.mgr.title()) { execute!(TTY.writer(), SetTitle(s)).ok(); } if let Some(p) = cx.parent() { Self::trigger_dirs(&[cx.current(), p]); } else { Self::trigger_dirs(&[cx.current()]); } act!(mgr:peek, cx)?; act!(mgr:watch, cx)?; act!(mgr:update_paged, cx)?; cx.tasks().prework_sorted(&cx.current().files); succ!(); } } impl Refresh { fn cwd_changed() { if CWD.load().kind().is_virtual() { MgrProxy::watch(); } } // TODO: performance improvement fn trigger_dirs(folders: &[&Folder]) { async fn go(dir: UrlBuf, cha: Cha) { let Some(cha) = Files::assert_stale(&dir, cha).await else { return }; match Files::from_dir_bulk(&dir).await { Ok(files) => FilesOp::Full(dir, files, cha).emit(), Err(e) => FilesOp::issue_error(&dir, e).await, } } let futs: Vec<_> = folders .iter() .filter(|&f| f.url.is_absolute() && f.url.is_internal()) .map(|&f| go(f.url.clone(), f.cha)) .collect(); if !futs.is_empty() { tokio::spawn(futures::future::join_all(futs)); } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/spot/arrow.rs
yazi-actor/src/spot/arrow.rs
use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_parser::ArrowOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Arrow; impl Actor for Arrow { type Options = ArrowOpt; const NAME: &str = "arrow"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let spot = &mut cx.tab_mut().spot; let Some(lock) = &mut spot.lock else { succ!() }; let new = opt.step.add(spot.skip, lock.len().unwrap_or(u16::MAX as _), 0); let Some(old) = lock.selected() else { return act!(mgr:spot, cx, new); }; lock.select(Some(new)); let new = lock.selected().unwrap(); spot.skip = new; succ!(render!(new != old)); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/spot/copy.rs
yazi-actor/src/spot/copy.rs
use anyhow::Result; use yazi_macro::succ; use yazi_parser::spot::CopyOpt; use yazi_shared::data::Data; use yazi_widgets::CLIPBOARD; use crate::{Actor, Ctx}; pub struct Copy; impl Actor for Copy { type Options = CopyOpt; const NAME: &str = "copy"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let spot = &cx.tab().spot; let Some(lock) = &spot.lock else { succ!() }; let Some(table) = lock.table() else { succ!() }; let mut s = String::new(); match opt.r#type.as_ref() { "cell" => { let Some(cell) = table.selected_cell() else { succ!() }; s = cell.to_string(); } "line" => { // TODO } _ => {} } futures::executor::block_on(CLIPBOARD.set(s)); succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/spot/mod.rs
yazi-actor/src/spot/mod.rs
yazi_macro::mod_flat!(arrow close copy swipe);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/spot/close.rs
yazi-actor/src/spot/close.rs
use anyhow::Result; use yazi_macro::succ; use yazi_parser::VoidOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Close; impl Actor for Close { type Options = VoidOpt; const NAME: &str = "close"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { succ!(cx.tab_mut().spot.reset()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/spot/swipe.rs
yazi-actor/src/spot/swipe.rs
use anyhow::Result; use yazi_macro::act; use yazi_parser::ArrowOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Swipe; impl Actor for Swipe { type Options = ArrowOpt; const NAME: &str = "swipe"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { act!(mgr:arrow, cx, opt)?; act!(mgr:spot, cx) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/input/complete.rs
yazi-actor/src/input/complete.rs
use anyhow::Result; use yazi_macro::{act, succ}; use yazi_parser::input::CompleteOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Complete; impl Actor for Complete { type Options = CompleteOpt; const NAME: &str = "complete"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let input = &mut cx.input; if !input.visible || input.ticket.current() != opt.ticket { succ!(); } act!(complete, input, opt) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/input/mod.rs
yazi-actor/src/input/mod.rs
yazi_macro::mod_flat!(close complete escape show);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/input/show.rs
yazi-actor/src/input/show.rs
use std::ops::DerefMut; use anyhow::Result; use yazi_config::YAZI; use yazi_macro::{act, render, succ}; use yazi_parser::input::ShowOpt; use yazi_shared::{data::Data, errors::InputError}; use yazi_widgets::input::InputCallback; use crate::{Actor, Ctx}; pub struct Show; impl Actor for Show { type Options = ShowOpt; const NAME: &str = "show"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { act!(input:close, cx)?; let input = &mut cx.input; input.visible = true; input.title = opt.cfg.title; input.position = opt.cfg.position; // Typing input.tx = Some(opt.tx.clone()); let ticket = input.ticket.clone(); // Reset input let cb: InputCallback = Box::new(move |before, after| { if opt.cfg.realtime { opt.tx.send(Err(InputError::Typed(format!("{before}{after}")))).ok(); } else if opt.cfg.completion { opt.tx.send(Err(InputError::Completed(before.to_owned(), ticket.current()))).ok(); } }); *input.deref_mut() = yazi_widgets::input::Input::new( opt.cfg.value, opt.cfg.position.offset.width.saturating_sub(YAZI.input.border()) as usize, opt.cfg.obscure, cb, ); // Set cursor after reset // TODO: remove this if let Some(cursor) = opt.cfg.cursor { input.snap_mut().cursor = cursor; act!(r#move, input)?; } succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/input/escape.rs
yazi-actor/src/input/escape.rs
use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_parser::VoidOpt; use yazi_shared::data::Data; use yazi_widgets::input::InputOp; use crate::{Actor, Ctx}; pub struct Escape; impl Actor for Escape { type Options = VoidOpt; const NAME: &str = "escape"; fn act(cx: &mut Ctx, _: Self::Options) -> Result<Data> { use yazi_widgets::input::InputMode as M; let input = &mut cx.input; let mode = input.snap().mode; match mode { M::Normal if input.snap_mut().op == InputOp::None => act!(input:close, cx), M::Insert => act!(cmp:close, cx), M::Normal | M::Replace => Ok(().into()), }?; act!(escape, cx.input)?; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/input/close.rs
yazi-actor/src/input/close.rs
use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_parser::input::CloseOpt; use yazi_shared::{data::Data, errors::InputError}; use crate::{Actor, Ctx}; pub struct Close; impl Actor for Close { type Options = CloseOpt; const NAME: &str = "close"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let input = &mut cx.input; input.visible = false; input.ticket.next(); if let Some(tx) = input.tx.take() { let value = input.snap().value.clone(); _ = tx.send(if opt.submit { Ok(value) } else { Err(InputError::Canceled(value)) }); } act!(cmp:close, cx)?; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/pick/arrow.rs
yazi-actor/src/pick/arrow.rs
use anyhow::Result; use yazi_macro::{render, succ}; use yazi_parser::ArrowOpt; use yazi_shared::data::Data; use yazi_widgets::Scrollable; use crate::{Actor, Ctx}; pub struct Arrow; impl Actor for Arrow { type Options = ArrowOpt; const NAME: &str = "arrow"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { succ!(render!(cx.pick.scroll(opt.step))); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/pick/mod.rs
yazi-actor/src/pick/mod.rs
yazi_macro::mod_flat!(arrow close show);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/pick/show.rs
yazi-actor/src/pick/show.rs
use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_parser::pick::ShowOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Show; impl Actor for Show { type Options = ShowOpt; const NAME: &str = "show"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { act!(pick:close, cx)?; let pick = &mut cx.pick; pick.title = opt.cfg.title; pick.items = opt.cfg.items; pick.position = opt.cfg.position; pick.callback = Some(opt.tx); pick.visible = true; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/pick/close.rs
yazi-actor/src/pick/close.rs
use anyhow::{Result, anyhow}; use yazi_macro::{render, succ}; use yazi_parser::pick::CloseOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Close; impl Actor for Close { type Options = CloseOpt; const NAME: &str = "close"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let pick = &mut cx.pick; if let Some(cb) = pick.callback.take() { _ = cb.send(if opt.submit { Ok(pick.cursor) } else { Err(anyhow!("canceled")) }); } pick.cursor = 0; pick.offset = 0; pick.visible = false; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/cmp/trigger.rs
yazi-actor/src/cmp/trigger.rs
use std::mem; use anyhow::Result; use yazi_fs::{path::clean_url, provider::{DirReader, FileHolder}}; use yazi_macro::{act, render, succ}; use yazi_parser::cmp::{CmpItem, ShowOpt, TriggerOpt}; use yazi_proxy::CmpProxy; use yazi_shared::{AnyAsciiChar, BytePredictor, data::Data, natsort, path::{AsPath, PathBufDyn, PathLike}, scheme::{SchemeCow, SchemeLike}, strand::{AsStrand, StrandLike}, url::{UrlBuf, UrlCow, UrlLike}}; use yazi_vfs::provider; use crate::{Actor, Ctx}; pub struct Trigger; impl Actor for Trigger { type Options = TriggerOpt; const NAME: &str = "trigger"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let cmp = &mut cx.cmp; if let Some(t) = opt.ticket { if t < cmp.ticket { succ!(); } cmp.ticket = t; } let Some((parent, word)) = Self::split_url(&opt.word) else { return act!(cmp:close, cx, false); }; if cmp.caches.contains_key(&parent) { let ticket = cmp.ticket; return act!(cmp:show, cx, ShowOpt { cache: vec![], cache_name: parent, word, ticket }); } let ticket = cmp.ticket; tokio::spawn(async move { let mut dir = provider::read_dir(&parent).await?; let mut cache = vec![]; // "/" is both a directory separator and the root directory per se // As there's no parent directory for the FS root, it is a special case if parent.loc() == "/" { cache.push(CmpItem { name: Default::default(), is_dir: true }); } while let Ok(Some(ent)) = dir.next().await { if let Ok(ft) = ent.file_type().await { cache.push(CmpItem { name: ent.name().into_owned(), is_dir: ft.is_dir() }); } } if !cache.is_empty() { cache .sort_unstable_by(|a, b| natsort(a.name.encoded_bytes(), b.name.encoded_bytes(), false)); CmpProxy::show(ShowOpt { cache, cache_name: parent, word, ticket }); } Ok::<_, anyhow::Error>(()) }); succ!(render!(mem::replace(&mut cmp.visible, false))); } } impl Trigger { fn split_url(s: &str) -> Option<(UrlBuf, PathBufDyn)> { let sep = if cfg!(windows) { AnyAsciiChar::new(b"/\\").unwrap() } else { AnyAsciiChar::new(b"/").unwrap() }; let (scheme, path) = SchemeCow::parse(s.as_bytes()).ok()?; if path.is_empty() && !sep.predicate(s.bytes().last()?) { return None; // We don't complete a `sftp://test`, but `sftp://test/` } // Scheme let scheme = scheme.zeroed(); if scheme.is_local() && path.as_strand() == "~" { return None; // We don't complete a `~`, but `~/` } // Child let child = path.rsplit_pred(sep).map_or(path.as_path(), |(_, c)| c).to_owned(); // Parent let url = UrlCow::try_from((scheme.clone().zeroed(), path)).ok()?; let abs = if let Some(u) = provider::try_absolute(&url) { u } else { url }; let parent = abs.loc().try_strip_suffix(&child).ok()?; Some((clean_url(UrlCow::try_from((scheme, parent)).ok()?), child)) } } #[cfg(test)] mod tests { use yazi_fs::CWD; use yazi_shared::url::UrlLike; use super::*; fn compare(s: &str, parent: &str, child: &str) { let (mut p, c) = Trigger::split_url(s).unwrap(); if let Ok(u) = p.try_strip_prefix(yazi_fs::CWD.load().as_ref()) { p = UrlBuf::Regular(u.as_os().unwrap().into()); } assert_eq!((p, c.to_str().unwrap()), (parent.parse().unwrap(), child)); } #[cfg(unix)] #[test] fn test_split() { yazi_shared::init_tests(); yazi_fs::init(); assert_eq!(Trigger::split_url(""), None); assert_eq!(Trigger::split_url("sftp://test"), None); compare(" ", "", " "); compare("/", "/", ""); compare("//", "/", ""); compare("///", "/", ""); compare("/foo", "/", "foo"); compare("//foo", "/", "foo"); compare("///foo", "/", "foo"); compare("/foo/", "/foo/", ""); compare("//foo/", "/foo/", ""); compare("/foo/bar", "/foo/", "bar"); compare("///foo/bar", "/foo/", "bar"); CWD.set(&"sftp://test".parse::<UrlBuf>().unwrap(), || {}); compare("sftp://test/a", "sftp://test/.", "a"); compare("sftp://test//a", "sftp://test//", "a"); compare("sftp://test2/a", "sftp://test2/.", "a"); compare("sftp://test2//a", "sftp://test2//", "a"); } #[cfg(windows)] #[test] fn test_split() { yazi_fs::init(); compare("foo", "", "foo"); compare(r"foo\", r"foo\", ""); compare(r"foo\bar", r"foo\", "bar"); compare(r"foo\bar\", r"foo\bar\", ""); compare(r"C:\", r"C:\", ""); compare(r"C:\foo", r"C:\", "foo"); compare(r"C:\foo\", r"C:\foo\", ""); compare(r"C:\foo\bar", r"C:\foo\", "bar"); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/cmp/arrow.rs
yazi-actor/src/cmp/arrow.rs
use anyhow::Result; use yazi_macro::{render, succ}; use yazi_parser::ArrowOpt; use yazi_shared::data::Data; use yazi_widgets::Scrollable; use crate::{Actor, Ctx}; pub struct Arrow; impl Actor for Arrow { type Options = ArrowOpt; const NAME: &str = "arrow"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { succ!(render!(cx.cmp.scroll(opt.step))); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/cmp/mod.rs
yazi-actor/src/cmp/mod.rs
yazi_macro::mod_flat!(arrow close show trigger);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/cmp/show.rs
yazi-actor/src/cmp/show.rs
use std::{mem, ops::ControlFlow}; use anyhow::Result; use yazi_macro::{render, succ}; use yazi_parser::cmp::{CmpItem, ShowOpt}; use yazi_shared::{data::Data, path::{AsPath, PathDyn}, strand::StrandLike}; use crate::{Actor, Ctx}; const LIMIT: usize = 30; pub struct Show; impl Actor for Show { type Options = ShowOpt; const NAME: &str = "show"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let cmp = &mut cx.cmp; if cmp.ticket != opt.ticket { succ!(); } if !opt.cache.is_empty() { cmp.caches.insert(opt.cache_name.clone(), opt.cache); } let Some(cache) = cmp.caches.get(&opt.cache_name) else { succ!(); }; cmp.cands = Self::match_candidates(opt.word.as_path(), cache); if cmp.cands.is_empty() { succ!(render!(mem::replace(&mut cmp.visible, false))); } cmp.offset = 0; cmp.cursor = 0; cmp.visible = true; succ!(render!()); } } impl Show { fn match_candidates(word: PathDyn, cache: &[CmpItem]) -> Vec<CmpItem> { let smart = !word.encoded_bytes().iter().any(|&b| b.is_ascii_uppercase()); let flow = cache.iter().try_fold((Vec::new(), Vec::new()), |(mut exact, mut fuzzy), item| { let starts_with = if smart { item.name.eq_ignore_ascii_case(word) } else { item.name.starts_with(word) }; if starts_with { exact.push(item); if exact.len() >= LIMIT { return ControlFlow::Break((exact, fuzzy)); } } else if fuzzy.len() < LIMIT - exact.len() && item.name.contains(word) { // Here we don't break the control flow, since we want more exact matching. fuzzy.push(item) } ControlFlow::Continue((exact, fuzzy)) }); let (exact, fuzzy) = match flow { ControlFlow::Continue(v) => v, ControlFlow::Break(v) => v, }; let it = fuzzy.into_iter().take(LIMIT - exact.len()); exact.into_iter().chain(it).cloned().collect() } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/cmp/close.rs
yazi-actor/src/cmp/close.rs
use std::mem; use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_parser::{cmp::CloseOpt, input::CompleteOpt}; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Close; impl Actor for Close { type Options = CloseOpt; const NAME: &str = "close"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let cmp = &mut cx.core.cmp; if let Some(item) = cmp.selected().filter(|_| opt.submit).cloned() { return act!(input:complete, cx, CompleteOpt { item, ticket: cmp.ticket }); } cmp.caches.clear(); cmp.ticket = Default::default(); succ!(render!(mem::replace(&mut cmp.visible, false))); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/confirm/arrow.rs
yazi-actor/src/confirm/arrow.rs
use anyhow::Result; use yazi_macro::{render, succ}; use yazi_parser::ArrowOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Arrow; impl Actor for Arrow { type Options = ArrowOpt; const NAME: &str = "arrow"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { let confirm = &mut cx.core.confirm; let area = cx.core.mgr.area(confirm.position); let len = confirm.list.line_count(area.width); let old = confirm.offset; confirm.offset = opt.step.add(confirm.offset, len, area.height as _); succ!(render!(old != confirm.offset)); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/confirm/mod.rs
yazi-actor/src/confirm/mod.rs
yazi_macro::mod_flat!(arrow close show);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/confirm/show.rs
yazi-actor/src/confirm/show.rs
use anyhow::Result; use yazi_macro::{act, render, succ}; use yazi_parser::confirm::ShowOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Show; impl Actor for Show { type Options = ShowOpt; const NAME: &str = "show"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { act!(confirm:close, cx)?; let confirm = &mut cx.confirm; confirm.title = opt.cfg.title; confirm.body = opt.cfg.body; confirm.list = opt.cfg.list; confirm.position = opt.cfg.position; confirm.offset = 0; confirm.callback = Some(opt.tx); confirm.visible = true; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/confirm/close.rs
yazi-actor/src/confirm/close.rs
use anyhow::Result; use yazi_macro::{render, succ}; use yazi_parser::confirm::CloseOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Close; impl Actor for Close { type Options = CloseOpt; const NAME: &str = "close"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { if let Some(cb) = cx.confirm.callback.take() { _ = cb.send(opt.submit); } cx.confirm.visible = false; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/core/preflight.rs
yazi-actor/src/core/preflight.rs
use anyhow::Result; use mlua::{ErrorContext, ExternalError, IntoLua, Value}; use yazi_binding::runtime_mut; use yazi_dds::{LOCAL, spark::{Spark, SparkKind}}; use yazi_plugin::LUA; use crate::{Ctx, lives::Lives}; pub struct Preflight; impl Preflight { pub fn act<'a>(cx: &mut Ctx, opt: (SparkKind, Spark<'a>)) -> Result<Spark<'a>> { let kind = opt.0; let Some(handlers) = LOCAL.read().get(kind.as_ref()).filter(|&m| !m.is_empty()).cloned() else { return Ok(opt.1); }; Ok(Lives::scope(cx.core, || { let mut body = opt.1.into_lua(&LUA)?; for (id, cb) in handlers { runtime_mut!(LUA)?.push(&id); let result = cb.call::<Value>(&body); runtime_mut!(LUA)?.pop(); match result { Ok(Value::Nil) => { Err(format!("`{kind}` event cancelled by `{id}` plugin on preflight").into_lua_err())? } Ok(v) => body = v, Err(e) => Err( format!("Failed to run `{kind}` event handler in `{id}` plugin: {e}").into_lua_err(), )?, }; } Spark::from_lua(&LUA, kind, body) .with_context(|e| format!("Unexpected return type from `{kind}` event handlers: {e}")) })?) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/core/mod.rs
yazi-actor/src/core/mod.rs
yazi_macro::mod_flat!(preflight);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/which/callback.rs
yazi-actor/src/which/callback.rs
use anyhow::Result; use yazi_macro::succ; use yazi_parser::which::CallbackOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Callback; impl Actor for Callback { type Options = CallbackOpt; const NAME: &str = "callback"; fn act(_: &mut Ctx, opt: Self::Options) -> Result<Data> { opt.tx.try_send(opt.idx)?; succ!(); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/which/mod.rs
yazi-actor/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-actor/src/which/show.rs
yazi-actor/src/which/show.rs
use anyhow::Result; use yazi_macro::{render, succ}; use yazi_parser::which::ShowOpt; use yazi_shared::data::Data; use crate::{Actor, Ctx}; pub struct Show; impl Actor for Show { type Options = ShowOpt; const NAME: &str = "show"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> { if opt.cands.is_empty() { succ!(); } let which = &mut cx.which; which.times = 0; which.cands = opt.cands.into_iter().map(|c| c.into()).collect(); which.visible = true; which.silent = opt.silent; succ!(render!()); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/yanked.rs
yazi-actor/src/lives/yanked.rs
use std::ops::Deref; use mlua::{AnyUserData, MetaMethod, MultiValue, ObjectLike, UserData, UserDataFields, UserDataMethods}; use yazi_binding::{Iter, get_metatable}; use super::{Lives, PtrCell}; pub(super) struct Yanked { inner: PtrCell<yazi_core::mgr::Yanked>, iter: AnyUserData, } impl Deref for Yanked { type Target = yazi_core::mgr::Yanked; fn deref(&self) -> &Self::Target { &self.inner } } impl Yanked { pub(super) fn make(inner: &yazi_core::mgr::Yanked) -> mlua::Result<AnyUserData> { let inner = PtrCell::from(inner); Lives::scoped_userdata(Self { inner, iter: Lives::scoped_userdata(Iter::new( inner.as_static().iter().map(yazi_binding::Url::new), Some(inner.len()), ))?, }) } } impl UserData for Yanked { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { fields.add_field_method_get("is_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.iter)? .call_function::<MultiValue>(MetaMethod::Pairs.name(), me.iter.clone()) }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/tasks.rs
yazi-actor/src/lives/tasks.rs
use std::ops::Deref; use mlua::{AnyUserData, LuaSerdeExt, UserData, UserDataFields, Value}; use yazi_binding::{SER_OPT, cached_field, deprecate}; use super::{Lives, PtrCell}; use crate::lives::TaskSnap; pub(super) struct Tasks { inner: PtrCell<yazi_core::tasks::Tasks>, v_snaps: Option<Value>, v_summary: Option<Value>, v_progress: Option<Value>, } impl Deref for Tasks { type Target = yazi_core::tasks::Tasks; fn deref(&self) -> &Self::Target { &self.inner } } impl Tasks { pub(super) fn make(inner: &yazi_core::tasks::Tasks) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { inner: inner.into(), v_snaps: None, v_summary: None, v_progress: None, }) } } impl UserData for Tasks { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { fields.add_field_method_get("cursor", |_, me| Ok(me.cursor)); cached_field!(fields, snaps, |lua, me| { let tbl = lua.create_table_with_capacity(me.snaps.len(), 0)?; for snap in &me.snaps { tbl.raw_push(TaskSnap::make(snap)?)?; } Ok(tbl) }); cached_field!(fields, summary, |lua, me| lua.to_value_with(&me.summary, SER_OPT)); cached_field!(fields, progress, |lua, me| { deprecate!( lua, "`cx.tasks.progress` is deprecated, use `cx.tasks.summary` instead, in your {}" ); lua.create_table_from([ ("total", me.summary.total), ("succ", me.summary.success), ("fail", me.summary.failed), ("found", 0), ("processed", 0), ]) }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/tabs.rs
yazi-actor/src/lives/tabs.rs
use std::ops::Deref; use mlua::{AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods}; use super::{Lives, PtrCell, Tab}; pub(super) struct Tabs { inner: PtrCell<yazi_core::mgr::Tabs>, } impl Deref for Tabs { type Target = yazi_core::mgr::Tabs; fn deref(&self) -> &Self::Target { &self.inner } } impl Tabs { pub(super) fn make(inner: &yazi_core::mgr::Tabs) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { inner: inner.into() }) } } impl UserData for Tabs { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { fields.add_field_method_get("idx", |_, me| Ok(me.cursor + 1)); } fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) { methods.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len())); methods.add_meta_method(MetaMethod::Index, |_, me, idx: usize| { if idx > me.len() || idx == 0 { Ok(None) } else { Some(Tab::make(&me[idx - 1])).transpose() } }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/finder.rs
yazi-actor/src/lives/finder.rs
use std::ops::Deref; use mlua::{AnyUserData, MetaMethod, UserData, UserDataMethods}; use super::{Lives, PtrCell}; pub(super) struct Finder { inner: PtrCell<yazi_core::tab::Finder>, } impl Deref for Finder { type Target = yazi_core::tab::Finder; fn deref(&self) -> &Self::Target { &self.inner } } impl Finder { pub(super) fn make(inner: &yazi_core::tab::Finder) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { inner: inner.into() }) } } impl UserData for Finder { fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) { methods.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.filter.to_string())); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/filter.rs
yazi-actor/src/lives/filter.rs
use std::ops::Deref; use mlua::{AnyUserData, MetaMethod, UserData, UserDataMethods}; use super::{Lives, PtrCell}; pub(super) struct Filter { inner: PtrCell<yazi_fs::Filter>, } impl Deref for Filter { type Target = yazi_fs::Filter; fn deref(&self) -> &Self::Target { &self.inner } } impl Filter { pub(super) fn make(inner: &yazi_fs::Filter) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { inner: inner.into() }) } } impl UserData for Filter { fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) { methods.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.to_string())); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/core.rs
yazi-actor/src/lives/core.rs
use std::ops::Deref; use mlua::{AnyUserData, IntoLua, MetaMethod, UserData, Value}; use paste::paste; use super::{Lives, PtrCell}; pub(super) struct Core { inner: PtrCell<yazi_core::Core>, c_active: Option<Value>, c_tabs: Option<Value>, c_tasks: Option<Value>, c_yanked: Option<Value>, c_layer: Option<Value>, } impl Deref for Core { type Target = yazi_core::Core; fn deref(&self) -> &Self::Target { &self.inner } } impl Core { pub(super) fn make(inner: &yazi_core::Core) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { inner: inner.into(), c_active: None, c_tabs: None, c_tasks: None, c_yanked: None, c_layer: None, }) } } impl UserData for Core { fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) { methods.add_meta_method_mut(MetaMethod::Index, |lua, me, key: mlua::String| { macro_rules! reuse { ($key:ident, $value:expr) => { match paste! { &me.[<c_ $key>] } { Some(v) => v.clone(), None => { let v = $value?.into_lua(lua)?; paste! { me.[<c_ $key>] = Some(v.clone()); }; v } } }; } Ok(match &*key.as_bytes() { b"active" => reuse!(active, super::Tab::make(me.active())), b"tabs" => reuse!(tabs, super::Tabs::make(&me.mgr.tabs)), b"tasks" => reuse!(tasks, super::Tasks::make(&me.tasks)), b"yanked" => reuse!(yanked, super::Yanked::make(&me.mgr.yanked)), b"layer" => { reuse!(layer, Ok::<_, mlua::Error>(yazi_plugin::bindings::Layer::from(me.layer()))) } _ => Value::Nil, }) }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/lives.rs
yazi-actor/src/lives/lives.rs
use std::cell::RefCell; use hashbrown::HashMap; use mlua::{AnyUserData, UserData}; use scopeguard::defer; use tracing::error; use yazi_plugin::LUA; use yazi_shared::RoCell; use super::{Core, PtrCell}; static TO_DESTROY: RoCell<RefCell<Vec<AnyUserData>>> = RoCell::new_const(RefCell::new(Vec::new())); pub(super) static FILE_CACHE: RoCell<RefCell<HashMap<PtrCell<yazi_fs::File>, AnyUserData>>> = RoCell::new(); pub struct Lives; impl Lives { pub fn scope<T>(core: &yazi_core::Core, f: impl FnOnce() -> mlua::Result<T>) -> mlua::Result<T> { FILE_CACHE.init(Default::default()); defer! { FILE_CACHE.drop(); } let result = LUA.scope(|scope| { scope.add_destructor(|| { for ud in TO_DESTROY.borrow_mut().drain(..) { ud.destroy().expect("failed to destruct scoped userdata"); } }); LUA.set_named_registry_value("cx", scope.create_any_userdata_ref(core)?)?; LUA.globals().raw_set("cx", Core::make(core)?)?; f() }); if let Err(ref e) = result { error!("{e}"); } result } pub(crate) fn scoped_userdata<T>(data: T) -> mlua::Result<AnyUserData> where T: UserData + 'static, { let ud = LUA.create_userdata(data)?; TO_DESTROY.borrow_mut().push(ud.clone()); Ok(ud) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/file.rs
yazi-actor/src/lives/file.rs
use std::{ops::Deref, ptr}; use mlua::{AnyUserData, IntoLua, UserData, UserDataFields, UserDataMethods, Value}; use yazi_binding::{Style, cached_field}; use yazi_config::THEME; use yazi_plugin::bindings::Range; use yazi_shared::{path::AsPath, url::UrlLike}; use super::Lives; use crate::lives::PtrCell; pub(super) struct File { idx: usize, folder: PtrCell<yazi_core::tab::Folder>, tab: PtrCell<yazi_core::tab::Tab>, v_cha: Option<Value>, v_url: Option<Value>, v_link_to: Option<Value>, v_name: Option<Value>, v_path: Option<Value>, v_cache: Option<Value>, v_bare: Option<Value>, } impl Deref for File { type Target = yazi_fs::File; fn deref(&self) -> &Self::Target { &self.folder.files[self.idx] } } impl AsRef<yazi_fs::File> for File { fn as_ref(&self) -> &yazi_fs::File { self } } impl File { pub(super) fn make( idx: usize, folder: &yazi_core::tab::Folder, tab: &yazi_core::tab::Tab, ) -> mlua::Result<AnyUserData> { use hashbrown::hash_map::Entry; Ok(match super::FILE_CACHE.borrow_mut().entry(PtrCell(&folder.files[idx])) { Entry::Occupied(oe) => oe.into_mut().clone(), Entry::Vacant(ve) => { let ud = Lives::scoped_userdata(Self { idx, folder: folder.into(), tab: tab.into(), v_cha: None, v_url: None, v_link_to: None, v_name: None, v_path: None, v_cache: None, v_bare: None, })?; ve.insert(ud.clone()); ud } }) } } impl UserData for File { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { yazi_binding::impl_file_fields!(fields); cached_field!(fields, bare, |_, me| Ok(yazi_binding::File::new(&**me))); fields.add_field_method_get("idx", |_, me| Ok(me.idx + 1)); fields.add_field_method_get("is_hovered", |_, me| Ok(me.idx == me.folder.cursor)); fields.add_field_method_get("in_current", |_, me| Ok(ptr::eq(&*me.folder, &me.tab.current))); fields.add_field_method_get("in_preview", |_, me| { Ok(me.idx == me.folder.cursor && me.tab.hovered().is_some_and(|f| f.url == me.folder.url)) }); } fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) { yazi_binding::impl_file_methods!(methods); methods.add_method("size", |_, me, ()| { Ok(if me.is_dir() { me.folder.files.sizes.get(&me.urn()).copied() } else { Some(me.len) }) }); methods.add_method("mime", |lua, me, ()| { lua.named_registry_value::<AnyUserData>("cx")?.borrow_scoped(|core: &yazi_core::Core| { core.mgr.mimetype.get(&me.url).map(|s| lua.create_string(s)).transpose() })? }); methods.add_method("prefix", |lua, me, ()| { if !me.url.has_trail() { return Ok(None); } let mut comp = me.url.try_strip_prefix(me.url.trail()).unwrap_or(me.url.loc()).components(); comp.next_back(); Some(lua.create_string(comp.as_path().encoded_bytes())).transpose() }); methods.add_method("style", |lua, me, ()| { lua.named_registry_value::<AnyUserData>("cx")?.borrow_scoped(|core: &yazi_core::Core| { let mime = core.mgr.mimetype.get(&me.url).unwrap_or_default(); THEME.filetype.iter().find(|&x| x.matches(me, mime)).map(|x| Style::from(x.style)) }) }); methods.add_method("is_yanked", |lua, me, ()| { lua.named_registry_value::<AnyUserData>("cx")?.borrow_scoped(|core: &yazi_core::Core| { if !core.mgr.yanked.contains(&me.url) { 0u8 } else if core.mgr.yanked.cut { 2u8 } else { 1u8 } }) }); methods.add_method("is_marked", |_, me, ()| { use yazi_core::tab::Mode::*; if !me.tab.mode.is_visual() || me.folder.url != me.tab.current.url { return Ok(0u8); } Ok(match &me.tab.mode { Select(_, indices) if indices.contains(&me.idx) => 1u8, Unset(_, indices) if indices.contains(&me.idx) => 2u8, _ => 0u8, }) }); methods.add_method("is_selected", |_, me, ()| Ok(me.tab.selected.contains(&me.url))); methods.add_method("found", |lua, me, ()| { lua.named_registry_value::<AnyUserData>("cx")?.borrow_scoped(|core: &yazi_core::Core| { let Some(finder) = &core.active().finder else { return Ok(None); }; let Some(idx) = finder.matched_idx(&me.folder, me.urn()) else { return Ok(None); }; Some(lua.create_sequence_from([idx.into_lua(lua)?, finder.matched.len().into_lua(lua)?])) .transpose() }) }); methods.add_method("highlights", |lua, me, ()| { lua.named_registry_value::<AnyUserData>("cx")?.borrow_scoped(|core: &yazi_core::Core| { let Some(finder) = &core.active().finder else { return None; }; if me.folder.url != me.tab.current.url { return None; } let h = finder.filter.highlighted(me.url.name()?)?; Some(h.into_iter().map(Range::from).collect::<Vec<_>>()) }) }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/preference.rs
yazi-actor/src/lives/preference.rs
use std::ops::Deref; use mlua::{AnyUserData, UserData, UserDataFields, Value}; use yazi_binding::cached_field; use super::{Lives, PtrCell}; pub(super) struct Preference { inner: PtrCell<yazi_core::tab::Preference>, v_sort_by: Option<Value>, v_linemode: Option<Value>, } impl Deref for Preference { type Target = yazi_core::tab::Preference; fn deref(&self) -> &Self::Target { &self.inner } } impl Preference { pub(super) fn make(inner: &yazi_core::tab::Preference) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { inner: inner.into(), v_sort_by: None, v_linemode: None }) } } impl UserData for Preference { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { cached_field!(fields, sort_by, |_, me| Ok(me.sort_by.to_string())); fields.add_field_method_get("sort_sensitive", |_, me| Ok(me.sort_sensitive)); fields.add_field_method_get("sort_reverse", |_, me| Ok(me.sort_reverse)); fields.add_field_method_get("sort_dir_first", |_, me| Ok(me.sort_dir_first)); fields.add_field_method_get("sort_translit", |_, me| Ok(me.sort_translit)); cached_field!(fields, linemode, |lua, me| lua.create_string(&me.linemode)); fields.add_field_method_get("show_hidden", |_, me| Ok(me.show_hidden)); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/mod.rs
yazi-actor/src/lives/mod.rs
yazi_macro::mod_flat!(core file files filter finder folder lives mode preference preview ptr selected tab tabs task tasks yanked);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/files.rs
yazi-actor/src/lives/files.rs
use std::ops::{Deref, Range}; use mlua::{AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods, Value}; use yazi_binding::cached_field; use super::{File, Filter, Lives, PtrCell}; pub(super) struct Files { window: Range<usize>, folder: PtrCell<yazi_core::tab::Folder>, tab: PtrCell<yazi_core::tab::Tab>, v_filter: Option<Value>, } impl Deref for Files { type Target = yazi_fs::Files; fn deref(&self) -> &Self::Target { &self.folder.files } } impl Files { pub(super) fn make( window: Range<usize>, folder: &yazi_core::tab::Folder, tab: &yazi_core::tab::Tab, ) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { window, folder: folder.into(), tab: tab.into(), v_filter: None }) } } impl UserData for Files { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { cached_field!(fields, filter, |_, me| me.filter().map(Filter::make).transpose()); } fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) { methods.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.window.end - me.window.start)); methods.add_meta_method(MetaMethod::Index, |_, me, mut idx: usize| { idx += me.window.start; if idx > me.window.end || idx == 0 { Ok(None) } else { Some(File::make(idx - 1, &me.folder, &me.tab)).transpose() } }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/task.rs
yazi-actor/src/lives/task.rs
use std::ops::Deref; use mlua::{AnyUserData, LuaSerdeExt, UserData, UserDataFields, Value}; use yazi_binding::{SER_OPT, cached_field}; use super::{Lives, PtrCell}; pub(super) struct TaskSnap { inner: PtrCell<yazi_scheduler::TaskSnap>, v_name: Option<Value>, v_prog: Option<Value>, } impl Deref for TaskSnap { type Target = yazi_scheduler::TaskSnap; fn deref(&self) -> &Self::Target { &self.inner } } impl TaskSnap { pub(super) fn make(inner: &yazi_scheduler::TaskSnap) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { inner: inner.into(), v_name: None, v_prog: None }) } } impl UserData for TaskSnap { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { cached_field!(fields, name, |lua, me| lua.create_string(&me.name)); cached_field!(fields, prog, |lua, me| lua.to_value_with(&me.prog, SER_OPT)); fields.add_field_method_get("cooked", |_, me| Ok(me.prog.cooked())); fields.add_field_method_get("running", |_, me| Ok(me.prog.running())); fields.add_field_method_get("success", |_, me| Ok(me.prog.success())); fields.add_field_method_get("failed", |_, me| Ok(me.prog.failed())); fields.add_field_method_get("percent", |_, me| Ok(me.prog.percent())); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/selected.rs
yazi-actor/src/lives/selected.rs
use mlua::AnyUserData; use super::Lives; use crate::lives::PtrCell; #[derive(Clone, Copy)] pub(super) struct Selected; impl Selected { pub(super) fn make(inner: &yazi_core::tab::Selected) -> mlua::Result<AnyUserData> { let inner = PtrCell::from(inner); Lives::scoped_userdata(yazi_binding::Iter::new( inner.as_static().values().map(yazi_binding::Url::new), Some(inner.len()), )) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/ptr.rs
yazi-actor/src/lives/ptr.rs
use std::{hash::{Hash, Hasher}, ops::Deref}; pub(super) struct PtrCell<T>(pub(super) *const T); impl<T> Deref for PtrCell<T> { type Target = T; fn deref(&self) -> &Self::Target { unsafe { &*self.0 } } } impl<T> From<&T> for PtrCell<T> { fn from(value: &T) -> Self { Self(value) } } impl<T> Clone for PtrCell<T> { fn clone(&self) -> Self { *self } } impl<T> Copy for PtrCell<T> {} impl<T> PartialEq for PtrCell<T> { fn eq(&self, other: &Self) -> bool { self.0.addr() == other.0.addr() } } impl<T> Eq for PtrCell<T> {} impl<T> Hash for PtrCell<T> { fn hash<H: Hasher>(&self, state: &mut H) { state.write_usize(self.0.addr()); } } impl<T> PtrCell<T> { #[inline] pub(super) fn as_static(&self) -> &'static T { unsafe { &*self.0 } } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/mode.rs
yazi-actor/src/lives/mode.rs
use std::ops::Deref; use mlua::{AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods}; use super::{Lives, PtrCell}; pub(super) struct Mode { inner: PtrCell<yazi_core::tab::Mode>, } impl Deref for Mode { type Target = yazi_core::tab::Mode; fn deref(&self) -> &Self::Target { &self.inner } } impl Mode { pub(super) fn make(inner: &yazi_core::tab::Mode) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { inner: inner.into() }) } } impl UserData for Mode { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { fields.add_field_method_get("is_select", |_, me| Ok(me.is_select())); fields.add_field_method_get("is_unset", |_, me| Ok(me.is_unset())); fields.add_field_method_get("is_visual", |_, me| Ok(me.is_visual())); } fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) { methods.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.to_string())); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/folder.rs
yazi-actor/src/lives/folder.rs
use std::ops::{Deref, Range}; use mlua::{AnyUserData, UserData, UserDataFields, Value}; use yazi_binding::{FolderStage, Url, cached_field}; use yazi_config::LAYOUT; use super::{File, Files, Lives, PtrCell}; pub(super) struct Folder { window: Range<usize>, inner: PtrCell<yazi_core::tab::Folder>, tab: PtrCell<yazi_core::tab::Tab>, v_cwd: Option<Value>, v_files: Option<Value>, v_stage: Option<Value>, v_window: Option<Value>, v_hovered: Option<Value>, } impl Deref for Folder { type Target = yazi_core::tab::Folder; fn deref(&self) -> &Self::Target { &self.inner } } impl Folder { pub(super) fn make( window: Option<Range<usize>>, inner: &yazi_core::tab::Folder, tab: &yazi_core::tab::Tab, ) -> mlua::Result<AnyUserData> { let window = match window { Some(w) => w, None => { let limit = LAYOUT.get().preview.height as usize; inner.offset..inner.files.len().min(inner.offset + limit) } }; Lives::scoped_userdata(Self { window, inner: inner.into(), tab: tab.into(), v_cwd: None, v_files: None, v_stage: None, v_window: None, v_hovered: None, }) } } impl UserData for Folder { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { cached_field!(fields, cwd, |_, me| Ok(Url::new(&me.url))); cached_field!(fields, files, |_, me| Files::make(0..me.files.len(), me, &me.tab)); cached_field!(fields, stage, |_, me| Ok(FolderStage::new(me.stage.clone()))); cached_field!(fields, window, |_, me| Files::make(me.window.clone(), me, &me.tab)); fields.add_field_method_get("offset", |_, me| Ok(me.offset)); fields.add_field_method_get("cursor", |_, me| Ok(me.cursor)); cached_field!(fields, hovered, |_, me| { me.hovered().map(|_| File::make(me.cursor, me, &me.tab)).transpose() }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/preview.rs
yazi-actor/src/lives/preview.rs
use std::ops::Deref; use mlua::{AnyUserData, UserData, UserDataFields, Value}; use yazi_binding::cached_field; use yazi_config::LAYOUT; use super::{Folder, Lives, PtrCell}; pub(super) struct Preview { tab: PtrCell<yazi_core::tab::Tab>, v_folder: Option<Value>, } impl Deref for Preview { type Target = yazi_core::tab::Preview; fn deref(&self) -> &Self::Target { &self.tab.preview } } impl Preview { pub(super) fn make(tab: &yazi_core::tab::Tab) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { tab: tab.into(), v_folder: None }) } } impl UserData for Preview { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { fields.add_field_method_get("skip", |_, me| Ok(me.skip)); cached_field!(fields, folder, |_, me| { me.tab .hovered_folder() .map(|f| { let limit = LAYOUT.get().preview.height as usize; Folder::make(Some(me.skip..f.files.len().min(me.skip + limit)), f, &me.tab) }) .transpose() }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-actor/src/lives/tab.rs
yazi-actor/src/lives/tab.rs
use std::ops::Deref; use mlua::{AnyUserData, UserData, UserDataFields, UserDataMethods, Value}; use yazi_binding::{Id, UrlRef, cached_field}; use yazi_shared::url::UrlLike; use super::{Finder, Folder, Lives, Mode, Preference, Preview, PtrCell, Selected}; pub(super) struct Tab { inner: PtrCell<yazi_core::tab::Tab>, v_name: Option<Value>, v_mode: Option<Value>, v_pref: Option<Value>, v_current: Option<Value>, v_parent: Option<Value>, v_selected: Option<Value>, v_preview: Option<Value>, v_finder: Option<Value>, } impl Deref for Tab { type Target = yazi_core::tab::Tab; fn deref(&self) -> &Self::Target { &self.inner } } impl Tab { pub(super) fn make(inner: &yazi_core::tab::Tab) -> mlua::Result<AnyUserData> { Lives::scoped_userdata(Self { inner: inner.into(), v_name: None, v_mode: None, v_pref: None, v_current: None, v_parent: None, v_selected: None, v_preview: None, v_finder: None, }) } } impl UserData for Tab { fn add_fields<F: UserDataFields<Self>>(fields: &mut F) { fields.add_field_method_get("id", |_, me| Ok(Id(me.id))); cached_field!(fields, name, |lua, me| { let url = &me.current.url; lua.create_string(url.name().map_or_else(|| url.loc().encoded_bytes(), |n| n.encoded_bytes())) }); cached_field!(fields, mode, |_, me| Mode::make(&me.mode)); cached_field!(fields, pref, |_, me| Preference::make(&me.pref)); cached_field!(fields, current, |_, me| Folder::make(None, &me.current, me)); cached_field!(fields, parent, |_, me| { me.parent.as_ref().map(|f| Folder::make(None, f, me)).transpose() }); cached_field!(fields, selected, |_, me| Selected::make(&me.selected)); cached_field!(fields, preview, |_, me| Preview::make(me)); cached_field!(fields, finder, |_, me| me.finder.as_ref().map(Finder::make).transpose()); } fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) { methods.add_method("history", |_, me, url: UrlRef| { me.history.get(url.as_ref()).map(|f| Folder::make(None, f, me)).transpose() }); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/icon.rs
yazi-config/src/icon.rs
use crate::Style; #[derive(Clone, Debug)] pub struct Icon { pub text: String, pub style: Style, }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/lib.rs
yazi-config/src/lib.rs
yazi_macro::mod_pub!(keymap mgr open opener plugin popup preview tasks theme which vfs); yazi_macro::mod_flat!(icon layout pattern platform preset priority style utils yazi); use std::io::{Read, Write}; use yazi_shared::{RoCell, SyncCell}; use yazi_term::tty::TTY; pub static YAZI: RoCell<yazi::Yazi> = RoCell::new(); pub static KEYMAP: RoCell<keymap::Keymap> = RoCell::new(); pub static THEME: RoCell<theme::Theme> = RoCell::new(); pub static LAYOUT: SyncCell<Layout> = SyncCell::new(Layout::default()); pub fn init() -> anyhow::Result<()> { if let Err(e) = try_init(true) { wait_for_key(e)?; try_init(false)?; } Ok(()) } fn try_init(merge: bool) -> anyhow::Result<()> { let mut yazi = Preset::yazi()?; let mut keymap = Preset::keymap()?; if merge { yazi = yazi.deserialize_over(toml::Deserializer::parse(&yazi::Yazi::read()?)?)?; keymap = keymap.deserialize_over(toml::Deserializer::parse(&keymap::Keymap::read()?)?)?; } YAZI.init(yazi.reshape()?); KEYMAP.init(keymap.reshape()?); Ok(()) } pub fn init_flavor(light: bool) -> anyhow::Result<()> { if let Err(e) = try_init_flavor(light, true) { wait_for_key(e)?; try_init_flavor(light, false)?; } Ok(()) } fn try_init_flavor(light: bool, merge: bool) -> anyhow::Result<()> { let mut theme = Preset::theme(light)?; if merge { let shadow = theme::Theme::deserialize_shadow(toml::Deserializer::parse(&theme::Theme::read()?)?)?; let flavor = shadow.flavor.as_ref().map(theme::Flavor::from).unwrap_or_default().read(light)?; theme = theme.deserialize_over(toml::Deserializer::parse(&flavor)?)?; theme = theme.deserialize_over_with::<toml::Value>(shadow)?; } THEME.init(theme.reshape(light)?); Ok(()) } fn wait_for_key(e: anyhow::Error) -> anyhow::Result<()> { let stdout = &mut *TTY.lockout(); writeln!(stdout, "{e}")?; if let Some(src) = e.source() { writeln!(stdout, "\nCaused by:\n{src}")?; } use crossterm::style::{Attribute, Print, SetAttributes}; crossterm::execute!( stdout, SetAttributes(Attribute::Reverse.into()), SetAttributes(Attribute::Bold.into()), Print("Press <Enter> to continue with preset settings..."), SetAttributes(Attribute::Reset.into()), Print("\n"), )?; TTY.reader().read_exact(&mut [0])?; Ok(()) }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/pattern.rs
yazi-config/src/pattern.rs
use std::{fmt::Debug, str::FromStr}; use anyhow::{Result, bail}; use globset::{Candidate, GlobBuilder}; use serde::Deserialize; use yazi_shared::{scheme::SchemeKind, url::AsUrl}; #[derive(Deserialize)] #[serde(try_from = "String")] pub struct Pattern { inner: globset::GlobMatcher, scheme: PatternScheme, pub is_dir: bool, is_star: bool, #[cfg(windows)] sep_lit: bool, } impl Debug for Pattern { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Pattern") .field("regex", &self.inner.glob().regex()) .field("scheme", &self.scheme) .field("is_dir", &self.is_dir) .field("is_star", &self.is_star) .finish() } } impl Pattern { pub fn match_url(&self, url: impl AsUrl, is_dir: bool) -> bool { let url = url.as_url(); if is_dir != self.is_dir { return false; } else if !self.scheme.matches(url.kind()) { return false; } else if self.is_star { return true; } #[cfg(unix)] { self.inner.is_match_candidate(&Candidate::from_bytes(url.loc().encoded_bytes())) } #[cfg(windows)] if self.sep_lit { use yazi_shared::strand::{AsStrand, StrandLike}; self.inner.is_match_candidate(&Candidate::from_bytes( url.loc().as_strand().backslash_to_slash().encoded_bytes(), )) } else { self.inner.is_match_candidate(&Candidate::from_bytes(url.loc().encoded_bytes())) } } pub fn match_mime(&self, mime: impl AsRef<str>) -> bool { self.is_star || (!mime.as_ref().is_empty() && self.inner.is_match(mime.as_ref())) } #[inline] pub fn any_file(&self) -> bool { self.is_star && !self.is_dir } #[inline] pub fn any_dir(&self) -> bool { self.is_star && self.is_dir } } impl FromStr for Pattern { type Err = anyhow::Error; fn from_str(s: &str) -> Result<Self, Self::Err> { // Trim leading case-sensitive indicator let a = s.trim_start_matches(r"\s"); // Parse the URL scheme if present let (scheme, skip) = PatternScheme::parse(a)?; let b = &a[skip..]; // Trim the ending slash which indicates a directory let c = b.trim_end_matches('/'); // Check whether it's a filename pattern or a full path pattern let sep_lit = c.contains('/'); let inner = GlobBuilder::new(c) .case_insensitive(a.len() == s.len()) .literal_separator(sep_lit) .backslash_escape(false) .empty_alternates(true) .build()? .compile_matcher(); Ok(Self { inner, scheme, is_dir: c.len() < b.len(), is_star: c == "*", #[cfg(windows)] sep_lit, }) } } impl TryFrom<String> for Pattern { type Error = anyhow::Error; fn try_from(s: String) -> Result<Self, Self::Error> { Self::from_str(s.as_str()) } } // --- Scheme #[derive(Clone, Copy, Debug)] enum PatternScheme { Any, Local, Remote, Virtual, Regular, Search, Archive, Sftp, } impl PatternScheme { fn parse(s: &str) -> Result<(Self, usize)> { let Some((protocol, _)) = s.split_once("://") else { return Ok((Self::Any, 0)); }; let scheme = match protocol { "*" => Self::Any, "local" => Self::Local, "remote" => Self::Remote, "virtual" => Self::Virtual, "regular" => Self::Regular, "search" => Self::Search, "archive" => Self::Archive, "sftp" => Self::Sftp, "" => bail!("Invalid URL pattern: protocol is empty"), _ => bail!("Unknown protocol in URL pattern: {protocol}"), }; Ok((scheme, protocol.len() + 3)) } #[inline] fn matches(self, kind: SchemeKind) -> bool { use SchemeKind as K; match (self, kind) { (Self::Any, _) => true, (Self::Local, s) => s.is_local(), (Self::Remote, s) => s.is_remote(), (Self::Virtual, s) => s.is_virtual(), (Self::Regular, K::Regular) => true, (Self::Search, K::Search) => true, (Self::Archive, K::Archive) => true, (Self::Sftp, K::Sftp) => true, _ => false, } } } // --- Tests #[cfg(test)] mod tests { use yazi_shared::url::UrlCow; use super::*; fn matches(glob: &str, url: &str) -> bool { Pattern::from_str(glob).unwrap().match_url(UrlCow::try_from(url).unwrap(), false) } #[cfg(unix)] #[test] fn test_unix() { // Wildcard assert!(matches("*", "/foo")); assert!(matches("*", "/foo/bar")); assert!(matches("**", "foo")); assert!(matches("**", "/foo")); assert!(matches("**", "/foo/bar")); // Filename assert!(matches("*.md", "foo.md")); assert!(matches("*.md", "/foo.md")); assert!(matches("*.md", "/foo/bar.md")); // 1-star assert!(matches("/*", "/foo")); assert!(matches("/*/*.md", "/foo/bar.md")); // 2-star assert!(matches("/**", "/foo")); assert!(matches("/**", "/foo/bar")); assert!(matches("**/**", "/foo")); assert!(matches("**/**", "/foo/bar")); assert!(matches("/**/*", "/foo")); assert!(matches("/**/*", "/foo/bar")); // Failures assert!(!matches("/*/*", "/foo")); assert!(!matches("/*/*.md", "/foo.md")); assert!(!matches("/*", "/foo/bar")); assert!(!matches("/*.md", "/foo/bar.md")); } #[cfg(windows)] #[test] fn test_windows() { // Wildcard assert!(matches("*", r#"C:\foo"#)); assert!(matches("*", r#"C:\foo\bar"#)); assert!(matches("**", r#"foo"#)); assert!(matches("**", r#"C:\foo"#)); assert!(matches("**", r#"C:\foo\bar"#)); // Filename assert!(matches("*.md", r#"foo.md"#)); assert!(matches("*.md", r#"C:\foo.md"#)); assert!(matches("*.md", r#"C:\foo\bar.md"#)); // 1-star assert!(matches(r#"C:/*"#, r#"C:\foo"#)); assert!(matches(r#"C:/*/*.md"#, r#"C:\foo\bar.md"#)); // 2-star assert!(matches(r#"C:/**"#, r#"C:\foo"#)); assert!(matches(r#"C:/**"#, r#"C:\foo\bar"#)); assert!(matches(r#"**/**"#, r#"C:\foo"#)); assert!(matches(r#"**/**"#, r#"C:\foo\bar"#)); assert!(matches(r#"C:/**/*"#, r#"C:\foo"#)); assert!(matches(r#"C:/**/*"#, r#"C:\foo\bar"#)); // Drive letter assert!(matches(r#"*:/*"#, r#"C:\foo"#)); assert!(matches(r#"*:/**/*.md"#, r#"C:\foo\bar.md"#)); // Failures assert!(!matches(r#"C:/*/*"#, r#"C:\foo"#)); assert!(!matches(r#"C:/*/*.md"#, r#"C:\foo.md"#)); assert!(!matches(r#"C:/*"#, r#"C:\foo\bar"#)); assert!(!matches(r#"C:/*.md"#, r#"C:\foo\bar.md"#)); } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/preset.rs
yazi-config/src/preset.rs
use crate::{Yazi, keymap::Keymap, theme::Theme, vfs::Vfs}; pub(crate) struct Preset; impl Preset { pub(super) fn yazi() -> Result<Yazi, toml::de::Error> { toml::from_str(&yazi_macro::config_preset!("yazi")) } pub(super) fn keymap() -> Result<Keymap, toml::de::Error> { toml::from_str(&yazi_macro::config_preset!("keymap")) } pub(super) fn theme(light: bool) -> Result<Theme, toml::de::Error> { toml::from_str(&if light { yazi_macro::theme_preset!("light") } else { yazi_macro::theme_preset!("dark") }) } pub(super) fn vfs() -> Result<Vfs, toml::de::Error> { toml::from_str(&yazi_macro::config_preset!("vfs")) } #[inline] pub(crate) fn mix<E, A, B, C>(a: A, b: B, c: C) -> impl Iterator<Item = E> where A: IntoIterator<Item = E>, B: IntoIterator<Item = E>, C: IntoIterator<Item = E>, { a.into_iter().chain(b).chain(c) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/platform.rs
yazi-config/src/platform.rs
#[inline] pub(crate) fn check_for(r#for: Option<&str>) -> bool { match r#for.as_ref().map(|s| s.as_ref()) { Some("unix") if cfg!(unix) => true, Some(os) if os == std::env::consts::OS => true, Some(_) => false, None => true, } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/utils.rs
yazi-config/src/utils.rs
use std::path::PathBuf; use yazi_fs::path::{clean_url, expand_url}; use yazi_shared::url::UrlBuf; pub(crate) fn normalize_path(path: PathBuf) -> Option<PathBuf> { clean_url(yazi_fs::provider::local::try_absolute(expand_url(UrlBuf::from(path)))?) .into_loc() .into_os() .ok() .filter(|p| p.as_os_str().is_empty() || p.is_absolute()) }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/layout.rs
yazi-config/src/layout.rs
use ratatui::layout::Rect; #[derive(Clone, Copy, Default, Eq, PartialEq)] pub struct Layout { pub current: Rect, pub preview: Rect, pub progress: Rect, } impl Layout { pub const fn default() -> Self { Self { current: Rect::ZERO, preview: Rect::ZERO, progress: Rect::ZERO } } pub const fn folder_limit(self) -> usize { self.current.height as _ } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/style.rs
yazi-config/src/style.rs
use ratatui::style::Color; use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)] pub struct Style { pub fg: Option<Color>, pub bg: Option<Color>, pub bold: Option<bool>, pub dim: Option<bool>, pub italic: Option<bool>, pub underline: Option<bool>, pub blink: Option<bool>, pub blink_rapid: Option<bool>, pub reversed: Option<bool>, pub hidden: Option<bool>, pub crossed: Option<bool>, } impl From<ratatui::style::Style> for Style { #[rustfmt::skip] fn from(value: ratatui::style::Style) -> Self { use ratatui::style::Modifier as M; let sub = value.sub_modifier; let all = value.add_modifier - sub; Self { fg: value.fg, bg: value.bg, bold: if all.contains(M::BOLD) { Some(true) } else if sub.contains(M::BOLD) { Some(false) } else { None }, dim: if all.contains(M::DIM) { Some(true) } else if sub.contains(M::DIM) { Some(false) } else { None }, italic: if all.contains(M::ITALIC) { Some(true) } else if sub.contains(M::ITALIC) { Some(false) } else { None }, underline: if all.contains(M::UNDERLINED) { Some(true) } else if sub.contains(M::UNDERLINED) { Some(false) } else { None }, blink: if all.contains(M::SLOW_BLINK) { Some(true) } else if sub.contains(M::SLOW_BLINK) { Some(false) } else { None }, blink_rapid: if all.contains(M::RAPID_BLINK) { Some(true) } else if sub.contains(M::RAPID_BLINK) { Some(false) } else { None }, reversed: if all.contains(M::REVERSED) { Some(true) } else if sub.contains(M::REVERSED) { Some(false) } else { None }, hidden: if all.contains(M::HIDDEN) { Some(true) } else if sub.contains(M::HIDDEN) { Some(false) } else { None }, crossed: if all.contains(M::CROSSED_OUT) { Some(true) } else if sub.contains(M::CROSSED_OUT) { Some(false) } else { None }, } } } impl From<Style> for ratatui::style::Style { #[rustfmt::skip] fn from(value: Style) -> Self { use ratatui::style::Modifier as M; let (mut add, mut sub) = (M::empty(), M::empty()); if let Some(b) = value.bold { if b { add |= M::BOLD } else { sub |= M::BOLD }; } if let Some(b) = value.dim { if b { add |= M::DIM } else { sub |= M::DIM }; } if let Some(b) = value.italic { if b { add |= M::ITALIC } else { sub |= M::ITALIC }; } if let Some(b) = value.underline { if b { add |= M::UNDERLINED } else { sub |= M::UNDERLINED }; } if let Some(b) = value.blink { if b { add |= M::SLOW_BLINK } else { sub |= M::SLOW_BLINK }; } if let Some(b) = value.blink_rapid { if b { add |= M::RAPID_BLINK } else { sub |= M::RAPID_BLINK }; } if let Some(b) = value.reversed { if b { add |= M::REVERSED } else { sub |= M::REVERSED }; } if let Some(b) = value.hidden { if b { add |= M::HIDDEN } else { sub |= M::HIDDEN }; } if let Some(b) = value.crossed { if b { add |= M::CROSSED_OUT } else { sub |= M::CROSSED_OUT }; } Self { fg: value.fg, bg: value.bg, underline_color: None, add_modifier: add, sub_modifier: sub, } } } impl Style { pub fn derive(self, other: ratatui::style::Style) -> ratatui::style::Style { ratatui::style::Style::from(self).patch(other) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/priority.rs
yazi-config/src/priority.rs
use serde::Deserialize; #[derive(Clone, Copy, Debug, Default, Deserialize)] #[serde(rename_all = "kebab-case")] pub enum Priority { Low = 0, #[default] Normal = 1, High = 2, }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/yazi.rs
yazi-config/src/yazi.rs
use anyhow::{Context, Result}; use serde::Deserialize; use yazi_codegen::DeserializeOver1; use yazi_fs::{Xdg, ok_or_not_found}; use crate::{mgr, open, opener, plugin, popup, preview, tasks, which}; #[derive(Deserialize, DeserializeOver1)] pub struct Yazi { pub mgr: mgr::Mgr, pub preview: preview::Preview, pub opener: opener::Opener, pub open: open::Open, pub tasks: tasks::Tasks, pub plugin: plugin::Plugin, pub input: popup::Input, pub confirm: popup::Confirm, pub pick: popup::Pick, pub which: which::Which, } impl Yazi { pub(super) fn read() -> Result<String> { let p = Xdg::config_dir().join("yazi.toml"); ok_or_not_found(std::fs::read_to_string(&p)) .with_context(|| format!("Failed to read config {p:?}")) } pub(super) fn reshape(self) -> Result<Self> { Ok(Self { mgr: self.mgr.reshape()?, preview: self.preview.reshape()?, opener: self.opener.reshape()?, open: self.open.reshape()?, tasks: self.tasks.reshape()?, plugin: self.plugin.reshape()?, input: self.input, confirm: self.confirm, pick: self.pick, which: self.which, }) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/opener/mod.rs
yazi-config/src/opener/mod.rs
yazi_macro::mod_flat!(opener rule);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/opener/rule.rs
yazi-config/src/opener/rule.rs
use anyhow::{Result, bail}; use serde::Deserialize; use yazi_fs::Splatter; #[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct OpenerRule { pub run: String, #[serde(default)] pub block: bool, #[serde(default)] pub orphan: bool, #[serde(default)] pub desc: String, pub r#for: Option<String>, #[serde(skip)] pub spread: bool, } impl OpenerRule { pub fn desc(&self) -> String { if !self.desc.is_empty() { self.desc.clone() } else if let Some(first) = self.run.split_whitespace().next() { first.to_owned() } else { String::new() } } } impl OpenerRule { pub(super) fn reshape(mut self) -> Result<Self> { if self.run.is_empty() { bail!("[open].rules.*.run cannot be empty."); } #[cfg(unix)] { self.spread = Splatter::<()>::spread(&self.run) || self.run.contains("$@") || self.run.contains("$*"); } #[cfg(windows)] { self.spread = Splatter::<()>::spread(&self.run) || self.run.contains("%*"); } Ok(self) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/opener/opener.rs
yazi-config/src/opener/opener.rs
use std::{mem, ops::Deref}; use anyhow::Result; use hashbrown::HashMap; use indexmap::IndexSet; use serde::Deserialize; use super::OpenerRule; use crate::check_for; #[derive(Debug, Deserialize)] pub struct Opener(HashMap<String, Vec<OpenerRule>>); impl Deref for Opener { type Target = HashMap<String, Vec<OpenerRule>>; fn deref(&self) -> &Self::Target { &self.0 } } impl Opener { pub fn all<'a, I>(&self, uses: I) -> impl Iterator<Item = &OpenerRule> where I: Iterator<Item = &'a str>, { uses.flat_map(|use_| self.get(use_)).flatten() } pub fn first<'a, I>(&self, uses: I) -> Option<&OpenerRule> where I: Iterator<Item = &'a str>, { uses.flat_map(|use_| self.get(use_)).flatten().next() } pub fn block<'a, I>(&self, uses: I) -> Option<&OpenerRule> where I: Iterator<Item = &'a str>, { uses.flat_map(|use_| self.get(use_)).flatten().find(|&o| o.block) } } impl Opener { pub(crate) fn reshape(mut self) -> Result<Self> { for rules in self.0.values_mut() { *rules = mem::take(rules) .into_iter() .map(|mut r| (r.r#for.take(), r)) .filter(|(r#for, _)| check_for(r#for.as_deref())) .map(|(_, r)| r.reshape()) .collect::<Result<IndexSet<_>>>()? .into_iter() .collect(); } Ok(self) } pub(crate) fn deserialize_over<'de, D>(mut self, deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>, { let map: HashMap<String, Vec<OpenerRule>> = HashMap::deserialize(deserializer)?; self.0.extend(map); Ok(self) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/tasks/tasks.rs
yazi-config/src/tasks/tasks.rs
use anyhow::{Result, bail}; use serde::Deserialize; use yazi_codegen::DeserializeOver2; #[derive(Debug, Deserialize, DeserializeOver2)] pub struct Tasks { pub micro_workers: u8, pub macro_workers: u8, pub bizarre_retry: u8, pub image_alloc: u32, pub image_bound: [u16; 2], pub suppress_preload: bool, } impl Tasks { pub(crate) fn reshape(self) -> Result<Self> { if self.micro_workers < 1 { bail!("[tasks].micro_workers must be at least 1."); } else if self.macro_workers < 1 { bail!("[tasks].macro_workers must be at least 1."); } else if self.bizarre_retry < 1 { bail!("[tasks].bizarre_retry` must be at least 1."); } Ok(self) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/tasks/mod.rs
yazi-config/src/tasks/mod.rs
yazi_macro::mod_flat!(tasks);
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/plugin/previewer.rs
yazi-config/src/plugin/previewer.rs
use serde::Deserialize; use yazi_fs::File; use yazi_shared::event::Cmd; use crate::Pattern; #[derive(Debug, Deserialize)] pub struct Previewer { pub url: Option<Pattern>, pub mime: Option<Pattern>, pub run: Cmd, } impl Previewer { #[inline] pub fn matches(&self, file: &File, mime: &str) -> bool { self.mime.as_ref().is_some_and(|p| p.match_mime(mime)) || self.url.as_ref().is_some_and(|p| p.match_url(&file.url, file.is_dir())) } #[inline] pub fn any_file(&self) -> bool { self.url.as_ref().is_some_and(|p| p.any_file()) } #[inline] pub fn any_dir(&self) -> bool { self.url.as_ref().is_some_and(|p| p.any_dir()) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/plugin/fetcher.rs
yazi-config/src/plugin/fetcher.rs
use serde::Deserialize; use yazi_fs::File; use yazi_shared::event::Cmd; use crate::{Pattern, Priority}; #[derive(Debug, Deserialize)] pub struct Fetcher { #[serde(skip)] pub idx: u8, pub id: String, pub url: Option<Pattern>, pub mime: Option<Pattern>, pub run: Cmd, #[serde(default)] pub prio: Priority, } impl Fetcher { #[inline] pub fn matches(&self, file: &File, mime: &str) -> bool { self.mime.as_ref().is_some_and(|p| p.match_mime(mime)) || self.url.as_ref().is_some_and(|p| p.match_url(&file.url, file.is_dir())) } }
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false
sxyazi/yazi
https://github.com/sxyazi/yazi/blob/3c39a326abaacb37d9ff15af7668756d60624dfa/yazi-config/src/plugin/mod.rs
yazi-config/src/plugin/mod.rs
yazi_macro::mod_flat!(fetcher plugin preloader previewer spotter); pub const MAX_PREWORKERS: u8 = 32;
rust
MIT
3c39a326abaacb37d9ff15af7668756d60624dfa
2026-01-04T15:33:17.426354Z
false