mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
7bb5fbb4bb
commit
b1fbbd4934
7 changed files with 55 additions and 35 deletions
|
|
@ -23,7 +23,7 @@ impl App {
|
|||
|
||||
Lives::register()?;
|
||||
let mut app = Self { cx: Ctx::make(), term: Some(term), signals };
|
||||
app.render()?;
|
||||
app.render();
|
||||
|
||||
let mut times = 0;
|
||||
let mut events = Vec::with_capacity(200);
|
||||
|
|
@ -39,13 +39,13 @@ impl App {
|
|||
|
||||
if times >= 50 {
|
||||
times = 0;
|
||||
app.render()?;
|
||||
app.render();
|
||||
} else if let Ok(event) = app.signals.rx.try_recv() {
|
||||
events.push(event);
|
||||
emit!(Render);
|
||||
} else {
|
||||
times = 0;
|
||||
app.render()?;
|
||||
app.render();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -58,7 +58,7 @@ impl App {
|
|||
Event::Seq(execs, layer) => self.dispatch_seq(execs, layer),
|
||||
Event::Render => self.dispatch_render(),
|
||||
Event::Key(key) => self.dispatch_key(key),
|
||||
Event::Resize => self.resize()?,
|
||||
Event::Resize => self.resize(()),
|
||||
Event::Paste(str) => self.dispatch_paste(str),
|
||||
Event::Quit(opt) => self.quit(opt),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,31 @@
|
|||
use std::sync::atomic::Ordering;
|
||||
|
||||
use anyhow::Result;
|
||||
use ratatui::backend::Backend;
|
||||
|
||||
use crate::{app::App, lives::Lives, root::{Root, COLLISION}};
|
||||
|
||||
impl App {
|
||||
pub(crate) fn render(&mut self) -> Result<()> {
|
||||
pub(crate) fn render(&mut self) {
|
||||
let Some(term) = &mut self.term else {
|
||||
return Ok(());
|
||||
return;
|
||||
};
|
||||
|
||||
let collision = COLLISION.swap(false, Ordering::Relaxed);
|
||||
let frame = term.draw(|f| {
|
||||
_ = Lives::scope(&self.cx, |_| {
|
||||
f.render_widget(Root::new(&self.cx), f.size());
|
||||
Ok(())
|
||||
});
|
||||
let frame = term
|
||||
.draw(|f| {
|
||||
_ = Lives::scope(&self.cx, |_| Ok(f.render_widget(Root::new(&self.cx), f.size())));
|
||||
if let Some((x, y)) = self.cx.cursor() {
|
||||
f.set_cursor(x, y);
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
if let Some((x, y)) = self.cx.cursor() {
|
||||
f.set_cursor(x, y);
|
||||
}
|
||||
})?;
|
||||
if !COLLISION.load(Ordering::Relaxed) {
|
||||
if collision {
|
||||
// Reload preview if collision is resolved
|
||||
self.cx.manager.peek(true);
|
||||
}
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
let mut patch = vec![];
|
||||
|
|
@ -40,12 +38,11 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
term.backend_mut().draw(patch.iter().map(|(x, y, cell)| (*x, *y, cell)))?;
|
||||
term.backend_mut().draw(patch.iter().map(|(x, y, cell)| (*x, *y, cell))).ok();
|
||||
if let Some((x, y)) = self.cx.cursor() {
|
||||
term.show_cursor()?;
|
||||
term.set_cursor(x, y)?;
|
||||
term.show_cursor().ok();
|
||||
term.set_cursor(x, y).ok();
|
||||
}
|
||||
term.backend_mut().flush()?;
|
||||
Ok(())
|
||||
term.backend_mut().flush().ok();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,23 @@
|
|||
use anyhow::Result;
|
||||
use yazi_shared::event::Exec;
|
||||
|
||||
use crate::app::App;
|
||||
|
||||
pub struct Opt;
|
||||
|
||||
impl From<Exec> for Opt {
|
||||
fn from(_: Exec) -> Self { Self }
|
||||
}
|
||||
|
||||
impl From<()> for Opt {
|
||||
fn from(_: ()) -> Self { Self }
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub(crate) fn resize(&mut self) -> Result<()> {
|
||||
pub(crate) fn resize(&mut self, _: impl Into<Opt>) {
|
||||
self.cx.manager.active_mut().preview.reset();
|
||||
self.render()?;
|
||||
self.render();
|
||||
|
||||
self.cx.manager.current_mut().sync_page(true);
|
||||
self.cx.manager.hover(None);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ impl App {
|
|||
|
||||
// While the app resumes, it's possible that the terminal size has changed.
|
||||
// We need to trigger a resize, and render the UI based on the resized area.
|
||||
self.resize().unwrap();
|
||||
self.resize(());
|
||||
|
||||
self.signals.resume();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ impl<'a> Executor<'a> {
|
|||
on!(plugin);
|
||||
on!(plugin_do);
|
||||
on!(update_progress);
|
||||
on!(resize);
|
||||
on!(stop);
|
||||
on!(resume);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#![allow(clippy::module_inception)]
|
||||
#![allow(clippy::unit_arg)]
|
||||
|
||||
mod app;
|
||||
mod completion;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,17 @@ impl Utils {
|
|||
Ok((args, named))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn create_exec(cmd: String, table: Table, data: Option<Value>) -> mlua::Result<Exec> {
|
||||
let (args, named) = Self::parse_args(table)?;
|
||||
let mut exec = Exec { cmd, args, named, ..Default::default() };
|
||||
|
||||
if let Some(data) = data.and_then(|v| ValueSendable::try_from(v).ok()) {
|
||||
exec = exec.with_data(data);
|
||||
}
|
||||
Ok(exec)
|
||||
}
|
||||
|
||||
pub(super) fn call(lua: &Lua, ya: &Table) -> mlua::Result<()> {
|
||||
ya.set(
|
||||
"render",
|
||||
|
|
@ -37,17 +48,18 @@ impl Utils {
|
|||
})?,
|
||||
)?;
|
||||
|
||||
ya.set(
|
||||
"app_emit",
|
||||
lua.create_function(|_, (cmd, table, data): (String, Table, Option<Value>)| {
|
||||
emit!(Call(Self::create_exec(cmd, table, data)?, Layer::App));
|
||||
Ok(())
|
||||
})?,
|
||||
)?;
|
||||
|
||||
ya.set(
|
||||
"manager_emit",
|
||||
lua.create_function(|_, (cmd, table, data): (String, Table, Option<Value>)| {
|
||||
let (args, named) = Self::parse_args(table)?;
|
||||
let mut exec = Exec { cmd, args, named, ..Default::default() };
|
||||
|
||||
if let Some(data) = data.and_then(|v| ValueSendable::try_from(v).ok()) {
|
||||
exec = exec.with_data(data);
|
||||
}
|
||||
|
||||
emit!(Call(exec, Layer::Manager));
|
||||
emit!(Call(Self::create_exec(cmd, table, data)?, Layer::Manager));
|
||||
Ok(())
|
||||
})?,
|
||||
)?;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue