This commit is contained in:
sxyazi 2024-01-07 15:30:05 +08:00
parent 5f80021321
commit e1e5b2a4d9
No known key found for this signature in database
10 changed files with 27 additions and 26 deletions

View file

@ -23,7 +23,7 @@ impl Tab {
return; return;
}; };
if hovered != &opt.lock.url { if opt.lock.url != *hovered {
return; return;
} }

View file

@ -2,7 +2,6 @@ use std::{mem, sync::atomic::Ordering};
use anyhow::{Ok, Result}; use anyhow::{Ok, Result};
use crossterm::event::KeyEvent; use crossterm::event::KeyEvent;
use tracing::debug;
use yazi_config::keymap::Key; use yazi_config::keymap::Key;
use yazi_core::input::InputMode; use yazi_core::input::InputMode;
use yazi_shared::{emit, event::{Event, Exec, NEED_RENDER}, term::Term, Layer}; use yazi_shared::{emit, event::{Event, Exec, NEED_RENDER}, term::Term, Layer};
@ -30,19 +29,17 @@ impl App {
let mut render_in_place = false; let mut render_in_place = false;
while app.signals.rx.recv_many(&mut events, 10).await > 0 { while app.signals.rx.recv_many(&mut events, 10).await > 0 {
for event in events.drain(..) { for event in events.drain(..) {
debug!("event - do: {:?}", event);
match event { match event {
Event::Call(exec, layer) => app.dispatch_call(exec, layer), Event::Call(exec, layer) => app.dispatch_call(exec, layer),
Event::Render => render_in_place = true, Event::Render => render_in_place = true,
Event::Key(key) => app.dispatch_key(key), Event::Key(key) => app.dispatch_key(key),
Event::Resize(cols, rows) => app.dispatch_resize(cols, rows)?, Event::Resize => app.resize()?,
Event::Paste(str) => app.dispatch_paste(str), Event::Paste(str) => app.dispatch_paste(str),
Event::Quit(no_cwd_file) => { Event::Quit(no_cwd_file) => {
app.quit(no_cwd_file)?; app.quit(no_cwd_file)?;
return Ok(()); return Ok(());
} }
} }
debug!("event - done");
} }
if mem::replace(&mut render_in_place, false) { if mem::replace(&mut render_in_place, false) {
@ -68,15 +65,6 @@ impl App {
} }
} }
fn dispatch_resize(&mut self, _: u16, _: u16) -> Result<()> {
self.cx.manager.active_mut().preview.reset();
self.render()?;
self.cx.manager.current_mut().sync_page(true);
self.cx.manager.peek(false);
Ok(())
}
#[inline] #[inline]
fn dispatch_call(&mut self, exec: Vec<Exec>, layer: Layer) { fn dispatch_call(&mut self, exec: Vec<Exec>, layer: Layer) {
Executor::new(self).dispatch(&exec, layer); Executor::new(self).dispatch(&exec, layer);

View file

@ -1,4 +1,5 @@
mod plugin; mod plugin;
mod quit; mod quit;
mod render; mod render;
mod resize;
mod stop; mod stop;

View file

@ -1,8 +1,7 @@
use std::{backtrace::Backtrace, sync::atomic::Ordering}; use std::sync::atomic::Ordering;
use anyhow::Result; use anyhow::Result;
use ratatui::backend::Backend; use ratatui::backend::Backend;
use tracing::debug;
use crate::{app::App, lives::Lives, root::{Root, COLLISION}}; use crate::{app::App, lives::Lives, root::{Root, COLLISION}};
@ -15,9 +14,7 @@ impl App {
let collision = COLLISION.swap(false, Ordering::Relaxed); let collision = COLLISION.swap(false, Ordering::Relaxed);
let frame = term.draw(|f| { let frame = term.draw(|f| {
Lives::scope(&self.cx, |_| { Lives::scope(&self.cx, |_| {
debug!("rendering: {:?}", Backtrace::force_capture());
f.render_widget(Root::new(&self.cx), f.size()); f.render_widget(Root::new(&self.cx), f.size());
debug!("rendered");
}); });
if let Some((x, y)) = self.cx.cursor() { if let Some((x, y)) = self.cx.cursor() {

View file

@ -0,0 +1,14 @@
use anyhow::Result;
use crate::app::App;
impl App {
pub(crate) fn resize(&mut self) -> Result<()> {
self.cx.manager.active_mut().preview.reset();
self.render()?;
self.cx.manager.current_mut().sync_page(true);
self.cx.manager.hover(None);
Ok(())
}
}

View file

@ -27,10 +27,10 @@ impl App {
} else { } else {
self.term = Some(Term::start().unwrap()); self.term = Some(Term::start().unwrap());
self.signals.stop_term(false); self.signals.stop_term(false);
// FIXME: find a better way to handle this
self.render().unwrap(); // While the app resumes, it's possible that the terminal size has changed.
self.cx.manager.hover(None); // We need to trigger a resize, and render the UI based on the resized area.
self.cx.manager.peek(true); self.resize().unwrap();
} }
if let Some(tx) = opt.tx { if let Some(tx) = opt.tx {
tx.send(()).ok(); tx.send(()).ok();

View file

@ -88,7 +88,7 @@ impl Signals {
// otherwise event will be dispatched twice. // otherwise event will be dispatched twice.
CrosstermEvent::Key(key @ KeyEvent { kind: KeyEventKind::Press, .. }) => Event::Key(key), CrosstermEvent::Key(key @ KeyEvent { kind: KeyEventKind::Press, .. }) => Event::Key(key),
CrosstermEvent::Paste(str) => Event::Paste(str), CrosstermEvent::Paste(str) => Event::Paste(str),
CrosstermEvent::Resize(cols, rows) => Event::Resize(cols, rows), CrosstermEvent::Resize(..) => Event::Resize,
_ => continue, _ => continue,
}; };
if tx.send(event).is_err() { if tx.send(event).is_err() {

View file

@ -22,7 +22,8 @@ impl Loader {
return Ok(()); return Ok(());
} }
let b = fs::read(BOOT.plugin_dir.join(name)).await.map(|v| v.into()).or_else(|_| { let path = BOOT.plugin_dir.join(format!("{name}.yazi/init.lua"));
let b = fs::read(path).await.map(|v| v.into()).or_else(|_| {
Ok(Cow::from(match name { Ok(Cow::from(match name {
"noop.lua" => include_bytes!("../preset/plugins/noop.lua") as &[u8], "noop.lua" => include_bytes!("../preset/plugins/noop.lua") as &[u8],
"archive.lua" => include_bytes!("../preset/plugins/archive.lua"), "archive.lua" => include_bytes!("../preset/plugins/archive.lua"),

View file

@ -33,7 +33,7 @@ pub fn init() {
fn stage_2(lua: &Lua) { fn stage_2(lua: &Lua) {
let setup = br#" let setup = br#"
ya.SYNC_ON = true ya.SYNC_ON = true
package.path = BOOT.plugin_dir .. "/?.yazi/init.lua;" .. BOOT.plugin_dir .. "/?.lua;" .. package.path package.path = BOOT.plugin_dir .. "/?.yazi/init.lua;" .. package.path
"#; "#;
lua.load(setup as &[u8]).exec().unwrap(); lua.load(setup as &[u8]).exec().unwrap();

View file

@ -11,7 +11,7 @@ pub enum Event {
Call(Vec<Exec>, Layer), Call(Vec<Exec>, Layer),
Render, Render,
Key(KeyEvent), Key(KeyEvent),
Resize(u16, u16), Resize,
Paste(String), Paste(String),
Quit(bool), // no-cwd-file Quit(bool), // no-cwd-file
} }