mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
refactor: use term "core" instead of "context" (#2978)
This commit is contained in:
parent
c9c85130e1
commit
6366e46c23
39 changed files with 210 additions and 219 deletions
|
|
@ -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() }
|
||||
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<Term>,
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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::<Table>("Root")?.call_method::<Table>("new", area)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ impl App {
|
|||
return;
|
||||
};
|
||||
|
||||
self.cx.notify.push(opt);
|
||||
self.core.notify.push(opt);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::<Value>() {
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
});
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ impl From<CmdCow> 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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ use paste::paste;
|
|||
|
||||
use super::{Lives, PtrCell};
|
||||
|
||||
pub(super) struct Ctx {
|
||||
inner: PtrCell<crate::Ctx>,
|
||||
pub(super) struct Core {
|
||||
inner: PtrCell<yazi_core::Core>,
|
||||
|
||||
c_active: Option<Value>,
|
||||
c_tabs: Option<Value>,
|
||||
|
|
@ -15,15 +15,15 @@ pub(super) struct Ctx {
|
|||
c_layer: Option<Value>,
|
||||
}
|
||||
|
||||
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<AnyUserData> {
|
||||
pub(super) fn make(inner: &yazi_core::Core) -> mlua::Result<AnyUserData> {
|
||||
Lives::scoped_userdata(Self {
|
||||
inner: inner.into(),
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ impl Ctx {
|
|||
}
|
||||
}
|
||||
|
||||
impl UserData for Ctx {
|
||||
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 {
|
||||
|
|
@ -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::<AnyUserData>("cx")?.borrow_scoped(|cx: &Ctx| {
|
||||
cx.mgr.mimetype.by_url(&me.url).map(|s| lua.create_string(s)).transpose()
|
||||
lua.named_registry_value::<AnyUserData>("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::<AnyUserData>("cx")?.borrow_scoped(|cx: &Ctx| {
|
||||
let mime = cx.mgr.mimetype.by_file(me).unwrap_or_default();
|
||||
lua.named_registry_value::<AnyUserData>("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::<AnyUserData>("cx")?.borrow_scoped(|cx: &Ctx| {
|
||||
if !cx.mgr.yanked.contains(&me.url) {
|
||||
lua.named_registry_value::<AnyUserData>("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::<AnyUserData>("cx")?.borrow_scoped(|cx: &Ctx| {
|
||||
let Some(finder) = &cx.active().finder else {
|
||||
lua.named_registry_value::<AnyUserData>("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::<AnyUserData>("cx")?.borrow_scoped(|cx: &Ctx| {
|
||||
let Some(finder) = &cx.active().finder else {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -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<RefCell<Vec<AnyUserData>>> = RoCell::new_const(RefCell::new(Vec::new()));
|
||||
pub(super) static FILE_CACHE: RoCell<RefCell<HashMap<PtrCell<yazi_fs::File>, AnyUserData>>> =
|
||||
|
|
@ -17,7 +16,10 @@ pub(super) static FILE_CACHE: RoCell<RefCell<HashMap<PtrCell<yazi_fs::File>, Any
|
|||
pub(crate) struct Lives;
|
||||
|
||||
impl Lives {
|
||||
pub(crate) fn scope<T>(cx: &Ctx, f: impl FnOnce() -> mlua::Result<T>) -> mlua::Result<T> {
|
||||
pub(crate) 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(); }
|
||||
|
||||
|
|
@ -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()
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<()> {
|
||||
|
|
|
|||
|
|
@ -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::<Table>("Modal")?.call_method::<Table>("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() {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Table> {
|
||||
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::<Table>("Root")?.call_method::<Table>("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::<Table>("Progress")?.call_method::<Table>("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() {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue