From 6366e46c23da43f7aae7f083d00fd989321b9638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Fri, 11 Jul 2025 09:00:22 +0800 Subject: [PATCH] refactor: use term "core" instead of "context" (#2978) --- .../src/context.rs => yazi-core/src/app.rs | 9 +-- yazi-core/src/lib.rs | 2 + yazi-fm/src/app/app.rs | 10 +-- yazi-fm/src/app/commands/accept_payload.rs | 2 +- yazi-fm/src/app/commands/mouse.rs | 2 +- yazi-fm/src/app/commands/notify.rs | 2 +- yazi-fm/src/app/commands/plugin.rs | 6 +- yazi-fm/src/app/commands/quit.rs | 6 +- yazi-fm/src/app/commands/reflow.rs | 2 +- yazi-fm/src/app/commands/render.rs | 16 ++--- yazi-fm/src/app/commands/resize.rs | 8 +-- yazi-fm/src/app/commands/resume.rs | 2 +- yazi-fm/src/app/commands/stop.rs | 2 +- yazi-fm/src/app/commands/update_notify.rs | 4 +- yazi-fm/src/app/commands/update_progress.rs | 2 +- yazi-fm/src/cmp/cmp.rs | 13 ++-- yazi-fm/src/confirm/body.rs | 9 ++- yazi-fm/src/confirm/confirm.rs | 15 ++-- yazi-fm/src/confirm/list.rs | 13 ++-- yazi-fm/src/executor.rs | 72 +++++++++---------- yazi-fm/src/help/bindings.rs | 11 ++- yazi-fm/src/help/help.rs | 10 +-- yazi-fm/src/input/input.rs | 11 ++- yazi-fm/src/lives/{context.rs => core.rs} | 14 ++-- yazi-fm/src/lives/file.rs | 24 +++---- yazi-fm/src/lives/lives.rs | 12 ++-- yazi-fm/src/lives/mod.rs | 2 +- yazi-fm/src/main.rs | 2 +- yazi-fm/src/mgr/modal.rs | 9 ++- yazi-fm/src/mgr/preview.rs | 11 ++- yazi-fm/src/notify/notify.rs | 10 ++- yazi-fm/src/pick/list.rs | 9 ++- yazi-fm/src/pick/pick.rs | 13 ++-- yazi-fm/src/root.rs | 44 ++++++------ yazi-fm/src/router.rs | 12 ++-- yazi-fm/src/spot/spot.rs | 11 ++- yazi-fm/src/tasks/progress.rs | 9 ++- yazi-fm/src/tasks/tasks.rs | 10 ++- yazi-fm/src/which/which.rs | 8 +-- 39 files changed, 210 insertions(+), 219 deletions(-) rename yazi-fm/src/context.rs => yazi-core/src/app.rs (90%) rename yazi-fm/src/lives/{context.rs => core.rs} (85%) diff --git a/yazi-fm/src/context.rs b/yazi-core/src/app.rs similarity index 90% rename from yazi-fm/src/context.rs rename to yazi-core/src/app.rs index cc1f012b..5a03df6e 100644 --- a/yazi-fm/src/context.rs +++ b/yazi-core/src/app.rs @@ -1,9 +1,10 @@ use crossterm::cursor::SetCursorStyle; use ratatui::layout::{Position, Rect}; -use yazi_core::{cmp::Cmp, confirm::Confirm, help::Help, input::Input, mgr::Mgr, notify::Notify, pick::Pick, tab::{Folder, Tab}, tasks::Tasks, which::Which}; use yazi_shared::Layer; -pub struct Ctx { +use crate::{cmp::Cmp, confirm::Confirm, help::Help, input::Input, mgr::Mgr, notify::Notify, pick::Pick, tab::{Folder, Tab}, tasks::Tasks, which::Which}; + +pub struct Core { pub mgr: Mgr, pub tasks: Tasks, pub pick: Pick, @@ -15,7 +16,7 @@ pub struct Ctx { pub notify: Notify, } -impl Ctx { +impl Core { pub fn make() -> Self { Self { mgr: Mgr::make(), @@ -69,7 +70,7 @@ impl Ctx { } } -impl Ctx { +impl Core { #[inline] pub fn active(&self) -> &Tab { self.mgr.active() } diff --git a/yazi-core/src/lib.rs b/yazi-core/src/lib.rs index e921f8be..033592b1 100644 --- a/yazi-core/src/lib.rs +++ b/yazi-core/src/lib.rs @@ -8,6 +8,8 @@ yazi_macro::mod_pub!(cmp confirm help input mgr notify pick spot tab tasks which); +yazi_macro::mod_flat!(app); + pub fn init() { mgr::WATCHED.with(<_>::default); mgr::LINKED.with(<_>::default); diff --git a/yazi-fm/src/app/app.rs b/yazi-fm/src/app/app.rs index 48f87500..94379740 100644 --- a/yazi-fm/src/app/app.rs +++ b/yazi-fm/src/app/app.rs @@ -8,10 +8,10 @@ use yazi_macro::emit; use yazi_shared::event::{CmdCow, Event, NEED_RENDER}; use yazi_widgets::input::InputMode; -use crate::{Ctx, Executor, Router, Signals, Term}; +use crate::{Executor, Router, Signals, Term}; pub(crate) struct App { - pub(crate) cx: Ctx, + pub(crate) core: yazi_core::Core, pub(crate) term: Option, pub(crate) signals: Signals, } @@ -21,7 +21,7 @@ impl App { let term = Term::start()?; let (mut rx, signals) = (Event::take(), Signals::start()?); - let mut app = Self { cx: Ctx::make(), term: Some(term), signals }; + let mut app = Self { core: yazi_core::Core::make(), term: Some(term), signals }; app.render(); let mut events = Vec::with_capacity(50); @@ -100,8 +100,8 @@ impl App { #[inline] fn dispatch_paste(&mut self, str: String) { - if self.cx.input.visible { - let input = &mut self.cx.input; + if self.core.input.visible { + let input = &mut self.core.input; if input.mode() == InputMode::Insert { input.type_str(&str); } else if input.mode() == InputMode::Replace { diff --git a/yazi-fm/src/app/commands/accept_payload.rs b/yazi-fm/src/app/commands/accept_payload.rs index 96c1349a..e6792da6 100644 --- a/yazi-fm/src/app/commands/accept_payload.rs +++ b/yazi-fm/src/app/commands/accept_payload.rs @@ -25,7 +25,7 @@ impl App { }; drop(lock); - _ = Lives::scope(&self.cx, || { + _ = Lives::scope(&self.core, || { let body = payload.body.into_lua(&LUA)?; for (id, cb) in handlers { runtime_mut!(LUA)?.push(&id); diff --git a/yazi-fm/src/app/commands/mouse.rs b/yazi-fm/src/app/commands/mouse.rs index 79397f5b..128fc8fc 100644 --- a/yazi-fm/src/app/commands/mouse.rs +++ b/yazi-fm/src/app/commands/mouse.rs @@ -20,7 +20,7 @@ impl App { let event = yazi_plugin::bindings::MouseEvent::from(opt.event); let Some(size) = self.term.as_ref().and_then(|t| t.size().ok()) else { return }; - let res = Lives::scope(&self.cx, move || { + let res = Lives::scope(&self.core, move || { let area = yazi_binding::elements::Rect::from(size); let root = LUA.globals().raw_get::("Root")?.call_method::
("new", area)?; diff --git a/yazi-fm/src/app/commands/notify.rs b/yazi-fm/src/app/commands/notify.rs index ab66ec69..529bbc83 100644 --- a/yazi-fm/src/app/commands/notify.rs +++ b/yazi-fm/src/app/commands/notify.rs @@ -8,6 +8,6 @@ impl App { return; }; - self.cx.notify.push(opt); + self.core.notify.push(opt); } } diff --git a/yazi-fm/src/app/commands/plugin.rs b/yazi-fm/src/app/commands/plugin.rs index e03818dd..7786441c 100644 --- a/yazi-fm/src/app/commands/plugin.rs +++ b/yazi-fm/src/app/commands/plugin.rs @@ -24,7 +24,7 @@ impl App { } if opt.mode == PluginMode::Async { - return self.cx.tasks.plugin_micro(opt); + return self.core.tasks.plugin_micro(opt); } else if opt.mode == PluginMode::Sync && hits { return self.plugin_do(opt); } @@ -53,7 +53,7 @@ impl App { } if opt.mode.auto_then(chunk.sync_entry) != PluginMode::Sync { - return self.cx.tasks.plugin_micro(opt); + return self.core.tasks.plugin_micro(opt); } match runtime_mut!(LUA) { @@ -68,7 +68,7 @@ impl App { }; drop(loader); - let result = Lives::scope(&self.cx, || { + let result = Lives::scope(&self.core, || { if let Some(cb) = opt.cb { cb(&LUA, plugin) } else { diff --git a/yazi-fm/src/app/commands/quit.rs b/yazi-fm/src/app/commands/quit.rs index 27c871bd..33928ea6 100644 --- a/yazi-fm/src/app/commands/quit.rs +++ b/yazi-fm/src/app/commands/quit.rs @@ -8,8 +8,8 @@ use crate::{Term, app::App}; impl App { pub(crate) fn quit(&mut self, opt: EventQuit) -> ! { - self.cx.tasks.shutdown(); - self.cx.mgr.shutdown(); + self.core.tasks.shutdown(); + self.core.mgr.shutdown(); futures::executor::block_on(async { _ = futures::join!( @@ -25,7 +25,7 @@ impl App { async fn cwd_to_file(&self, no: bool) { if let Some(p) = ARGS.cwd_file.as_ref().filter(|_| !no) { - let cwd = self.cx.mgr.cwd().as_os_str(); + let cwd = self.core.mgr.cwd().as_os_str(); fs::write(p, cwd.as_encoded_bytes()).await.ok(); } } diff --git a/yazi-fm/src/app/commands/reflow.rs b/yazi-fm/src/app/commands/reflow.rs index 1663c061..fbbb013f 100644 --- a/yazi-fm/src/app/commands/reflow.rs +++ b/yazi-fm/src/app/commands/reflow.rs @@ -23,7 +23,7 @@ impl App { let Some(size) = self.term.as_ref().and_then(|t| t.size().ok()) else { return }; let mut layout = LAYOUT.get(); - let result = Lives::scope(&self.cx, || { + let result = Lives::scope(&self.core, || { let comps = Root::reflow((Position::ORIGIN, size).into())?; for v in comps.sequence_values::() { diff --git a/yazi-fm/src/app/commands/render.rs b/yazi-fm/src/app/commands/render.rs index 354970f2..4bd5b21b 100644 --- a/yazi-fm/src/app/commands/render.rs +++ b/yazi-fm/src/app/commands/render.rs @@ -14,25 +14,25 @@ impl App { let Some(term) = &mut self.term else { return }; Self::routine(true, None); - let _guard = scopeguard::guard(self.cx.cursor(), |c| Self::routine(false, c)); + let _guard = scopeguard::guard(self.core.cursor(), |c| Self::routine(false, c)); let collision = COLLISION.swap(false, Ordering::Relaxed); let frame = term .draw(|f| { - _ = Lives::scope(&self.cx, || Ok(f.render_widget(Root::new(&self.cx), f.area()))); + _ = Lives::scope(&self.core, || Ok(f.render_widget(Root::new(&self.core), f.area()))); }) .unwrap(); if COLLISION.load(Ordering::Relaxed) { Self::patch(frame); } - if !self.cx.notify.messages.is_empty() { + if !self.core.notify.messages.is_empty() { self.render_partially(); } // Reload preview if collision is resolved if collision && !COLLISION.load(Ordering::Relaxed) { - self.cx.mgr.peek(true); + self.core.mgr.peek(true); } } @@ -43,13 +43,13 @@ impl App { } Self::routine(true, None); - let _guard = scopeguard::guard(self.cx.cursor(), |c| Self::routine(false, c)); + let _guard = scopeguard::guard(self.core.cursor(), |c| Self::routine(false, c)); let frame = term .draw_partial(|f| { - _ = Lives::scope(&self.cx, || { - f.render_widget(crate::tasks::Progress::new(&self.cx), f.area()); - f.render_widget(crate::notify::Notify::new(&self.cx), f.area()); + _ = Lives::scope(&self.core, || { + f.render_widget(crate::tasks::Progress::new(&self.core), f.area()); + f.render_widget(crate::notify::Notify::new(&self.core), f.area()); Ok(()) }); }) diff --git a/yazi-fm/src/app/commands/resize.rs b/yazi-fm/src/app/commands/resize.rs index deb00416..8da72285 100644 --- a/yazi-fm/src/app/commands/resize.rs +++ b/yazi-fm/src/app/commands/resize.rs @@ -17,9 +17,9 @@ impl App { pub fn resize(&mut self, _: Opt) { self.reflow(()); - self.cx.current_mut().sync_page(true); - self.cx.current_mut().arrow(0); - self.cx.mgr.peek(false); - self.cx.mgr.parent_mut().map(|f| f.arrow(0)); + self.core.current_mut().sync_page(true); + self.core.current_mut().arrow(0); + self.core.mgr.peek(false); + self.core.mgr.parent_mut().map(|f| f.arrow(0)); } } diff --git a/yazi-fm/src/app/commands/resume.rs b/yazi-fm/src/app/commands/resume.rs index 93e0a694..c86ee884 100644 --- a/yazi-fm/src/app/commands/resume.rs +++ b/yazi-fm/src/app/commands/resume.rs @@ -5,7 +5,7 @@ use crate::{Term, app::App}; impl App { pub(crate) fn resume(&mut self, _: CmdCow) { - self.cx.active_mut().preview.reset_image(); + self.core.active_mut().preview.reset_image(); self.term = Some(Term::start().unwrap()); // While the app resumes, it's possible that the terminal size has changed. diff --git a/yazi-fm/src/app/commands/stop.rs b/yazi-fm/src/app/commands/stop.rs index ff07a25f..2e891f63 100644 --- a/yazi-fm/src/app/commands/stop.rs +++ b/yazi-fm/src/app/commands/stop.rs @@ -14,7 +14,7 @@ impl From for Opt { impl App { #[yazi_codegen::command] pub fn stop(&mut self, opt: Opt) { - self.cx.active_mut().preview.reset_image(); + self.core.active_mut().preview.reset_image(); // We need to destroy the `term` first before stopping the `signals` // to prevent any signal from triggering the term to render again diff --git a/yazi-fm/src/app/commands/update_notify.rs b/yazi-fm/src/app/commands/update_notify.rs index f100fb9c..e320b5ab 100644 --- a/yazi-fm/src/app/commands/update_notify.rs +++ b/yazi-fm/src/app/commands/update_notify.rs @@ -10,9 +10,9 @@ impl App { let area = notify::Notify::available(Rect { x: 0, y: 0, width: columns, height: rows }); - self.cx.notify.tick(cmd, area); + self.core.notify.tick(cmd, area); - if self.cx.notify.messages.is_empty() { + if self.core.notify.messages.is_empty() { self.render(); } else { self.render_partially(); diff --git a/yazi-fm/src/app/commands/update_progress.rs b/yazi-fm/src/app/commands/update_progress.rs index 2a7f8837..21372ecf 100644 --- a/yazi-fm/src/app/commands/update_progress.rs +++ b/yazi-fm/src/app/commands/update_progress.rs @@ -21,7 +21,7 @@ impl App { let Ok(opt) = opt.try_into() else { return }; // Update the progress of all tasks. - let tasks = &mut self.cx.tasks; + let tasks = &mut self.core.tasks; let progressed = tasks.progress != opt.progress; tasks.progress = opt.progress; diff --git a/yazi-fm/src/cmp/cmp.rs b/yazi-fm/src/cmp/cmp.rs index 310a20c5..3fb0f714 100644 --- a/yazi-fm/src/cmp/cmp.rs +++ b/yazi-fm/src/cmp/cmp.rs @@ -3,21 +3,20 @@ use std::path::MAIN_SEPARATOR_STR; use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, List, ListItem, Widget}}; use yazi_adapter::Dimension; use yazi_config::{THEME, popup::{Offset, Position}}; - -use crate::Ctx; +use yazi_core::Core; pub(crate) struct Cmp<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Cmp<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Cmp<'_> { fn render(self, rect: Rect, buf: &mut Buffer) { let items: Vec<_> = self - .cx + .core .cmp .window() .iter() @@ -27,7 +26,7 @@ impl Widget for Cmp<'_> { let slash = if x.is_dir { MAIN_SEPARATOR_STR } else { "" }; let mut item = ListItem::new(format!(" {icon} {}{slash}", x.name.display())); - if i == self.cx.cmp.rel_cursor() { + if i == self.core.cmp.rel_cursor() { item = item.style(THEME.cmp.active); } else { item = item.style(THEME.cmp.inactive); @@ -37,7 +36,7 @@ impl Widget for Cmp<'_> { }) .collect(); - let input_area = self.cx.mgr.area(self.cx.input.position); + let input_area = self.core.mgr.area(self.core.input.position); let mut area = Position::sticky(Dimension::available().into(), input_area, Offset { x: 1, y: 0, diff --git a/yazi-fm/src/confirm/body.rs b/yazi-fm/src/confirm/body.rs index 070ef31d..cdb084f0 100644 --- a/yazi-fm/src/confirm/body.rs +++ b/yazi-fm/src/confirm/body.rs @@ -1,20 +1,19 @@ use ratatui::{buffer::Buffer, layout::{Margin, Rect}, style::Styled, widgets::{Block, Borders, Widget}}; use yazi_config::THEME; - -use crate::Ctx; +use yazi_core::Core; pub(crate) struct Body<'a> { - cx: &'a Ctx, + core: &'a Core, border: bool, } impl<'a> Body<'a> { - pub(crate) fn new(cx: &'a Ctx, border: bool) -> Self { Self { cx, border } } + pub(crate) fn new(core: &'a Core, border: bool) -> Self { Self { core, border } } } impl Widget for Body<'_> { fn render(self, area: Rect, buf: &mut Buffer) { - let confirm = &self.cx.confirm; + let confirm = &self.core.confirm; // Inner area let inner = area.inner(Margin::new(1, 0)); diff --git a/yazi-fm/src/confirm/confirm.rs b/yazi-fm/src/confirm/confirm.rs index 1608510e..6e1afd05 100644 --- a/yazi-fm/src/confirm/confirm.rs +++ b/yazi-fm/src/confirm/confirm.rs @@ -1,20 +1,19 @@ use ratatui::{buffer::Buffer, layout::{Alignment, Constraint, Layout, Margin, Rect}, widgets::{Block, BorderType, Widget}}; use yazi_config::THEME; - -use crate::Ctx; +use yazi_core::Core; pub(crate) struct Confirm<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Confirm<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Confirm<'_> { fn render(self, _: Rect, buf: &mut Buffer) { - let confirm = &self.cx.confirm; - let area = self.cx.mgr.area(confirm.position); + let confirm = &self.core.confirm; + let area = self.core.mgr.area(confirm.position); yazi_binding::elements::Clear::default().render(area, buf); @@ -39,8 +38,8 @@ impl Widget for Confirm<'_> { ]) .split(area.inner(Margin::new(0, 1))); - super::Body::new(self.cx, body_border).render(chunks[0], buf); - super::List::new(self.cx).render(chunks[1], buf); + super::Body::new(self.core, body_border).render(chunks[0], buf); + super::List::new(self.core).render(chunks[1], buf); super::Buttons.render(chunks[2], buf); } } diff --git a/yazi-fm/src/confirm/list.rs b/yazi-fm/src/confirm/list.rs index 2d2459b8..e9978344 100644 --- a/yazi-fm/src/confirm/list.rs +++ b/yazi-fm/src/confirm/list.rs @@ -1,14 +1,13 @@ use ratatui::{buffer::Buffer, layout::{Margin, Rect}, widgets::{Block, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Widget, Wrap}}; use yazi_config::THEME; - -use crate::Ctx; +use yazi_core::Core; pub(crate) struct List<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> List<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for List<'_> { @@ -21,11 +20,11 @@ impl Widget for List<'_> { block.clone().render(area.inner(Margin::new(1, 0)), buf); let list = self - .cx + .core .confirm .list .clone() - .scroll((self.cx.confirm.offset as u16, 0)) + .scroll((self.core.confirm.offset as u16, 0)) .block(block) .style(THEME.confirm.list) .wrap(Wrap { trim: false }); @@ -37,7 +36,7 @@ impl Widget for List<'_> { Scrollbar::new(ScrollbarOrientation::VerticalRight).render( area, buf, - &mut ScrollbarState::new(lines).position(self.cx.confirm.offset), + &mut ScrollbarState::new(lines).position(self.core.confirm.offset), ); } diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index ca012549..b542d52d 100644 --- a/yazi-fm/src/executor.rs +++ b/yazi-fm/src/executor.rs @@ -51,39 +51,39 @@ impl<'a> Executor<'a> { macro_rules! on { (MGR, $name:ident $(,$args:expr)*) => { if cmd.name == stringify!($name) { - return self.app.cx.mgr.$name(cmd, $($args),*); + return self.app.core.mgr.$name(cmd, $($args),*); } }; (ACTIVE, $name:ident $(,$args:expr)*) => { if cmd.name == stringify!($name) { return if let Some(tab) = cmd.get("tab") { let Some(id) = tab.as_id() else { return }; - let Some(tab) = self.app.cx.mgr.tabs.find_mut(id) else { return }; + let Some(tab) = self.app.core.mgr.tabs.find_mut(id) else { return }; tab.$name(cmd, $($args),*) } else { - self.app.cx.mgr.active_mut().$name(cmd, $($args),*) + self.app.core.mgr.active_mut().$name(cmd, $($args),*) }; } }; (TABS, $name:ident) => { if cmd.name == concat!("tab_", stringify!($name)) { - return self.app.cx.mgr.tabs.$name(cmd); + return self.app.core.mgr.tabs.$name(cmd); } }; } on!(MGR, update_tasks); - on!(MGR, update_files, &self.app.cx.tasks); - on!(MGR, update_mimes, &self.app.cx.tasks); - on!(MGR, update_paged, &self.app.cx.tasks); + on!(MGR, update_files, &self.app.core.tasks); + on!(MGR, update_mimes, &self.app.core.tasks); + on!(MGR, update_paged, &self.app.core.tasks); on!(MGR, update_yanked); on!(MGR, watch); on!(MGR, peek); on!(MGR, seek); on!(MGR, spot); - on!(MGR, refresh, &self.app.cx.tasks); - on!(MGR, quit, &self.app.cx.tasks); - on!(MGR, close, &self.app.cx.tasks); + on!(MGR, refresh, &self.app.core.tasks); + on!(MGR, quit, &self.app.core.tasks); + on!(MGR, close, &self.app.core.tasks); on!(MGR, suspend); on!(ACTIVE, escape); on!(ACTIVE, update_peeked); @@ -105,15 +105,15 @@ impl<'a> Executor<'a> { on!(ACTIVE, visual_mode); // Operation - on!(MGR, open, &self.app.cx.tasks); - on!(MGR, open_do, &self.app.cx.tasks); + on!(MGR, open, &self.app.core.tasks); + on!(MGR, open_do, &self.app.core.tasks); on!(MGR, yank); on!(MGR, unyank); - on!(MGR, paste, &self.app.cx.tasks); - on!(MGR, link, &self.app.cx.tasks); - on!(MGR, hardlink, &self.app.cx.tasks); - on!(MGR, remove, &self.app.cx.tasks); - on!(MGR, remove_do, &self.app.cx.tasks); + on!(MGR, paste, &self.app.core.tasks); + on!(MGR, link, &self.app.core.tasks); + on!(MGR, hardlink, &self.app.core.tasks); + on!(MGR, remove, &self.app.core.tasks); + on!(MGR, remove_do, &self.app.core.tasks); on!(MGR, create); on!(MGR, rename); on!(ACTIVE, copy); @@ -133,7 +133,7 @@ impl<'a> Executor<'a> { on!(ACTIVE, find_arrow); // Sorting - on!(ACTIVE, sort, &self.app.cx.tasks); + on!(ACTIVE, sort, &self.app.core.tasks); // Tabs on!(TABS, create); // TODO: use `tab_create` instead @@ -143,7 +143,7 @@ impl<'a> Executor<'a> { match cmd.name.as_ref() { // Help - "help" => self.app.cx.help.toggle(Layer::Mgr), + "help" => self.app.core.help.toggle(Layer::Mgr), // Plugin "plugin" => self.app.plugin(cmd), _ => {} @@ -154,7 +154,7 @@ impl<'a> Executor<'a> { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { - return self.app.cx.tasks.$name(cmd); + return self.app.core.tasks.$name(cmd); } }; } @@ -169,7 +169,7 @@ impl<'a> Executor<'a> { match cmd.name.as_ref() { // Help - "help" => self.app.cx.help.toggle(Layer::Tasks), + "help" => self.app.core.help.toggle(Layer::Tasks), // Plugin "plugin" => self.app.plugin(cmd), _ => {} @@ -180,7 +180,7 @@ impl<'a> Executor<'a> { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { - return self.app.cx.active_mut().spot.$name(cmd); + return self.app.core.active_mut().spot.$name(cmd); } }; } @@ -192,7 +192,7 @@ impl<'a> Executor<'a> { match cmd.name.as_ref() { // Help - "help" => self.app.cx.help.toggle(Layer::Spot), + "help" => self.app.core.help.toggle(Layer::Spot), // Plugin "plugin" => self.app.plugin(cmd), _ => {} @@ -203,7 +203,7 @@ impl<'a> Executor<'a> { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { - return self.app.cx.pick.$name(cmd); + return self.app.core.pick.$name(cmd); } }; } @@ -214,7 +214,7 @@ impl<'a> Executor<'a> { match cmd.name.as_ref() { // Help - "help" => self.app.cx.help.toggle(Layer::Pick), + "help" => self.app.core.help.toggle(Layer::Pick), // Plugin "plugin" => self.app.plugin(cmd), _ => {} @@ -225,7 +225,7 @@ impl<'a> Executor<'a> { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { - return self.app.cx.input.$name(cmd); + return self.app.core.input.$name(cmd); } }; } @@ -234,11 +234,11 @@ impl<'a> Executor<'a> { on!(show); on!(close); - match self.app.cx.input.mode() { + match self.app.core.input.mode() { InputMode::Normal => { match cmd.name.as_ref() { // Help - "help" => return self.app.cx.help.toggle(Layer::Input), + "help" => return self.app.core.help.toggle(Layer::Input), // Plugin "plugin" => return self.app.plugin(cmd), _ => {} @@ -247,19 +247,19 @@ impl<'a> Executor<'a> { InputMode::Insert | InputMode::Replace => {} }; - self.app.cx.input.execute(cmd) + self.app.core.input.execute(cmd) } fn confirm(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident $(,$args:expr)*) => { if cmd.name == stringify!($name) { - return self.app.cx.confirm.$name(cmd, $($args),*); + return self.app.core.confirm.$name(cmd, $($args),*); } }; } - on!(arrow, &self.app.cx.mgr); + on!(arrow, &self.app.core.mgr); on!(show); on!(close); } @@ -268,7 +268,7 @@ impl<'a> Executor<'a> { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { - return self.app.cx.help.$name(cmd); + return self.app.core.help.$name(cmd); } }; } @@ -278,7 +278,7 @@ impl<'a> Executor<'a> { on!(filter); match cmd.name.as_ref() { - "close" => self.app.cx.help.toggle(Layer::Help), + "close" => self.app.core.help.toggle(Layer::Help), // Plugin "plugin" => self.app.plugin(cmd), _ => {} @@ -289,7 +289,7 @@ impl<'a> Executor<'a> { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { - return self.app.cx.cmp.$name(cmd); + return self.app.core.cmp.$name(cmd); } }; } @@ -301,7 +301,7 @@ impl<'a> Executor<'a> { match cmd.name.as_ref() { // Help - "help" => self.app.cx.help.toggle(Layer::Cmp), + "help" => self.app.core.help.toggle(Layer::Cmp), // Plugin "plugin" => self.app.plugin(cmd), _ => {} @@ -312,7 +312,7 @@ impl<'a> Executor<'a> { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { - return self.app.cx.which.$name(cmd); + return self.app.core.which.$name(cmd); } }; } diff --git a/yazi-fm/src/help/bindings.rs b/yazi-fm/src/help/bindings.rs index 99b61e49..1d201557 100644 --- a/yazi-fm/src/help/bindings.rs +++ b/yazi-fm/src/help/bindings.rs @@ -1,19 +1,18 @@ use ratatui::{buffer::Buffer, layout::{self, Constraint, Rect}, widgets::{List, ListItem, Widget}}; use yazi_config::THEME; - -use crate::Ctx; +use yazi_core::Core; pub(super) struct Bindings<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Bindings<'a> { - pub(super) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(super) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Bindings<'_> { fn render(self, area: Rect, buf: &mut Buffer) { - let bindings = &self.cx.help.window(); + let bindings = &self.core.help.window(); if bindings.is_empty() { return; } @@ -39,7 +38,7 @@ impl Widget for Bindings<'_> { ]) .split(area); - let cursor = self.cx.help.rel_cursor() as u16; + let cursor = self.core.help.rel_cursor() as u16; buf.set_style( Rect { x: area.x, y: area.y + cursor, width: area.width, height: 1 }, THEME.help.hovered, diff --git a/yazi-fm/src/help/help.rs b/yazi-fm/src/help/help.rs index 8c9457d3..4d86ac19 100644 --- a/yazi-fm/src/help/help.rs +++ b/yazi-fm/src/help/help.rs @@ -1,15 +1,15 @@ use ratatui::{buffer::Buffer, layout::{self, Constraint, Rect}, text::Line, widgets::Widget}; use yazi_config::{KEYMAP, THEME}; +use yazi_core::Core; use super::Bindings; -use crate::Ctx; pub(crate) struct Help<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Help<'a> { - pub fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub fn new(core: &'a Core) -> Self { Self { core } } fn tips() -> String { match KEYMAP.help.iter().find(|&c| c.run.iter().any(|c| c.name == "filter")) { @@ -21,7 +21,7 @@ impl<'a> Help<'a> { impl Widget for Help<'_> { fn render(self, area: Rect, buf: &mut Buffer) { - let help = &self.cx.help; + let help = &self.core.help; yazi_binding::elements::Clear::default().render(area, buf); let chunks = layout::Layout::vertical([Constraint::Fill(1), Constraint::Length(1)]).split(area); @@ -31,6 +31,6 @@ impl Widget for Help<'_> { ) .render(chunks[1], buf); - Bindings::new(self.cx).render(chunks[0], buf); + Bindings::new(self.core).render(chunks[0], buf); } } diff --git a/yazi-fm/src/input/input.rs b/yazi-fm/src/input/input.rs index c4553d09..727bcef1 100644 --- a/yazi-fm/src/input/input.rs +++ b/yazi-fm/src/input/input.rs @@ -1,20 +1,19 @@ use ratatui::{buffer::Buffer, layout::{Margin, Rect}, text::Line, widgets::{Block, BorderType, Widget}}; use yazi_config::THEME; - -use crate::Ctx; +use yazi_core::Core; pub(crate) struct Input<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Input<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Input<'_> { fn render(self, _: Rect, buf: &mut Buffer) { - let input = &self.cx.input; - let area = self.cx.mgr.area(input.position); + let input = &self.core.input; + let area = self.core.mgr.area(input.position); yazi_binding::elements::Clear::default().render(area, buf); diff --git a/yazi-fm/src/lives/context.rs b/yazi-fm/src/lives/core.rs similarity index 85% rename from yazi-fm/src/lives/context.rs rename to yazi-fm/src/lives/core.rs index 6e548c46..d3182362 100644 --- a/yazi-fm/src/lives/context.rs +++ b/yazi-fm/src/lives/core.rs @@ -5,8 +5,8 @@ use paste::paste; use super::{Lives, PtrCell}; -pub(super) struct Ctx { - inner: PtrCell, +pub(super) struct Core { + inner: PtrCell, c_active: Option, c_tabs: Option, @@ -15,15 +15,15 @@ pub(super) struct Ctx { c_layer: Option, } -impl Deref for Ctx { - type Target = crate::Ctx; +impl Deref for Core { + type Target = yazi_core::Core; fn deref(&self) -> &Self::Target { &self.inner } } -impl Ctx { +impl Core { #[inline] - pub(super) fn make(inner: &crate::Ctx) -> mlua::Result { + pub(super) fn make(inner: &yazi_core::Core) -> mlua::Result { Lives::scoped_userdata(Self { inner: inner.into(), @@ -36,7 +36,7 @@ impl Ctx { } } -impl UserData for Ctx { +impl UserData for Core { fn add_methods>(methods: &mut M) { methods.add_meta_method_mut(MetaMethod::Index, |lua, me, key: mlua::String| { macro_rules! reuse { diff --git a/yazi-fm/src/lives/file.rs b/yazi-fm/src/lives/file.rs index 8dbb8429..b8eef2a3 100644 --- a/yazi-fm/src/lives/file.rs +++ b/yazi-fm/src/lives/file.rs @@ -6,7 +6,7 @@ use yazi_config::THEME; use yazi_plugin::bindings::Range; use super::Lives; -use crate::{Ctx, lives::PtrCell}; +use crate::lives::PtrCell; pub(super) struct File { idx: usize, @@ -76,8 +76,8 @@ impl UserData for File { 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::("cx")?.borrow_scoped(|cx: &Ctx| { - cx.mgr.mimetype.by_url(&me.url).map(|s| lua.create_string(s)).transpose() + lua.named_registry_value::("cx")?.borrow_scoped(|core: &yazi_core::Core| { + core.mgr.mimetype.by_url(&me.url).map(|s| lua.create_string(s)).transpose() })? }); methods.add_method("prefix", |lua, me, ()| { @@ -90,16 +90,16 @@ impl UserData for File { Some(lua.create_string(p.as_path().as_os_str().as_encoded_bytes())).transpose() }); methods.add_method("style", |lua, me, ()| { - lua.named_registry_value::("cx")?.borrow_scoped(|cx: &Ctx| { - let mime = cx.mgr.mimetype.by_file(me).unwrap_or_default(); + lua.named_registry_value::("cx")?.borrow_scoped(|core: &yazi_core::Core| { + let mime = core.mgr.mimetype.by_file(me).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::("cx")?.borrow_scoped(|cx: &Ctx| { - if !cx.mgr.yanked.contains(&me.url) { + lua.named_registry_value::("cx")?.borrow_scoped(|core: &yazi_core::Core| { + if !core.mgr.yanked.contains(&me.url) { 0u8 - } else if cx.mgr.yanked.cut { + } else if core.mgr.yanked.cut { 2u8 } else { 1u8 @@ -120,8 +120,8 @@ impl UserData for File { }); methods.add_method("is_selected", |_, me, ()| Ok(me.tab.selected.contains_key(&me.url))); methods.add_method("found", |lua, me, ()| { - lua.named_registry_value::("cx")?.borrow_scoped(|cx: &Ctx| { - let Some(finder) = &cx.active().finder else { + lua.named_registry_value::("cx")?.borrow_scoped(|core: &yazi_core::Core| { + let Some(finder) = &core.active().finder else { return Ok(None); }; @@ -134,8 +134,8 @@ impl UserData for File { }) }); methods.add_method("highlights", |lua, me, ()| { - lua.named_registry_value::("cx")?.borrow_scoped(|cx: &Ctx| { - let Some(finder) = &cx.active().finder else { + lua.named_registry_value::("cx")?.borrow_scoped(|core: &yazi_core::Core| { + let Some(finder) = &core.active().finder else { return None; }; if me.folder.url != me.tab.current.url { diff --git a/yazi-fm/src/lives/lives.rs b/yazi-fm/src/lives/lives.rs index ca3459d1..5906076c 100644 --- a/yazi-fm/src/lives/lives.rs +++ b/yazi-fm/src/lives/lives.rs @@ -7,8 +7,7 @@ use tracing::error; use yazi_plugin::LUA; use yazi_shared::RoCell; -use super::PtrCell; -use crate::Ctx; +use super::{Core, PtrCell}; static TO_DESTROY: RoCell>> = RoCell::new_const(RefCell::new(Vec::new())); pub(super) static FILE_CACHE: RoCell, AnyUserData>>> = @@ -17,7 +16,10 @@ pub(super) static FILE_CACHE: RoCell, Any pub(crate) struct Lives; impl Lives { - pub(crate) fn scope(cx: &Ctx, f: impl FnOnce() -> mlua::Result) -> mlua::Result { + pub(crate) fn scope( + core: &yazi_core::Core, + f: impl FnOnce() -> mlua::Result, + ) -> mlua::Result { FILE_CACHE.init(Default::default()); defer! { FILE_CACHE.drop(); } @@ -28,8 +30,8 @@ impl Lives { } }); - LUA.set_named_registry_value("cx", scope.create_any_userdata_ref(cx)?)?; - LUA.globals().raw_set("cx", super::Ctx::make(cx)?)?; + LUA.set_named_registry_value("cx", scope.create_any_userdata_ref(core)?)?; + LUA.globals().raw_set("cx", Core::make(core)?)?; f() }); diff --git a/yazi-fm/src/lives/mod.rs b/yazi-fm/src/lives/mod.rs index 42ab437f..b14c0faf 100644 --- a/yazi-fm/src/lives/mod.rs +++ b/yazi-fm/src/lives/mod.rs @@ -1,3 +1,3 @@ #![allow(clippy::module_inception)] -yazi_macro::mod_flat!(context file files filter finder folder iter lives mode preference preview ptr selected tab tabs tasks yanked); +yazi_macro::mod_flat!(core file files filter finder folder iter lives mode preference preview ptr selected tab tabs tasks yanked); diff --git a/yazi-fm/src/main.rs b/yazi-fm/src/main.rs index 57084c63..0419a6c9 100644 --- a/yazi-fm/src/main.rs +++ b/yazi-fm/src/main.rs @@ -6,7 +6,7 @@ static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; yazi_macro::mod_pub!(app cmp confirm help input lives mgr notify pick spot tasks which); -yazi_macro::mod_flat!(context executor logs panic root router signals term); +yazi_macro::mod_flat!(executor logs panic root router signals term); #[tokio::main] async fn main() -> anyhow::Result<()> { diff --git a/yazi-fm/src/mgr/modal.rs b/yazi-fm/src/mgr/modal.rs index 225b5d73..dd578862 100644 --- a/yazi-fm/src/mgr/modal.rs +++ b/yazi-fm/src/mgr/modal.rs @@ -2,17 +2,16 @@ use mlua::{ObjectLike, Table}; use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; use tracing::error; use yazi_binding::elements::render_once; +use yazi_core::Core; use yazi_plugin::LUA; -use crate::Ctx; - pub(crate) struct Modal<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Modal<'a> { #[inline] - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Modal<'_> { @@ -21,7 +20,7 @@ impl Widget for Modal<'_> { let area = yazi_binding::elements::Rect::from(area); let root = LUA.globals().raw_get::
("Modal")?.call_method::
("new", area)?; - render_once(root.call_method("children_redraw", ())?, buf, |p| self.cx.mgr.area(p)); + render_once(root.call_method("children_redraw", ())?, buf, |p| self.core.mgr.area(p)); Ok::<_, mlua::Error>(()) }; if let Err(e) = f() { diff --git a/yazi-fm/src/mgr/preview.rs b/yazi-fm/src/mgr/preview.rs index 3ef1c419..c3ee313a 100644 --- a/yazi-fm/src/mgr/preview.rs +++ b/yazi-fm/src/mgr/preview.rs @@ -1,20 +1,19 @@ use ratatui::{buffer::Buffer, widgets::Widget}; use yazi_config::LAYOUT; - -use crate::Ctx; +use yazi_core::Core; pub(crate) struct Preview<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Preview<'a> { #[inline] - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Preview<'_> { fn render(self, win: ratatui::layout::Rect, buf: &mut Buffer) { - let Some(lock) = &self.cx.active().preview.lock else { + let Some(lock) = &self.core.active().preview.lock else { return; }; @@ -23,7 +22,7 @@ impl Widget for Preview<'_> { } for w in &lock.data { - let rect = w.area().transform(|p| self.cx.mgr.area(p)); + let rect = w.area().transform(|p| self.core.mgr.area(p)); if win.intersects(rect) { w.clone().render(rect, buf); } diff --git a/yazi-fm/src/notify/notify.rs b/yazi-fm/src/notify/notify.rs index fe0501c1..5f1fb418 100644 --- a/yazi-fm/src/notify/notify.rs +++ b/yazi-fm/src/notify/notify.rs @@ -1,14 +1,12 @@ use ratatui::{buffer::Buffer, layout::{self, Constraint, Offset, Rect}, widgets::{Block, BorderType, Paragraph, Widget, Wrap}}; -use yazi_core::notify::Message; - -use crate::Ctx; +use yazi_core::{Core, notify::Message}; pub(crate) struct Notify<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Notify<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } pub(crate) fn available(area: Rect) -> Rect { let chunks = layout::Layout::horizontal([Constraint::Fill(1), Constraint::Min(80)]).split(area); @@ -43,7 +41,7 @@ impl<'a> Notify<'a> { impl Widget for Notify<'_> { fn render(self, area: Rect, buf: &mut Buffer) { - let notify = &self.cx.notify; + let notify = &self.core.notify; let available = Self::available(area); let messages = notify.messages.iter().take(notify.limit(available)).rev(); diff --git a/yazi-fm/src/pick/list.rs b/yazi-fm/src/pick/list.rs index 486c77ad..b5c3367a 100644 --- a/yazi-fm/src/pick/list.rs +++ b/yazi-fm/src/pick/list.rs @@ -1,20 +1,19 @@ use ratatui::{buffer::Buffer, layout::{Margin, Rect}, widgets::{ListItem, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Widget}}; use yazi_config::THEME; +use yazi_core::Core; use yazi_widgets::Scrollable; -use crate::Ctx; - pub(crate) struct List<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> List<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for List<'_> { fn render(self, area: Rect, buf: &mut Buffer) { - let pick = &self.cx.pick; + let pick = &self.core.pick; // Vertical scrollbar if pick.total() > pick.limit() { diff --git a/yazi-fm/src/pick/pick.rs b/yazi-fm/src/pick/pick.rs index 15b49cdb..a9dbc690 100644 --- a/yazi-fm/src/pick/pick.rs +++ b/yazi-fm/src/pick/pick.rs @@ -1,20 +1,21 @@ use ratatui::{buffer::Buffer, layout::{Margin, Rect}, widgets::{Block, BorderType, Widget}}; use yazi_config::THEME; +use yazi_core::Core; -use crate::{Ctx, pick::List}; +use crate::pick::List; pub(crate) struct Pick<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Pick<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Pick<'_> { fn render(self, _: Rect, buf: &mut Buffer) { - let pick = &self.cx.pick; - let area = self.cx.mgr.area(pick.position); + let pick = &self.core.pick; + let area = self.core.mgr.area(pick.position); yazi_binding::elements::Clear::default().render(area, buf); @@ -24,6 +25,6 @@ impl Widget for Pick<'_> { .border_style(THEME.pick.border) .render(area, buf); - List::new(self.cx).render(area.inner(Margin::new(0, 1)), buf); + List::new(self.core).render(area.inner(Margin::new(0, 1)), buf); } } diff --git a/yazi-fm/src/root.rs b/yazi-fm/src/root.rs index b9f97452..47073260 100644 --- a/yazi-fm/src/root.rs +++ b/yazi-fm/src/root.rs @@ -2,17 +2,17 @@ use mlua::{ObjectLike, Table}; use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; use tracing::error; use yazi_binding::elements::render_once; +use yazi_core::Core; use yazi_plugin::LUA; use super::{cmp, confirm, help, input, mgr, pick, spot, tasks, which}; -use crate::Ctx; pub(super) struct Root<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Root<'a> { - pub(super) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(super) fn new(core: &'a Core) -> Self { Self { core } } pub(super) fn reflow(area: Rect) -> mlua::Result
{ let area = yazi_binding::elements::Rect::from(area); @@ -27,46 +27,46 @@ impl Widget for Root<'_> { let area = yazi_binding::elements::Rect::from(area); let root = LUA.globals().raw_get::
("Root")?.call_method::
("new", area)?; - render_once(root.call_method("redraw", ())?, buf, |p| self.cx.mgr.area(p)); + render_once(root.call_method("redraw", ())?, buf, |p| self.core.mgr.area(p)); Ok::<_, mlua::Error>(()) }; if let Err(e) = f() { error!("Failed to redraw the `Root` component:\n{e}"); } - mgr::Preview::new(self.cx).render(area, buf); - mgr::Modal::new(self.cx).render(area, buf); + mgr::Preview::new(self.core).render(area, buf); + mgr::Modal::new(self.core).render(area, buf); - if self.cx.tasks.visible { - tasks::Tasks::new(self.cx).render(area, buf); + if self.core.tasks.visible { + tasks::Tasks::new(self.core).render(area, buf); } - if self.cx.active().spot.visible() { - spot::Spot::new(self.cx).render(area, buf); + if self.core.active().spot.visible() { + spot::Spot::new(self.core).render(area, buf); } - if self.cx.pick.visible { - pick::Pick::new(self.cx).render(area, buf); + if self.core.pick.visible { + pick::Pick::new(self.core).render(area, buf); } - if self.cx.input.visible { - input::Input::new(self.cx).render(area, buf); + if self.core.input.visible { + input::Input::new(self.core).render(area, buf); } - if self.cx.confirm.visible { - confirm::Confirm::new(self.cx).render(area, buf); + if self.core.confirm.visible { + confirm::Confirm::new(self.core).render(area, buf); } - if self.cx.help.visible { - help::Help::new(self.cx).render(area, buf); + if self.core.help.visible { + help::Help::new(self.core).render(area, buf); } - if self.cx.cmp.visible { - cmp::Cmp::new(self.cx).render(area, buf); + if self.core.cmp.visible { + cmp::Cmp::new(self.core).render(area, buf); } - if self.cx.which.visible { - which::Which::new(self.cx).render(area, buf); + if self.core.which.visible { + which::Which::new(self.core).render(area, buf); } } } diff --git a/yazi-fm/src/router.rs b/yazi-fm/src/router.rs index 4870d013..2480c675 100644 --- a/yazi-fm/src/router.rs +++ b/yazi-fm/src/router.rs @@ -14,13 +14,13 @@ impl<'a> Router<'a> { #[inline] pub(super) fn route(&mut self, key: Key) -> bool { - let cx = &mut self.app.cx; - let layer = cx.layer(); + let core = &mut self.app.core; + let layer = core.layer(); - if cx.help.visible && cx.help.r#type(&key) { + if core.help.visible && core.help.r#type(&key) { return true; } - if cx.input.visible && cx.input.r#type(&key) { + if core.input.visible && core.input.r#type(&key) { return true; } @@ -31,7 +31,7 @@ impl<'a> Router<'a> { self.matches(layer, key) } L::Cmp => self.matches(L::Cmp, key) || self.matches(L::Input, key), - L::Which => cx.which.r#type(key), + L::Which => core.which.r#type(key), } } @@ -43,7 +43,7 @@ impl<'a> Router<'a> { } if on.len() > 1 { - self.app.cx.which.show_with(key, layer); + self.app.core.which.show_with(key, layer); } else { emit!(Seq(ChordCow::from(chord).into_seq())); } diff --git a/yazi-fm/src/spot/spot.rs b/yazi-fm/src/spot/spot.rs index 682c8c0d..2b4b2436 100644 --- a/yazi-fm/src/spot/spot.rs +++ b/yazi-fm/src/spot/spot.rs @@ -1,23 +1,22 @@ use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; - -use crate::Ctx; +use yazi_core::Core; pub(crate) struct Spot<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Spot<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Spot<'_> { fn render(self, win: Rect, buf: &mut Buffer) { - let Some(lock) = &self.cx.active().spot.lock else { + let Some(lock) = &self.core.active().spot.lock else { return; }; for w in &lock.data { - let rect = w.area().transform(|p| self.cx.mgr.area(p)); + let rect = w.area().transform(|p| self.core.mgr.area(p)); if win.intersects(rect) { w.clone().render(rect, buf); } diff --git a/yazi-fm/src/tasks/progress.rs b/yazi-fm/src/tasks/progress.rs index e07a5004..1040c704 100644 --- a/yazi-fm/src/tasks/progress.rs +++ b/yazi-fm/src/tasks/progress.rs @@ -3,16 +3,15 @@ use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; use tracing::error; use yazi_binding::elements::render_once; use yazi_config::LAYOUT; +use yazi_core::Core; use yazi_plugin::LUA; -use crate::Ctx; - pub(crate) struct Progress<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Progress<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Progress<'_> { @@ -22,7 +21,7 @@ impl Widget for Progress<'_> { let progress = LUA.globals().raw_get::
("Progress")?.call_method::
("use", area)?; - render_once(progress.call_method("redraw", ())?, buf, |p| self.cx.mgr.area(p)); + render_once(progress.call_method("redraw", ())?, buf, |p| self.core.mgr.area(p)); Ok::<_, mlua::Error>(()) }; if let Err(e) = f() { diff --git a/yazi-fm/src/tasks/tasks.rs b/yazi-fm/src/tasks/tasks.rs index 2116125d..b4ddd55b 100644 --- a/yazi-fm/src/tasks/tasks.rs +++ b/yazi-fm/src/tasks/tasks.rs @@ -1,15 +1,13 @@ use ratatui::{buffer::Buffer, layout::{self, Alignment, Constraint, Rect}, text::{Line, Text}, widgets::{Block, BorderType, List, Padding, Widget}}; use yazi_config::THEME; -use yazi_core::tasks::TASKS_PERCENT; - -use crate::Ctx; +use yazi_core::{Core, tasks::TASKS_PERCENT}; pub(crate) struct Tasks<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Tasks<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } pub(super) fn area(area: Rect) -> Rect { let chunk = layout::Layout::vertical([ @@ -43,7 +41,7 @@ impl Widget for Tasks<'_> { let inner = block.inner(area); block.render(area, buf); - let tasks = &self.cx.tasks; + let tasks = &self.core.tasks; let items = tasks.summaries.iter().take(inner.height as usize).enumerate().map(|(i, v)| { let mut item = Text::from_iter(textwrap::wrap(&v.name, inner.width as usize).into_iter().map(Line::from)); diff --git a/yazi-fm/src/which/which.rs b/yazi-fm/src/which/which.rs index d2381f03..f68938e4 100644 --- a/yazi-fm/src/which/which.rs +++ b/yazi-fm/src/which/which.rs @@ -1,23 +1,23 @@ use ratatui::{buffer::Buffer, layout, layout::{Constraint, Rect}, widgets::{Block, Widget}}; use yazi_config::THEME; +use yazi_core::Core; use super::Cand; -use crate::Ctx; const PADDING_X: u16 = 1; const PADDING_Y: u16 = 1; pub(crate) struct Which<'a> { - cx: &'a Ctx, + core: &'a Core, } impl<'a> Which<'a> { - pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } } + pub(crate) fn new(core: &'a Core) -> Self { Self { core } } } impl Widget for Which<'_> { fn render(self, area: Rect, buf: &mut Buffer) { - let which = &self.cx.which; + let which = &self.core.which; if which.silent { return; }