mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
e77fa7a804
commit
e62b324be1
17 changed files with 104 additions and 96 deletions
|
|
@ -1,6 +1,5 @@
|
|||
use std::fmt::{self, Display};
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use yazi_shared::Layer;
|
||||
|
||||
use super::Control;
|
||||
use crate::MERGED_KEYMAP;
|
||||
|
|
@ -63,41 +62,15 @@ impl Default for Keymap {
|
|||
|
||||
impl Keymap {
|
||||
#[inline]
|
||||
pub fn get(&self, layer: KeymapLayer) -> &Vec<Control> {
|
||||
pub fn get(&self, layer: Layer) -> &Vec<Control> {
|
||||
match layer {
|
||||
KeymapLayer::Manager => &self.manager,
|
||||
KeymapLayer::Tasks => &self.tasks,
|
||||
KeymapLayer::Select => &self.select,
|
||||
KeymapLayer::Input => &self.input,
|
||||
KeymapLayer::Help => &self.help,
|
||||
KeymapLayer::Completion => &self.completion,
|
||||
KeymapLayer::Which => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
pub enum KeymapLayer {
|
||||
#[default]
|
||||
Manager,
|
||||
Tasks,
|
||||
Select,
|
||||
Input,
|
||||
Help,
|
||||
Completion,
|
||||
Which,
|
||||
}
|
||||
|
||||
impl Display for KeymapLayer {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
KeymapLayer::Manager => write!(f, "manager"),
|
||||
KeymapLayer::Tasks => write!(f, "tasks"),
|
||||
KeymapLayer::Select => write!(f, "select"),
|
||||
KeymapLayer::Input => write!(f, "input"),
|
||||
KeymapLayer::Help => write!(f, "help"),
|
||||
KeymapLayer::Completion => write!(f, "completion"),
|
||||
KeymapLayer::Which => write!(f, "which"),
|
||||
Layer::Manager => &self.manager,
|
||||
Layer::Tasks => &self.tasks,
|
||||
Layer::Select => &self.select,
|
||||
Layer::Input => &self.input,
|
||||
Layer::Help => &self.help,
|
||||
Layer::Completion => &self.completion,
|
||||
Layer::Which => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use yazi_config::keymap::{Exec, KeymapLayer};
|
||||
use yazi_config::keymap::Exec;
|
||||
use yazi_shared::Layer;
|
||||
|
||||
use crate::{completion::Completion, emit, input::Input};
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ impl From<&Exec> for Opt {
|
|||
impl Completion {
|
||||
#[inline]
|
||||
pub fn _close() {
|
||||
emit!(Call(Exec::call("close", vec![]).vec(), KeymapLayer::Completion));
|
||||
emit!(Call(Exec::call("close", vec![]).vec(), Layer::Completion));
|
||||
}
|
||||
|
||||
pub fn close(&mut self, opt: impl Into<Opt>) -> bool {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}};
|
||||
|
||||
use tokio::fs;
|
||||
use yazi_config::keymap::{Exec, KeymapLayer};
|
||||
use yazi_config::keymap::Exec;
|
||||
use yazi_shared::Layer;
|
||||
|
||||
use crate::{completion::Completion, emit};
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ impl Completion {
|
|||
pub fn _trigger(word: &str, ticket: usize) {
|
||||
emit!(Call(
|
||||
Exec::call("trigger", vec![word.to_owned()]).with("ticket", ticket).vec(),
|
||||
KeymapLayer::Completion
|
||||
Layer::Completion
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ impl Completion {
|
|||
.with("word", child)
|
||||
.with("ticket", ticket)
|
||||
.vec(),
|
||||
KeymapLayer::Completion
|
||||
Layer::Completion
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ use std::{collections::BTreeMap, ffi::OsString};
|
|||
use anyhow::Result;
|
||||
use crossterm::event::KeyEvent;
|
||||
use tokio::sync::{mpsc::{self, UnboundedSender}, oneshot};
|
||||
use yazi_config::{keymap::{Exec, KeymapLayer}, open::Opener, popup::{InputOpt, SelectOpt}};
|
||||
use yazi_shared::{fs::Url, InputError, RoCell};
|
||||
use yazi_config::{keymap::Exec, open::Opener, popup::{InputOpt, SelectOpt}};
|
||||
use yazi_shared::{fs::Url, InputError, Layer, RoCell};
|
||||
|
||||
use super::files::FilesOp;
|
||||
use crate::{preview::PreviewLock, tasks::TasksProgress};
|
||||
|
|
@ -18,7 +18,7 @@ pub enum Event {
|
|||
Render(String),
|
||||
Resize(u16, u16),
|
||||
Stop(bool, Option<oneshot::Sender<()>>),
|
||||
Call(Vec<Exec>, KeymapLayer),
|
||||
Call(Vec<Exec>, Layer),
|
||||
|
||||
// Manager
|
||||
Files(FilesOp),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crossterm::event::KeyCode;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
use yazi_config::{keymap::{Control, Key, KeymapLayer}, KEYMAP};
|
||||
use yazi_shared::term::Term;
|
||||
use yazi_config::{keymap::{Control, Key}, KEYMAP};
|
||||
use yazi_shared::{term::Term, Layer};
|
||||
|
||||
use super::HELP_MARGIN;
|
||||
use crate::input::Input;
|
||||
|
|
@ -9,7 +9,7 @@ use crate::input::Input;
|
|||
#[derive(Default)]
|
||||
pub struct Help {
|
||||
pub visible: bool,
|
||||
pub layer: KeymapLayer,
|
||||
pub layer: Layer,
|
||||
pub(super) bindings: Vec<Control>,
|
||||
|
||||
// Filter
|
||||
|
|
@ -24,7 +24,7 @@ impl Help {
|
|||
#[inline]
|
||||
pub fn limit() -> usize { Term::size().rows.saturating_sub(HELP_MARGIN) as usize }
|
||||
|
||||
pub fn toggle(&mut self, layer: KeymapLayer) -> bool {
|
||||
pub fn toggle(&mut self, layer: Layer) -> bool {
|
||||
self.visible = !self.visible;
|
||||
self.layer = layer;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::path::MAIN_SEPARATOR;
|
||||
|
||||
use yazi_config::keymap::{Exec, KeymapLayer};
|
||||
use yazi_config::keymap::Exec;
|
||||
use yazi_shared::Layer;
|
||||
|
||||
use crate::{emit, input::Input};
|
||||
|
||||
|
|
@ -23,7 +24,7 @@ impl Input {
|
|||
pub fn _complete(word: &str, ticket: usize) {
|
||||
emit!(Call(
|
||||
Exec::call("complete", vec![word.to_owned()]).with("ticket", ticket).vec(),
|
||||
KeymapLayer::Input
|
||||
Layer::Input
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::BTreeSet;
|
||||
|
||||
use yazi_config::keymap::{Exec, KeymapLayer};
|
||||
use yazi_shared::fs::Url;
|
||||
use yazi_config::keymap::Exec;
|
||||
use yazi_shared::{fs::Url, Layer};
|
||||
|
||||
use crate::{emit, manager::Manager};
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ impl Manager {
|
|||
pub fn _hover(url: Option<Url>) {
|
||||
emit!(Call(
|
||||
Exec::call("hover", url.map_or_else(Vec::new, |u| vec![u.to_string()])).vec(),
|
||||
KeymapLayer::Manager
|
||||
Layer::Manager
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use yazi_config::{keymap::{Exec, KeymapLayer}, MANAGER};
|
||||
use yazi_shared::{fs::Url, MIME_DIR};
|
||||
use yazi_config::{keymap::Exec, MANAGER};
|
||||
use yazi_shared::{fs::Url, Layer, MIME_DIR};
|
||||
|
||||
use crate::{emit, manager::Manager};
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ impl Manager {
|
|||
.with("only-if", only_if.to_string())
|
||||
.with_bool("upper-bound", true)
|
||||
.vec(),
|
||||
KeymapLayer::Manager
|
||||
Layer::Manager
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::env;
|
||||
|
||||
use yazi_config::keymap::{Exec, KeymapLayer};
|
||||
use yazi_config::keymap::Exec;
|
||||
use yazi_shared::Layer;
|
||||
|
||||
use crate::{emit, manager::Manager};
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ impl From<&Exec> for Opt {
|
|||
impl Manager {
|
||||
#[inline]
|
||||
pub fn _refresh() {
|
||||
emit!(Call(Exec::call("refresh", vec![]).vec(), KeymapLayer::Manager));
|
||||
emit!(Call(Exec::call("refresh", vec![]).vec(), Layer::Manager));
|
||||
}
|
||||
|
||||
pub fn refresh(&mut self, _: impl Into<Opt>) -> bool {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use std::{mem, time::Duration};
|
|||
|
||||
use tokio::{fs, pin};
|
||||
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
||||
use yazi_config::{keymap::{Exec, KeymapLayer}, popup::InputOpt};
|
||||
use yazi_shared::{fs::{expand_path, Url}, Debounce, InputError};
|
||||
use yazi_config::{keymap::Exec, popup::InputOpt};
|
||||
use yazi_shared::{fs::{expand_path, Url}, Debounce, InputError, Layer};
|
||||
|
||||
use crate::{completion::Completion, emit, manager::Manager, tab::Tab};
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ impl From<Url> for Opt {
|
|||
impl Tab {
|
||||
#[inline]
|
||||
pub fn _cd(target: &Url) {
|
||||
emit!(Call(Exec::call("cd", vec![target.to_string()]).vec(), KeymapLayer::Manager));
|
||||
emit!(Call(Exec::call("cd", vec![target.to_string()]).vec(), Layer::Manager));
|
||||
}
|
||||
|
||||
pub fn cd(&mut self, opt: impl Into<Opt>) -> bool {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use std::time::Duration;
|
|||
|
||||
use tokio::pin;
|
||||
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
||||
use yazi_config::{keymap::{Exec, KeymapLayer}, popup::InputOpt};
|
||||
use yazi_shared::{Debounce, InputError};
|
||||
use yazi_config::{keymap::Exec, popup::InputOpt};
|
||||
use yazi_shared::{Debounce, InputError, Layer};
|
||||
|
||||
use crate::{emit, tab::{Finder, FinderCase, Tab}};
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ impl Tab {
|
|||
.with_bool("smart", opt.case == FinderCase::Smart)
|
||||
.with_bool("insensitive", opt.case == FinderCase::Insensitive)
|
||||
.vec(),
|
||||
KeymapLayer::Manager
|
||||
Layer::Manager
|
||||
));
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use yazi_config::keymap::{Exec, KeymapLayer};
|
||||
use yazi_shared::fs::{expand_path, Url};
|
||||
use yazi_config::keymap::Exec;
|
||||
use yazi_shared::{fs::{expand_path, Url}, Layer};
|
||||
|
||||
use crate::{emit, files::{File, FilesOp}, manager::Manager, tab::Tab};
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ impl From<Url> for Opt {
|
|||
impl Tab {
|
||||
#[inline]
|
||||
pub fn _reveal(target: &Url) {
|
||||
emit!(Call(Exec::call("reveal", vec![target.to_string()]).vec(), KeymapLayer::Manager));
|
||||
emit!(Call(Exec::call("reveal", vec![target.to_string()]).vec(), Layer::Manager));
|
||||
}
|
||||
|
||||
pub fn reveal(&mut self, opt: impl Into<Opt>) -> bool {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
use std::mem;
|
||||
|
||||
use yazi_config::{keymap::{Control, Key, KeymapLayer}, KEYMAP};
|
||||
use yazi_config::{keymap::{Control, Key}, KEYMAP};
|
||||
use yazi_shared::Layer;
|
||||
|
||||
use crate::emit;
|
||||
|
||||
pub struct Which {
|
||||
layer: KeymapLayer,
|
||||
layer: Layer,
|
||||
pub times: usize,
|
||||
pub cands: Vec<Control>,
|
||||
|
||||
|
|
@ -14,12 +15,12 @@ pub struct Which {
|
|||
|
||||
impl Default for Which {
|
||||
fn default() -> Self {
|
||||
Self { layer: KeymapLayer::Manager, times: 0, cands: Default::default(), visible: false }
|
||||
Self { layer: Layer::Manager, times: 0, cands: Default::default(), visible: false }
|
||||
}
|
||||
}
|
||||
|
||||
impl Which {
|
||||
pub fn show(&mut self, key: &Key, layer: KeymapLayer) -> bool {
|
||||
pub fn show(&mut self, key: &Key, layer: Layer) -> bool {
|
||||
self.layer = layer;
|
||||
self.times = 1;
|
||||
self.cands =
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ use anyhow::{Ok, Result};
|
|||
use crossterm::event::KeyEvent;
|
||||
use ratatui::{backend::Backend, prelude::Rect};
|
||||
use tokio::sync::oneshot;
|
||||
use yazi_config::{keymap::{Exec, Key, KeymapLayer}, BOOT};
|
||||
use yazi_config::{keymap::{Exec, Key}, BOOT};
|
||||
use yazi_core::{emit, files::FilesOp, input::InputMode, manager::Manager, preview::COLLISION, Ctx, Event};
|
||||
use yazi_shared::term::Term;
|
||||
use yazi_shared::{term::Term, Layer};
|
||||
|
||||
use crate::{Executor, Logs, Panic, Root, Signals};
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ impl App {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn dispatch_call(&mut self, exec: Vec<Exec>, layer: KeymapLayer) {
|
||||
fn dispatch_call(&mut self, exec: Vec<Exec>, layer: Layer) {
|
||||
if Executor::new(&mut self.cx).dispatch(&exec, layer) {
|
||||
emit!(Render);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use yazi_config::{keymap::{Control, Exec, Key, KeymapLayer}, KEYMAP};
|
||||
use yazi_config::{keymap::{Control, Exec, Key}, KEYMAP};
|
||||
use yazi_core::{input::InputMode, Ctx};
|
||||
use yazi_shared::Layer;
|
||||
|
||||
pub(super) struct Executor<'a> {
|
||||
cx: &'a mut Ctx,
|
||||
|
|
@ -21,23 +22,23 @@ impl<'a> Executor<'a> {
|
|||
}
|
||||
|
||||
let b = if self.cx.completion.visible {
|
||||
self.matches(KeymapLayer::Completion, key).or_else(|| self.matches(KeymapLayer::Input, key))
|
||||
self.matches(Layer::Completion, key).or_else(|| self.matches(Layer::Input, key))
|
||||
} else if self.cx.help.visible {
|
||||
self.matches(KeymapLayer::Help, key)
|
||||
self.matches(Layer::Help, key)
|
||||
} else if self.cx.input.visible {
|
||||
self.matches(KeymapLayer::Input, key)
|
||||
self.matches(Layer::Input, key)
|
||||
} else if self.cx.select.visible {
|
||||
self.matches(KeymapLayer::Select, key)
|
||||
self.matches(Layer::Select, key)
|
||||
} else if self.cx.tasks.visible {
|
||||
self.matches(KeymapLayer::Tasks, key)
|
||||
self.matches(Layer::Tasks, key)
|
||||
} else {
|
||||
self.matches(KeymapLayer::Manager, key)
|
||||
self.matches(Layer::Manager, key)
|
||||
};
|
||||
b == Some(true)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn matches(&mut self, layer: KeymapLayer, key: Key) -> Option<bool> {
|
||||
fn matches(&mut self, layer: Layer, key: Key) -> Option<bool> {
|
||||
for Control { on, exec, .. } in KEYMAP.get(layer) {
|
||||
if on.is_empty() || on[0] != key {
|
||||
continue;
|
||||
|
|
@ -53,17 +54,17 @@ impl<'a> Executor<'a> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub(super) fn dispatch(&mut self, exec: &[Exec], layer: KeymapLayer) -> bool {
|
||||
pub(super) fn dispatch(&mut self, exec: &[Exec], layer: Layer) -> bool {
|
||||
let mut render = false;
|
||||
for e in exec {
|
||||
render |= match layer {
|
||||
KeymapLayer::Manager => self.manager(e),
|
||||
KeymapLayer::Tasks => self.tasks(e),
|
||||
KeymapLayer::Select => self.select(e),
|
||||
KeymapLayer::Input => self.input(e),
|
||||
KeymapLayer::Help => self.help(e),
|
||||
KeymapLayer::Completion => self.completion(e),
|
||||
KeymapLayer::Which => unreachable!(),
|
||||
Layer::Manager => self.manager(e),
|
||||
Layer::Tasks => self.tasks(e),
|
||||
Layer::Select => self.select(e),
|
||||
Layer::Input => self.input(e),
|
||||
Layer::Help => self.help(e),
|
||||
Layer::Completion => self.completion(e),
|
||||
Layer::Which => unreachable!(),
|
||||
};
|
||||
}
|
||||
render
|
||||
|
|
@ -143,7 +144,7 @@ impl<'a> Executor<'a> {
|
|||
// Tasks
|
||||
b"tasks_show" => self.cx.tasks.toggle(()),
|
||||
// Help
|
||||
b"help" => self.cx.help.toggle(KeymapLayer::Manager),
|
||||
b"help" => self.cx.help.toggle(Layer::Manager),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -168,7 +169,7 @@ impl<'a> Executor<'a> {
|
|||
on!(cancel);
|
||||
|
||||
match exec.cmd.as_str() {
|
||||
"help" => self.cx.help.toggle(KeymapLayer::Tasks),
|
||||
"help" => self.cx.help.toggle(Layer::Tasks),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -186,7 +187,7 @@ impl<'a> Executor<'a> {
|
|||
on!(arrow);
|
||||
|
||||
match exec.cmd.as_str() {
|
||||
"help" => self.cx.help.toggle(KeymapLayer::Select),
|
||||
"help" => self.cx.help.toggle(Layer::Select),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -232,7 +233,7 @@ impl<'a> Executor<'a> {
|
|||
on!(redo);
|
||||
|
||||
match exec.cmd.as_str() {
|
||||
"help" => self.cx.help.toggle(KeymapLayer::Input),
|
||||
"help" => self.cx.help.toggle(Layer::Input),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -259,7 +260,7 @@ impl<'a> Executor<'a> {
|
|||
on!(filter);
|
||||
|
||||
match exec.cmd.as_str() {
|
||||
"close" => self.cx.help.toggle(KeymapLayer::Help),
|
||||
"close" => self.cx.help.toggle(Layer::Help),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -279,7 +280,7 @@ impl<'a> Executor<'a> {
|
|||
on!(arrow);
|
||||
|
||||
match exec.cmd.as_str() {
|
||||
"help" => self.cx.help.toggle(KeymapLayer::Completion),
|
||||
"help" => self.cx.help.toggle(Layer::Completion),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
yazi-shared/src/layer.rs
Normal file
27
yazi-shared/src/layer.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use std::fmt::{self, Display};
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
pub enum Layer {
|
||||
#[default]
|
||||
Manager,
|
||||
Tasks,
|
||||
Select,
|
||||
Input,
|
||||
Help,
|
||||
Completion,
|
||||
Which,
|
||||
}
|
||||
|
||||
impl Display for Layer {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Manager => write!(f, "manager"),
|
||||
Self::Tasks => write!(f, "tasks"),
|
||||
Self::Select => write!(f, "select"),
|
||||
Self::Input => write!(f, "input"),
|
||||
Self::Help => write!(f, "help"),
|
||||
Self::Completion => write!(f, "completion"),
|
||||
Self::Which => write!(f, "which"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ mod defer;
|
|||
mod env;
|
||||
mod errors;
|
||||
pub mod fs;
|
||||
mod layer;
|
||||
mod mime;
|
||||
mod natsort;
|
||||
mod ro_cell;
|
||||
|
|
@ -18,6 +19,7 @@ pub use debounce::*;
|
|||
pub use defer::*;
|
||||
pub use env::*;
|
||||
pub use errors::*;
|
||||
pub use layer::*;
|
||||
pub use mime::*;
|
||||
pub use natsort::*;
|
||||
pub use ro_cell::*;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue