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;
};
if hovered != &opt.lock.url {
if opt.lock.url != *hovered {
return;
}

View file

@ -2,7 +2,6 @@ use std::{mem, sync::atomic::Ordering};
use anyhow::{Ok, Result};
use crossterm::event::KeyEvent;
use tracing::debug;
use yazi_config::keymap::Key;
use yazi_core::input::InputMode;
use yazi_shared::{emit, event::{Event, Exec, NEED_RENDER}, term::Term, Layer};
@ -30,19 +29,17 @@ impl App {
let mut render_in_place = false;
while app.signals.rx.recv_many(&mut events, 10).await > 0 {
for event in events.drain(..) {
debug!("event - do: {:?}", event);
match event {
Event::Call(exec, layer) => app.dispatch_call(exec, layer),
Event::Render => render_in_place = true,
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::Quit(no_cwd_file) => {
app.quit(no_cwd_file)?;
return Ok(());
}
}
debug!("event - done");
}
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]
fn dispatch_call(&mut self, exec: Vec<Exec>, layer: Layer) {
Executor::new(self).dispatch(&exec, layer);

View file

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

View file

@ -1,8 +1,7 @@
use std::{backtrace::Backtrace, sync::atomic::Ordering};
use std::sync::atomic::Ordering;
use anyhow::Result;
use ratatui::backend::Backend;
use tracing::debug;
use crate::{app::App, lives::Lives, root::{Root, COLLISION}};
@ -15,9 +14,7 @@ impl App {
let collision = COLLISION.swap(false, Ordering::Relaxed);
let frame = term.draw(|f| {
Lives::scope(&self.cx, |_| {
debug!("rendering: {:?}", Backtrace::force_capture());
f.render_widget(Root::new(&self.cx), f.size());
debug!("rendered");
});
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 {
self.term = Some(Term::start().unwrap());
self.signals.stop_term(false);
// FIXME: find a better way to handle this
self.render().unwrap();
self.cx.manager.hover(None);
self.cx.manager.peek(true);
// 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();
}
if let Some(tx) = opt.tx {
tx.send(()).ok();

View file

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

View file

@ -22,7 +22,8 @@ impl Loader {
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 {
"noop.lua" => include_bytes!("../preset/plugins/noop.lua") as &[u8],
"archive.lua" => include_bytes!("../preset/plugins/archive.lua"),

View file

@ -33,7 +33,7 @@ pub fn init() {
fn stage_2(lua: &Lua) {
let setup = br#"
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();

View file

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