This commit is contained in:
sxyazi 2024-01-07 22:19:44 +08:00
parent 980942260d
commit df2a5ee95c
No known key found for this signature in database
7 changed files with 21 additions and 74 deletions

View file

@ -3,13 +3,7 @@ use std::ffi::OsString;
use tracing::error; use tracing::error;
use yazi_config::{popup::SelectCfg, ARGS, OPEN}; use yazi_config::{popup::SelectCfg, ARGS, OPEN};
use yazi_plugin::isolate; use yazi_plugin::isolate;
use yazi_shared::event::QuitAction; use yazi_shared::{emit, event::{Exec, QuitAction}, fs::{File, Url}, Layer, MIME_DIR};
use yazi_shared::{
emit,
event::Exec,
fs::{File, Url},
Layer, MIME_DIR,
};
use crate::{manager::Manager, select::Select, tasks::Tasks}; use crate::{manager::Manager, select::Select, tasks::Tasks};

View file

@ -1,8 +1,5 @@
use yazi_config::popup::InputCfg; use yazi_config::popup::InputCfg;
use yazi_shared::{ use yazi_shared::{emit, event::{Exec, QuitAction}};
emit,
event::{Exec, QuitAction},
};
use crate::{input::Input, manager::Manager, tasks::Tasks}; use crate::{input::Input, manager::Manager, tasks::Tasks};
@ -11,14 +8,10 @@ pub struct Opt {
no_cwd_file: bool, no_cwd_file: bool,
} }
impl From<()> for Opt { impl From<()> for Opt {
fn from(_: ()) -> Self { fn from(_: ()) -> Self { Self::default() }
Self::default()
}
} }
impl From<&Exec> for Opt { impl From<&Exec> for Opt {
fn from(e: &Exec) -> Self { fn from(e: &Exec) -> Self { Self { no_cwd_file: e.named.contains_key("no-cwd-file") } }
Self { no_cwd_file: e.named.contains_key("no-cwd-file") }
}
} }
impl Manager { impl Manager {

View file

@ -4,12 +4,7 @@ use anyhow::{Ok, Result};
use crossterm::event::KeyEvent; use crossterm::event::KeyEvent;
use yazi_config::keymap::Key; use yazi_config::keymap::Key;
use yazi_core::input::InputMode; use yazi_core::input::InputMode;
use yazi_shared::{ use yazi_shared::{emit, event::{Event, Exec, NEED_RENDER}, term::Term, Layer};
emit,
event::{Event, Exec, NEED_RENDER},
term::Term,
Layer,
};
use crate::{lives::Lives, Ctx, Executor, Logs, Panic, Signals}; use crate::{lives::Lives, Ctx, Executor, Logs, Panic, Signals};
@ -59,9 +54,7 @@ impl App {
} }
#[inline] #[inline]
fn dispatch_key(&mut self, key: KeyEvent) { fn dispatch_key(&mut self, key: KeyEvent) { Executor::new(self).handle(Key::from(key)); }
Executor::new(self).handle(Key::from(key));
}
fn dispatch_paste(&mut self, str: String) { fn dispatch_paste(&mut self, str: String) {
if self.cx.input.visible { if self.cx.input.visible {

View file

@ -1,14 +1,7 @@
use anyhow::Result; use anyhow::Result;
use crossterm::event::{Event as CrosstermEvent, EventStream, KeyEvent, KeyEventKind}; use crossterm::event::{Event as CrosstermEvent, EventStream, KeyEvent, KeyEventKind};
use futures::StreamExt; use futures::StreamExt;
use tokio::{ use tokio::{select, sync::{mpsc::{self, UnboundedReceiver, UnboundedSender}, oneshot}, task::JoinHandle};
select,
sync::{
mpsc::{self, UnboundedReceiver, UnboundedSender},
oneshot,
},
task::JoinHandle,
};
use yazi_shared::event::Event; use yazi_shared::event::Event;
pub(super) struct Signals { pub(super) struct Signals {
@ -49,9 +42,7 @@ impl Signals {
} }
#[cfg(windows)] #[cfg(windows)]
fn spawn_system_task(&self) -> Result<()> { fn spawn_system_task(&self) -> Result<()> { Ok(()) }
Ok(())
}
#[cfg(unix)] #[cfg(unix)]
fn spawn_system_task(&self) -> Result<JoinHandle<()>> { fn spawn_system_task(&self) -> Result<JoinHandle<()>> {

View file

@ -28,14 +28,10 @@ pub enum QuitAction {
impl Event { impl Event {
#[inline] #[inline]
pub fn init(tx: UnboundedSender<Event>) { pub fn init(tx: UnboundedSender<Event>) { TX.init(tx); }
TX.init(tx);
}
#[inline] #[inline]
pub fn emit(self) { pub fn emit(self) { TX.send(self).ok(); }
TX.send(self).ok();
}
pub async fn wait<T>(self, rx: oneshot::Receiver<T>) -> T { pub async fn wait<T>(self, rx: oneshot::Receiver<T>) -> T {
TX.send(self).ok(); TX.send(self).ok();

View file

@ -1,21 +1,7 @@
use std::{ use std::{io::{stdout, Stdout, Write}, mem, ops::{Deref, DerefMut}};
io::{stdout, Stdout, Write},
mem,
ops::{Deref, DerefMut},
};
use anyhow::Result; use anyhow::Result;
use crossterm::{ use crossterm::{event::{DisableBracketedPaste, DisableFocusChange, EnableBracketedPaste, EnableFocusChange, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags}, execute, queue, terminal::{disable_raw_mode, enable_raw_mode, supports_keyboard_enhancement, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen, WindowSize}};
event::{
DisableBracketedPaste, DisableFocusChange, EnableBracketedPaste, EnableFocusChange,
KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
},
execute, queue,
terminal::{
disable_raw_mode, enable_raw_mode, supports_keyboard_enhancement, Clear, ClearType,
EnterAlternateScreen, LeaveAlternateScreen, WindowSize,
},
};
use ratatui::{backend::CrosstermBackend, Terminal}; use ratatui::{backend::CrosstermBackend, Terminal};
pub struct Term { pub struct Term {
@ -121,21 +107,15 @@ impl Term {
} }
impl Drop for Term { impl Drop for Term {
fn drop(&mut self) { fn drop(&mut self) { self.stop().ok(); }
self.stop().ok();
}
} }
impl Deref for Term { impl Deref for Term {
type Target = Terminal<CrosstermBackend<Stdout>>; type Target = Terminal<CrosstermBackend<Stdout>>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target { &self.inner }
&self.inner
}
} }
impl DerefMut for Term { impl DerefMut for Term {
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner }
&mut self.inner
}
} }