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