mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: help
This commit is contained in:
parent
e31bc6a075
commit
7a8923a3b6
13 changed files with 405 additions and 135 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use core::{input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which, Position};
|
||||
use core::{help::Help, input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which, Position};
|
||||
|
||||
use config::keymap::KeymapLayer;
|
||||
use crossterm::terminal::WindowSize;
|
||||
|
|
@ -8,8 +8,9 @@ use shared::Term;
|
|||
pub struct Ctx {
|
||||
pub manager: Manager,
|
||||
pub which: Which,
|
||||
pub select: Select,
|
||||
pub help: Help,
|
||||
pub input: Input,
|
||||
pub select: Select,
|
||||
pub tasks: Tasks,
|
||||
}
|
||||
|
||||
|
|
@ -18,8 +19,9 @@ impl Ctx {
|
|||
Self {
|
||||
manager: Manager::make(),
|
||||
which: Default::default(),
|
||||
select: Default::default(),
|
||||
help: Default::default(),
|
||||
input: Default::default(),
|
||||
select: Default::default(),
|
||||
tasks: Tasks::start(),
|
||||
}
|
||||
}
|
||||
|
|
@ -67,6 +69,8 @@ impl Ctx {
|
|||
pub(super) fn layer(&self) -> KeymapLayer {
|
||||
if self.which.visible {
|
||||
KeymapLayer::Which
|
||||
} else if self.help.visible {
|
||||
KeymapLayer::Help
|
||||
} else if self.input.visible {
|
||||
KeymapLayer::Input
|
||||
} else if self.select.visible {
|
||||
|
|
@ -80,6 +84,6 @@ impl Ctx {
|
|||
|
||||
#[inline]
|
||||
pub(super) fn image_layer(&self) -> bool {
|
||||
!matches!(self.layer(), KeymapLayer::Which | KeymapLayer::Tasks)
|
||||
!matches!(self.layer(), KeymapLayer::Which | KeymapLayer::Help | KeymapLayer::Tasks)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ impl Executor {
|
|||
KeymapLayer::Tasks => Self::tasks(cx, e),
|
||||
KeymapLayer::Select => Self::select(cx, e),
|
||||
KeymapLayer::Input => Self::input(cx, e),
|
||||
KeymapLayer::Help => Self::help(cx, e),
|
||||
KeymapLayer::Which => unreachable!(),
|
||||
};
|
||||
}
|
||||
|
|
@ -173,6 +174,9 @@ impl Executor {
|
|||
// Tasks
|
||||
"tasks_show" => cx.tasks.toggle(),
|
||||
|
||||
// Help
|
||||
"help" => cx.help.toggle(cx.layer()),
|
||||
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -187,8 +191,9 @@ impl Executor {
|
|||
}
|
||||
|
||||
"inspect" => cx.tasks.inspect(),
|
||||
|
||||
"cancel" => cx.tasks.cancel(),
|
||||
|
||||
"help" => cx.help.toggle(cx.layer()),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -202,6 +207,7 @@ impl Executor {
|
|||
if step > 0 { cx.select.next(step as usize) } else { cx.select.prev(step.unsigned_abs()) }
|
||||
}
|
||||
|
||||
"help" => cx.help.toggle(cx.layer()),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -235,6 +241,8 @@ impl Executor {
|
|||
|
||||
"undo" => cx.input.undo(),
|
||||
"redo" => cx.input.redo(),
|
||||
|
||||
"help" => cx.help.toggle(cx.layer()),
|
||||
_ => false,
|
||||
},
|
||||
InputMode::Insert => match exec.cmd.as_str() {
|
||||
|
|
@ -243,4 +251,20 @@ impl Executor {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn help(cx: &mut Ctx, exec: &Exec) -> bool {
|
||||
match exec.cmd.as_str() {
|
||||
"close" => cx.help.toggle(cx.layer()),
|
||||
"escape" => cx.help.escape(),
|
||||
|
||||
"arrow" => {
|
||||
let step = exec.args.get(0).and_then(|s| s.parse().ok()).unwrap_or(0);
|
||||
cx.help.arrow(step)
|
||||
}
|
||||
|
||||
"filter" => cx.help.filter(),
|
||||
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
55
app/src/help/bindings.rs
Normal file
55
app/src/help/bindings.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
use ratatui::{layout::{self, Constraint}, prelude::{Buffer, Direction, Rect}, style::{Modifier, Style}, widgets::{List, ListItem, Widget}};
|
||||
|
||||
use crate::context::Ctx;
|
||||
|
||||
pub(super) struct Bindings<'a> {
|
||||
cx: &'a Ctx,
|
||||
}
|
||||
|
||||
impl<'a> Bindings<'a> {
|
||||
pub(super) fn new(cx: &'a Ctx) -> Self { Self { cx } }
|
||||
}
|
||||
|
||||
impl Widget for Bindings<'_> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let bindings = &self.cx.help.window();
|
||||
let cursor = self.cx.help.rel_cursor();
|
||||
|
||||
let col1 = bindings
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, c)| {
|
||||
let mut x = ListItem::new(c.on.iter().map(ToString::to_string).collect::<String>());
|
||||
|
||||
if i == cursor {
|
||||
x = x.style(Style::new().add_modifier(Modifier::UNDERLINED));
|
||||
}
|
||||
x
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let col2 = bindings
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, c)| {
|
||||
let mut x =
|
||||
ListItem::new(c.exec.iter().map(ToString::to_string).collect::<Vec<_>>().join("; "));
|
||||
|
||||
if i == cursor {
|
||||
x = x.style(Style::new().add_modifier(Modifier::UNDERLINED));
|
||||
}
|
||||
x
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let chunks = layout::Layout::new()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints(
|
||||
[Constraint::Ratio(1, 9), Constraint::Ratio(4, 9), Constraint::Ratio(4, 9)].as_ref(),
|
||||
)
|
||||
.split(area);
|
||||
|
||||
List::new(col1).render(chunks[0], buf);
|
||||
List::new(col2).render(chunks[1], buf);
|
||||
}
|
||||
}
|
||||
28
app/src/help/layout.rs
Normal file
28
app/src/help/layout.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, style::{Color, Style}, widgets::{Clear, Paragraph, Widget}};
|
||||
|
||||
use super::Bindings;
|
||||
use crate::Ctx;
|
||||
|
||||
pub(crate) struct Layout<'a> {
|
||||
cx: &'a Ctx,
|
||||
}
|
||||
|
||||
impl<'a> Layout<'a> {
|
||||
pub fn new(cx: &'a Ctx) -> Self { Self { cx } }
|
||||
}
|
||||
|
||||
impl<'a> Widget for Layout<'a> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let chunks = layout::Layout::new()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Min(0), Constraint::Length(1)].as_ref())
|
||||
.split(area);
|
||||
|
||||
Clear.render(area, buf);
|
||||
Paragraph::new("manager.help")
|
||||
.style(Style::new().fg(Color::Rgb(35, 39, 59)).bg(Color::Rgb(200, 211, 248)))
|
||||
.render(chunks[1], buf);
|
||||
|
||||
Bindings::new(self.cx).render(chunks[0], buf);
|
||||
}
|
||||
}
|
||||
5
app/src/help/mod.rs
Normal file
5
app/src/help/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
mod bindings;
|
||||
mod layout;
|
||||
|
||||
use bindings::*;
|
||||
pub use layout::*;
|
||||
|
|
@ -4,6 +4,7 @@ mod app;
|
|||
mod context;
|
||||
mod executor;
|
||||
mod header;
|
||||
mod help;
|
||||
mod input;
|
||||
mod logs;
|
||||
mod manager;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use ratatui::{buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, widgets::Widget};
|
||||
|
||||
use super::{header, input, manager, select, status, tasks, which, Ctx};
|
||||
use crate::help;
|
||||
|
||||
pub(super) struct Root<'a> {
|
||||
cx: &'a Ctx,
|
||||
|
|
@ -33,6 +34,10 @@ impl<'a> Widget for Root<'a> {
|
|||
input::Input::new(self.cx).render(area, buf);
|
||||
}
|
||||
|
||||
if self.cx.help.visible {
|
||||
help::Layout::new(self.cx).render(area, buf);
|
||||
}
|
||||
|
||||
if self.cx.which.visible {
|
||||
which::Which::new(self.cx).render(area, buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@
|
|||
- enter: Enter the child directory.
|
||||
- back: Go back to the previous directory.
|
||||
- forward: Go forward to the next directory.
|
||||
- peek
|
||||
|
||||
- `n`: Peek up or down at file contents in the preview. Use negative values to peek up and positive values to peek down.
|
||||
|
||||
- cd: Change the current directory.
|
||||
|
||||
- `path`: the path to change to.
|
||||
|
|
@ -54,11 +58,11 @@
|
|||
- `--force`: Overwrite the destination file if it exists.
|
||||
- `--follow`: Copy the file pointed to by a symbolic link, rather than the link itself. Only valid during copying.
|
||||
|
||||
- remove: Move the file to the trash/recycle bin.
|
||||
- remove: Move the files to the trash/recycle bin.
|
||||
|
||||
- `--permanently`: Permanently delete the file.
|
||||
- `--permanently`: Permanently delete the files.
|
||||
|
||||
- create: Create a file or directory (ends with `/` for directory).
|
||||
- create: Create a file or directory (ends with `/` for directories).
|
||||
- rename: Rename a file or directory.
|
||||
- copy: Copy the path of files or directories that are selected or hovered on.
|
||||
|
||||
|
|
@ -90,12 +94,23 @@
|
|||
- `fzf`: Jump to a directory, or reveal a file using fzf.
|
||||
- `zoxide`: Jump to a directory using zoxide.
|
||||
|
||||
- sort
|
||||
|
||||
- `by`
|
||||
- `"alphabetical"`: Sort alphabetically, e.g. `1.md` < `10.md` < `2.md`
|
||||
- `"created"`: Sort by creation time.
|
||||
- `"modified"`: Sort by last modified time.
|
||||
- `"natural"`: Sort naturally, e.g. `1.md` < `2.md` < `10.md`
|
||||
- `"size"`: Sort by file size.
|
||||
- `--reverse`: Display files in reverse order.
|
||||
- `--dir_first`: Display directories first.
|
||||
|
||||
### Tabs
|
||||
|
||||
- tab_create
|
||||
|
||||
- `path`: Create a new tab using the specified path.
|
||||
- `--current`: Create a new tab based on the current directory.
|
||||
- `--current`: Create a new tab using the current path.
|
||||
|
||||
- tab_close
|
||||
|
||||
|
|
@ -112,7 +127,11 @@
|
|||
|
||||
### Tasks
|
||||
|
||||
- tasks_show: Display the task manager.
|
||||
- tasks_show: Show the task manager.
|
||||
|
||||
### Help
|
||||
|
||||
- help: Open the help menu.
|
||||
|
||||
## tasks
|
||||
|
||||
|
|
@ -120,7 +139,9 @@
|
|||
- arrow:
|
||||
- `-1`: Move the cursor up 1 line.
|
||||
- `1`: Move the cursor down 1 line.
|
||||
- inspect: Inspect the task.
|
||||
- cancel: Cancel the task.
|
||||
- help: Open the help menu.
|
||||
|
||||
## select
|
||||
|
||||
|
|
@ -128,6 +149,7 @@
|
|||
- `--submit`: Submit the selection.
|
||||
- arrow
|
||||
- `n`: Move the cursor up or down n lines. Negative value for up, positive value for down.
|
||||
- help: Open the help menu.
|
||||
|
||||
## input
|
||||
|
||||
|
|
@ -135,7 +157,7 @@
|
|||
|
||||
- `--submit`: Submit the input.
|
||||
|
||||
- escape: Cancel visual mode and enter normal mode.
|
||||
- escape: Go back the normal mode, or cancel input.
|
||||
- move: Move the cursor left or right.
|
||||
|
||||
- `n`: Move the cursor n characters left or right. Negative value for left, positive value for right.
|
||||
|
|
@ -155,7 +177,7 @@
|
|||
|
||||
- delete: Delete the selected characters.
|
||||
|
||||
- `--cut`: Cut the selected characters into the clipboard, instead of only deleting them.
|
||||
- `--cut`: Cut the selected characters into clipboard, instead of only deleting them.
|
||||
- `--insert`: Delete and enter insert mode.
|
||||
|
||||
- yank: Copy the selected characters.
|
||||
|
|
@ -166,6 +188,8 @@
|
|||
- undo: Undo the last operation.
|
||||
- redo: Redo the last operation.
|
||||
|
||||
- help: Open the help menu.
|
||||
|
||||
### Insert mode
|
||||
|
||||
- close: Cancel input.
|
||||
|
|
@ -174,3 +198,11 @@
|
|||
|
||||
- escape: Cancel insert mode and enter normal mode.
|
||||
- backspace: Delete the character before the cursor.
|
||||
|
||||
## Help
|
||||
|
||||
- close: Hide the help menu.
|
||||
- escape: Clear the filter, or hide the help menu.
|
||||
- arrow
|
||||
- `n`: Move the cursor up or down n lines. Negative value for up, positive value for down.
|
||||
- filter: Apply a filter for the help items.
|
||||
|
|
|
|||
|
|
@ -1,185 +1,214 @@
|
|||
[manager]
|
||||
|
||||
keymap = [
|
||||
{ on = [ "<Esc>" ], exec = "escape" },
|
||||
{ on = [ "q" ], exec = "quit" },
|
||||
# close current tab and exit if it is last tab
|
||||
{ on = [ "<C-q>" ], exec = "close" },
|
||||
{ on = [ "<Esc>" ], exec = "escape", desc = "Exit visual mode, clear selected, or cancel search" },
|
||||
{ on = [ "q" ], exec = "quit", desc = "Exit the process" },
|
||||
{ on = [ "<C-q>" ], exec = "close", desc = "Close the current tab, or quit if it's last tab" },
|
||||
|
||||
# Navigation
|
||||
{ on = [ "k" ], exec = "arrow -1" },
|
||||
{ on = [ "j" ], exec = "arrow 1" },
|
||||
{ on = [ "k" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||
{ on = [ "j" ], exec = "arrow 1", desc = "Move cursor down" },
|
||||
|
||||
{ on = [ "K" ], exec = "arrow -5" },
|
||||
{ on = [ "J" ], exec = "arrow 5" },
|
||||
{ on = [ "K" ], exec = "arrow -5", desc = "Move cursor up 5 lines" },
|
||||
{ on = [ "J" ], exec = "arrow 5", desc = "Move cursor down 5 line" },
|
||||
|
||||
{ on = [ "h" ], exec = "leave" },
|
||||
{ on = [ "l" ], exec = "enter" },
|
||||
{ on = [ "h" ], exec = "leave", desc = "Go back to the parent directory" },
|
||||
{ on = [ "l" ], exec = "enter", desc = "Enter the child directory" },
|
||||
|
||||
{ on = [ "H" ], exec = "back" },
|
||||
{ on = [ "L" ], exec = "forward" },
|
||||
{ on = [ "H" ], exec = "back", desc = "Go back to the previous directory" },
|
||||
{ on = [ "L" ], exec = "forward", desc = "Go forward to the next directory" },
|
||||
|
||||
{ on = [ "<C-k>" ], exec = "peek -5" },
|
||||
{ on = [ "<C-j>" ], exec = "peek 5" },
|
||||
{ on = [ "<C-k>" ], exec = "peek -5", desc = "Peek up 5 units in the preview" },
|
||||
{ on = [ "<C-j>" ], exec = "peek 5", desc = "Peek down 5 units in the preview" },
|
||||
|
||||
{ on = [ "<Up>" ], exec = "arrow -1" },
|
||||
{ on = [ "<Down>" ], exec = "arrow 1" },
|
||||
{ on = [ "<Left>" ], exec = "leave" },
|
||||
{ on = [ "<Right>" ], exec = "enter" },
|
||||
{ on = [ "<Up>" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||
{ on = [ "<Down>" ], exec = "arrow 1", desc = "Move cursor down" },
|
||||
{ on = [ "<Left>" ], exec = "leave", desc = "Go back to the parent directory" },
|
||||
{ on = [ "<Right>" ], exec = "enter", desc = "Enter the child directory" },
|
||||
|
||||
# Selection
|
||||
{ on = [ "<Space>" ], exec = [ "select --state=none", "arrow 1" ] },
|
||||
{ on = [ "v" ], exec = "visual_mode" },
|
||||
{ on = [ "V" ], exec = "visual_mode --unset" },
|
||||
{ on = [ "<C-a>" ], exec = "select_all --state=true" },
|
||||
{ on = [ "<C-r>" ], exec = "select_all --state=none" },
|
||||
{ on = [ "<Space>" ], exec = [ "select --state=none", "arrow 1" ], desc = "Toggle the current selection state" },
|
||||
{ on = [ "v" ], exec = "visual_mode", desc = "Enter visual mode (selection mode)" },
|
||||
{ on = [ "V" ], exec = "visual_mode --unset", desc = "Enter visual mode (unset mode)" },
|
||||
{ on = [ "<C-a>" ], exec = "select_all --state=true", desc = "Select all files" },
|
||||
{ on = [ "<C-r>" ], exec = "select_all --state=none", desc = "Inverse selection of all files" },
|
||||
|
||||
# Operation
|
||||
{ on = [ "o" ], exec = "open" },
|
||||
{ on = [ "O" ], exec = "open --interactive" },
|
||||
{ on = [ "<Enter>" ], exec = "open" },
|
||||
{ on = [ "<C-Enter>" ], exec = "open --interactive" }, # It's cool if you're using a terminal that supports CSI u
|
||||
{ on = [ "y" ], exec = "yank" },
|
||||
{ on = [ "x" ], exec = "yank --cut" },
|
||||
{ on = [ "p" ], exec = "paste" },
|
||||
{ on = [ "P" ], exec = "paste --force" },
|
||||
{ on = [ "k" ], exec = "paste --follow" },
|
||||
{ on = [ "K" ], exec = "paste --follow --force" },
|
||||
{ on = [ "d" ], exec = "remove" },
|
||||
{ on = [ "D" ], exec = "remove --permanently" },
|
||||
{ on = [ "a" ], exec = "create" },
|
||||
{ on = [ "r" ], exec = "rename" },
|
||||
{ on = [ ";" ], exec = "shell" },
|
||||
{ on = [ ":" ], exec = "shell --block" },
|
||||
{ on = [ "." ], exec = "hidden toggle" },
|
||||
{ on = [ "s" ], exec = "search fd" },
|
||||
{ on = [ "S" ], exec = "search rg" },
|
||||
{ on = [ "<C-s>" ], exec = "search none" },
|
||||
{ on = [ "z" ], exec = "jump zoxide" },
|
||||
{ on = [ "Z" ], exec = "jump fzf" },
|
||||
{ on = [ "o" ], exec = "open", desc = "Open the selected files" },
|
||||
{ on = [ "O" ], exec = "open --interactive", desc = "Open the selected files with an interactive UI to choose the opening method" },
|
||||
{ on = [ "<Enter>" ], exec = "open", desc = "Open the selected files" },
|
||||
{ on = [ "<C-Enter>" ], exec = "open --interactive", desc = "Open the selected files with an interactive UI to choose the opening method" }, # It's cool if you're using a terminal that supports CSI u
|
||||
{ on = [ "y" ], exec = "yank", desc = "Copy the selected files" },
|
||||
{ on = [ "x" ], exec = "yank --cut", desc = "Cut the selected files" },
|
||||
{ on = [ "p" ], exec = "paste", desc = "Paste the files" },
|
||||
{ on = [ "P" ], exec = "paste --force", desc = "Paste the files (overwrite if the destination exists)" },
|
||||
{ on = [ "k" ], exec = "paste --follow", desc = "Paste the files (follow the symlinks)" },
|
||||
{ on = [ "K" ], exec = "paste --follow --force", desc = "Paste the files (overwrite + follow)" },
|
||||
{ on = [ "d" ], exec = "remove", desc = "Move the files to the trash" },
|
||||
{ on = [ "D" ], exec = "remove --permanently", desc = "Permanently delete the files" },
|
||||
{ on = [ "a" ], exec = "create", desc = "Create a file or directory (ends with / for directories)" },
|
||||
{ on = [ "r" ], exec = "rename", desc = "Rename a file or directory" },
|
||||
{ on = [ ";" ], exec = "shell", desc = "Run a shell command" },
|
||||
{ on = [ ":" ], exec = "shell --block", desc = "Run a shell command (block the UI until the command finishes)" },
|
||||
{ on = [ "." ], exec = "hidden toggle", desc = "Toggle the visibility of hidden files" },
|
||||
{ on = [ "s" ], exec = "search fd", desc = "Search files by content using ripgrep" },
|
||||
{ on = [ "S" ], exec = "search rg", desc = "Search files by name using fd" },
|
||||
{ on = [ "<C-s>" ], exec = "search none", desc = "Cancel the ongoing search" },
|
||||
{ on = [ "z" ], exec = "jump zoxide", desc = "Jump to a directory, or reveal a file using fzf" },
|
||||
{ on = [ "Z" ], exec = "jump fzf", desc = "Jump to a directory using zoxide" },
|
||||
|
||||
# Copy
|
||||
{ on = [ "c", "c" ], exec = "copy path" },
|
||||
{ on = [ "c", "d" ], exec = "copy dirname" },
|
||||
{ on = [ "c", "f" ], exec = "copy filename" },
|
||||
{ on = [ "c", "n" ], exec = "copy name_without_ext" },
|
||||
{ on = [ "c", "c" ], exec = "copy path", desc = "Copy the full absolute path" },
|
||||
{ on = [ "c", "d" ], exec = "copy dirname", desc = "Copy the path of the parent directory" },
|
||||
{ on = [ "c", "f" ], exec = "copy filename", desc = "Copy the name of the file" },
|
||||
{ on = [ "c", "n" ], exec = "copy name_without_ext", desc = "Copy the name of the file without the extension" },
|
||||
|
||||
# Sorting
|
||||
{ on = [ ",", "a" ], exec = "sort alphabetical --dir_first" },
|
||||
{ on = [ ",", "A" ], exec = "sort alphabetical --reverse --dir_first" },
|
||||
{ on = [ ",", "c" ], exec = "sort created --dir_first" },
|
||||
{ on = [ ",", "C" ], exec = "sort created --reverse --dir_first" },
|
||||
{ on = [ ",", "m" ], exec = "sort modified --dir_first" },
|
||||
{ on = [ ",", "M" ], exec = "sort modified --reverse --dir_first" },
|
||||
{ on = [ ",", "n" ], exec = "sort natural --dir_first" },
|
||||
{ on = [ ",", "N" ], exec = "sort natural --reverse --dir_first" },
|
||||
{ on = [ ",", "s" ], exec = "sort size --dir_first" },
|
||||
{ on = [ ",", "S" ], exec = "sort size --reverse --dir_first" },
|
||||
{ on = [ ",", "a" ], exec = "sort alphabetical --dir_first", desc = "Sort alphabetically, directories first" },
|
||||
{ on = [ ",", "A" ], exec = "sort alphabetical --reverse --dir_first", desc = "Sort alphabetically, directories first (reverse)" },
|
||||
{ on = [ ",", "c" ], exec = "sort created --dir_first", desc = "Sort by creation time, directories first" },
|
||||
{ on = [ ",", "C" ], exec = "sort created --reverse --dir_first", desc = "Sort by creation time, directories first (reverse)" },
|
||||
{ on = [ ",", "m" ], exec = "sort modified --dir_first", desc = "Sort by modified time, directories first" },
|
||||
{ on = [ ",", "M" ], exec = "sort modified --reverse --dir_first", desc = "Sort by modified time, directories first (reverse)" },
|
||||
{ on = [ ",", "n" ], exec = "sort natural --dir_first", desc = "Sort naturally, directories first" },
|
||||
{ on = [ ",", "N" ], exec = "sort natural --reverse --dir_first", desc = "Sort naturally, directories first (reverse)" },
|
||||
{ on = [ ",", "s" ], exec = "sort size --dir_first", desc = "Sort by size, directories first" },
|
||||
{ on = [ ",", "S" ], exec = "sort size --reverse --dir_first", desc = "Sort by size, directories first (reverse)" },
|
||||
|
||||
# Tabs
|
||||
{ on = [ "t" ], exec = "tab_create --current" },
|
||||
{ on = [ "t" ], exec = "tab_create --current", desc = "Create a new tab using the current path" },
|
||||
|
||||
{ on = [ "1" ], exec = "tab_switch 0" },
|
||||
{ on = [ "2" ], exec = "tab_switch 1" },
|
||||
{ on = [ "3" ], exec = "tab_switch 2" },
|
||||
{ on = [ "4" ], exec = "tab_switch 3" },
|
||||
{ on = [ "5" ], exec = "tab_switch 4" },
|
||||
{ on = [ "6" ], exec = "tab_switch 5" },
|
||||
{ on = [ "7" ], exec = "tab_switch 6" },
|
||||
{ on = [ "8" ], exec = "tab_switch 7" },
|
||||
{ on = [ "9" ], exec = "tab_switch 8" },
|
||||
{ on = [ "1" ], exec = "tab_switch 0", desc = "Switch to the first tab" },
|
||||
{ on = [ "2" ], exec = "tab_switch 1", desc = "Switch to the second tab" },
|
||||
{ on = [ "3" ], exec = "tab_switch 2", desc = "Switch to the third tab" },
|
||||
{ on = [ "4" ], exec = "tab_switch 3", desc = "Switch to the fourth tab" },
|
||||
{ on = [ "5" ], exec = "tab_switch 4", desc = "Switch to the fifth tab" },
|
||||
{ on = [ "6" ], exec = "tab_switch 5", desc = "Switch to the sixth tab" },
|
||||
{ on = [ "7" ], exec = "tab_switch 6", desc = "Switch to the seventh tab" },
|
||||
{ on = [ "8" ], exec = "tab_switch 7", desc = "Switch to the eighth tab" },
|
||||
{ on = [ "9" ], exec = "tab_switch 8", desc = "Switch to the ninth tab" },
|
||||
|
||||
{ on = [ "[" ], exec = "tab_switch -1 --relative" },
|
||||
{ on = [ "]" ], exec = "tab_switch 1 --relative" },
|
||||
{ on = [ "[" ], exec = "tab_switch -1 --relative", desc = "Switch to the previous tab" },
|
||||
{ on = [ "]" ], exec = "tab_switch 1 --relative", desc = "Switch to the next tab" },
|
||||
|
||||
{ on = [ "{" ], exec = "tab_swap -1" },
|
||||
{ on = [ "}" ], exec = "tab_swap 1" },
|
||||
{ on = [ "{" ], exec = "tab_swap -1", desc = "Swap the current tab with the previous tab" },
|
||||
{ on = [ "}" ], exec = "tab_swap 1", desc = "Swap the current tab with the next tab" },
|
||||
|
||||
# Tasks
|
||||
{ on = [ "w" ], exec = "tasks_show" },
|
||||
{ on = [ "w" ], exec = "tasks_show", desc = "Show the tasks manager" },
|
||||
|
||||
# Goto
|
||||
{ on = [ "g", "h" ], exec = "cd ~" },
|
||||
{ on = [ "g", "c" ], exec = "cd ~/.config" },
|
||||
{ on = [ "g", "d" ], exec = "cd ~/Downloads" },
|
||||
{ on = [ "g", "t" ], exec = "cd /tmp" },
|
||||
{ on = [ "g", "<Space>" ], exec = "cd --interactive" },
|
||||
{ on = [ "g", "h" ], exec = "cd ~", desc = "Go to the home directory" },
|
||||
{ on = [ "g", "c" ], exec = "cd ~/.config", desc = "Go to the config directory" },
|
||||
{ on = [ "g", "d" ], exec = "cd ~/Downloads", desc = "Go to the downloads directory" },
|
||||
{ on = [ "g", "t" ], exec = "cd /tmp", desc = "Go to the temporary directory" },
|
||||
{ on = [ "g", "<Space>" ], exec = "cd --interactive", desc = "Go to a directory interactively" },
|
||||
|
||||
# Help
|
||||
{ on = [ "?" ], exec = "help", desc = "Open help" },
|
||||
]
|
||||
|
||||
[tasks]
|
||||
|
||||
keymap = [
|
||||
{ on = [ "<C-q>" ], exec = "close" },
|
||||
{ on = [ "<Esc>" ], exec = "close" },
|
||||
{ on = [ "w" ], exec = "close" },
|
||||
{ on = [ "<C-q>" ], exec = "close", desc = "Hide the task manager" },
|
||||
{ on = [ "<Esc>" ], exec = "close", desc = "Hide the task manager" },
|
||||
{ on = [ "w" ], exec = "close", desc = "Hide the task manager" },
|
||||
|
||||
{ on = [ "k" ], exec = "arrow -1" },
|
||||
{ on = [ "j" ], exec = "arrow 1" },
|
||||
{ on = [ "k" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||
{ on = [ "j" ], exec = "arrow 1", desc = "Move cursor down" },
|
||||
|
||||
{ on = [ "<Up>" ], exec = "arrow -1" },
|
||||
{ on = [ "<Down>" ], exec = "arrow 1" },
|
||||
{ on = [ "<Up>" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||
{ on = [ "<Down>" ], exec = "arrow 1", desc = "Move cursor down" },
|
||||
|
||||
{ on = [ "<Enter>" ], exec = "inspect" },
|
||||
{ on = [ "x" ], exec = "cancel" },
|
||||
{ on = [ "<Enter>" ], exec = "inspect", desc = "Inspect the task" },
|
||||
{ on = [ "x" ], exec = "cancel", desc = "Cancel the task" },
|
||||
|
||||
{ on = [ "?" ], exec = "help", desc = "Open help" }
|
||||
]
|
||||
|
||||
[select]
|
||||
|
||||
keymap = [
|
||||
{ on = [ "<C-q>" ], exec = "close" },
|
||||
{ on = [ "<Esc>" ], exec = "close" },
|
||||
{ on = [ "<Enter>" ], exec = "close --submit" },
|
||||
{ on = [ "<C-q>" ], exec = "close", desc = "Cancel selection" },
|
||||
{ on = [ "<Esc>" ], exec = "close", desc = "Cancel selection" },
|
||||
{ on = [ "<Enter>" ], exec = "close --submit", desc = "Submit the selection" },
|
||||
|
||||
{ on = [ "k" ], exec = "arrow -1" },
|
||||
{ on = [ "j" ], exec = "arrow 1" },
|
||||
{ on = [ "k" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||
{ on = [ "j" ], exec = "arrow 1", desc = "Move cursor down" },
|
||||
|
||||
{ on = [ "K" ], exec = "arrow -5" },
|
||||
{ on = [ "J" ], exec = "arrow 5" },
|
||||
{ on = [ "K" ], exec = "arrow -5", desc = "Move cursor up 5 lines" },
|
||||
{ on = [ "J" ], exec = "arrow 5", desc = "Move cursor down 5 lines" },
|
||||
|
||||
{ on = [ "<Up>" ], exec = "arrow -1" },
|
||||
{ on = [ "<Down>" ], exec = "arrow 1" },
|
||||
{ on = [ "<Up>" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||
{ on = [ "<Down>" ], exec = "arrow 1", desc = "Move cursor down" },
|
||||
|
||||
{ on = [ "?" ], exec = "help", desc = "Open help" }
|
||||
]
|
||||
|
||||
[input]
|
||||
|
||||
keymap = [
|
||||
{ on = [ "<C-q>" ], exec = "close" },
|
||||
{ on = [ "<Enter>" ], exec = "close --submit" },
|
||||
{ on = [ "<Esc>" ], exec = "escape" },
|
||||
{ on = [ "<Backspace>" ], exec = "backspace" },
|
||||
{ on = [ "<C-q>" ], exec = "close", desc = "Cancel input" },
|
||||
{ on = [ "<Enter>" ], exec = "close --submit", desc = "Submit the input" },
|
||||
{ on = [ "<Esc>" ], exec = "escape", desc = "Go back the normal mode, or cancel input" },
|
||||
{ on = [ "<Backspace>" ], exec = "backspace", desc = "Delete the character before the cursor" },
|
||||
|
||||
# Mode
|
||||
{ on = [ "i" ], exec = "insert" },
|
||||
{ on = [ "a" ], exec = "insert --append" },
|
||||
{ on = [ "v" ], exec = "visual" },
|
||||
{ on = [ "i" ], exec = "insert", desc = "Enter insert mode" },
|
||||
{ on = [ "a" ], exec = "insert --append", desc = "Enter append mode" },
|
||||
{ on = [ "v" ], exec = "visual", desc = "Enter visual mode" },
|
||||
|
||||
# Navigation
|
||||
{ on = [ "h" ], exec = "move -1" },
|
||||
{ on = [ "l" ], exec = "move 1" },
|
||||
{ on = [ "h" ], exec = "move -1", desc = "Move cursor left" },
|
||||
{ on = [ "l" ], exec = "move 1", desc = "Move cursor right" },
|
||||
|
||||
{ on = [ "0" ], exec = "move -999" },
|
||||
{ on = [ "$" ], exec = "move 999" },
|
||||
{ on = [ "I" ], exec = [ "move -999", "insert" ] },
|
||||
{ on = [ "A" ], exec = [ "move 999", "insert --append" ] },
|
||||
{ on = [ "0" ], exec = "move -999", desc = "Move to the BOL" },
|
||||
{ on = [ "$" ], exec = "move 999", desc = "Move to the EOL" },
|
||||
{ on = [ "I" ], exec = [ "move -999", "insert" ], desc = "Move to the BOL, and enter insert mode" },
|
||||
{ on = [ "A" ], exec = [ "move 999", "insert --append" ], desc = "Move to the EOL, and enter append mode" },
|
||||
|
||||
{ on = [ "<Left>" ], exec = "move -1" },
|
||||
{ on = [ "<Right>" ], exec = "move 1" },
|
||||
{ on = [ "<Left>" ], exec = "move -1", desc = "Move cursor left" },
|
||||
{ on = [ "<Right>" ], exec = "move 1", desc = "Move cursor right" },
|
||||
|
||||
{ on = [ "b" ], exec = "backward" },
|
||||
{ on = [ "w" ], exec = "forward" },
|
||||
{ on = [ "e" ], exec = "forward --end-of-word" },
|
||||
{ on = [ "b" ], exec = "backward", desc = "Move to the beginning of the previous word" },
|
||||
{ on = [ "w" ], exec = "forward", desc = "Move to the beginning of the next word" },
|
||||
{ on = [ "e" ], exec = "forward --end-of-word", desc = "Move to the end of the next word" },
|
||||
|
||||
# Deletion
|
||||
{ on = [ "d" ], exec = "delete --cut" },
|
||||
{ on = [ "c" ], exec = "delete --cut --insert" },
|
||||
{ on = [ "x" ], exec = [ "delete --cut", "move 1 --in-operating" ] },
|
||||
{ on = [ "d" ], exec = "delete --cut", desc = "Cut the selected characters" },
|
||||
{ on = [ "c" ], exec = "delete --cut --insert", desc = "Cut the selected characters, and enter insert mode" },
|
||||
{ on = [ "x" ], exec = [ "delete --cut", "move 1 --in-operating" ], desc = "Cut the current character" },
|
||||
|
||||
# Yank/Paste
|
||||
{ on = [ "y" ], exec = "yank" },
|
||||
{ on = [ "p" ], exec = "paste" },
|
||||
{ on = [ "P" ], exec = "paste --before" },
|
||||
{ on = [ "y" ], exec = "yank", desc = "Copy the selected characters" },
|
||||
{ on = [ "p" ], exec = "paste", desc = "Paste the copied characters after the cursor" },
|
||||
{ on = [ "P" ], exec = "paste --before", desc = "Paste the copied characters before the cursor" },
|
||||
|
||||
# Undo/Redo
|
||||
{ on = [ "u" ], exec = "undo" },
|
||||
{ on = [ "<C-r>" ], exec = "redo" },
|
||||
{ on = [ "u" ], exec = "undo", desc = "Undo the last operation" },
|
||||
{ on = [ "<C-r>" ], exec = "redo", desc = "Redo the last operation" },
|
||||
|
||||
# Help
|
||||
{ on = [ "?" ], exec = "help", desc = "Open help" }
|
||||
]
|
||||
|
||||
[help]
|
||||
|
||||
keymap = [
|
||||
{ on = [ "<C-q>" ], exec = "close", desc = "Hide the help" },
|
||||
{ on = [ "<Esc>" ], exec = "escape", desc = "Clear the filter, or hide the help" },
|
||||
|
||||
# Navigation
|
||||
{ on = [ "k" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||
{ on = [ "j" ], exec = "arrow 1", desc = "Move cursor down" },
|
||||
|
||||
{ on = [ "K" ], exec = "arrow -5", desc = "Move cursor up 5 lines" },
|
||||
{ on = [ "J" ], exec = "arrow 5", desc = "Move cursor down 5 lines" },
|
||||
|
||||
{ on = [ "<Up>" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||
{ on = [ "<Down>" ], exec = "arrow 1", desc = "Move cursor down" },
|
||||
|
||||
# Filtering
|
||||
{ on = [ "/" ], exec = "filter", desc = "Apply a filter for the help items" },
|
||||
]
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ pub struct Keymap {
|
|||
pub tasks: Vec<Control>,
|
||||
pub select: Vec<Control>,
|
||||
pub input: Vec<Control>,
|
||||
pub help: Vec<Control>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
|
|
@ -24,6 +25,7 @@ pub enum KeymapLayer {
|
|||
Tasks,
|
||||
Select,
|
||||
Input,
|
||||
Help,
|
||||
Which,
|
||||
}
|
||||
|
||||
|
|
@ -38,6 +40,7 @@ impl<'de> Deserialize<'de> for Keymap {
|
|||
tasks: Inner,
|
||||
select: Inner,
|
||||
input: Inner,
|
||||
help: Inner,
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
struct Inner {
|
||||
|
|
@ -50,6 +53,7 @@ impl<'de> Deserialize<'de> for Keymap {
|
|||
tasks: shadow.tasks.keymap,
|
||||
select: shadow.select.keymap,
|
||||
input: shadow.input.keymap,
|
||||
help: shadow.help.keymap,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -66,6 +70,7 @@ impl Keymap {
|
|||
KeymapLayer::Tasks => &self.tasks,
|
||||
KeymapLayer::Select => &self.select,
|
||||
KeymapLayer::Input => &self.input,
|
||||
KeymapLayer::Help => &self.help,
|
||||
KeymapLayer::Which => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
76
core/src/help/help.rs
Normal file
76
core/src/help/help.rs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
use config::{keymap::{Control, KeymapLayer}, KEYMAP};
|
||||
use shared::Term;
|
||||
|
||||
use super::HELP_MARGIN;
|
||||
use crate::emit;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Help {
|
||||
pub visible: bool,
|
||||
bindings: Vec<Control>,
|
||||
|
||||
offset: usize,
|
||||
cursor: usize,
|
||||
}
|
||||
|
||||
impl Help {
|
||||
#[inline]
|
||||
pub fn limit() -> usize { Term::size().rows.saturating_sub(HELP_MARGIN) as usize }
|
||||
|
||||
pub fn toggle(&mut self, layer: KeymapLayer) -> bool {
|
||||
self.visible = !self.visible;
|
||||
self.bindings = if self.visible { KEYMAP.get(layer).clone() } else { Vec::new() };
|
||||
|
||||
emit!(Peek); // Show/hide preview for images
|
||||
true
|
||||
}
|
||||
|
||||
pub fn escape(&mut self) -> bool { todo!() }
|
||||
|
||||
#[inline]
|
||||
pub fn arrow(&mut self, step: isize) -> bool {
|
||||
if step > 0 { self.next(step as usize) } else { self.prev(step.unsigned_abs()) }
|
||||
}
|
||||
|
||||
pub fn next(&mut self, step: usize) -> bool {
|
||||
let len = self.bindings.len();
|
||||
if len == 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
let old = self.cursor;
|
||||
self.cursor = (self.cursor + step).min(len - 1);
|
||||
|
||||
let limit = Self::limit();
|
||||
if self.cursor >= (self.offset + limit).min(len).saturating_sub(5) {
|
||||
self.offset = len.saturating_sub(limit).min(self.offset + self.cursor - old);
|
||||
}
|
||||
|
||||
old != self.cursor
|
||||
}
|
||||
|
||||
pub fn prev(&mut self, step: usize) -> bool {
|
||||
let old = self.cursor;
|
||||
self.cursor = self.cursor.saturating_sub(step);
|
||||
|
||||
if self.cursor < self.offset + 5 {
|
||||
self.offset = self.offset.saturating_sub(old - self.cursor);
|
||||
}
|
||||
|
||||
old != self.cursor
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn window(&self) -> &[Control] {
|
||||
let end = (self.offset + Self::limit()).min(self.bindings.len());
|
||||
&self.bindings[self.offset..end]
|
||||
}
|
||||
|
||||
pub fn filter(&mut self) -> bool { todo!() }
|
||||
}
|
||||
|
||||
impl Help {
|
||||
// --- Cursor
|
||||
#[inline]
|
||||
pub fn rel_cursor(&self) -> usize { self.cursor - self.offset }
|
||||
}
|
||||
5
core/src/help/mod.rs
Normal file
5
core/src/help/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
mod help;
|
||||
|
||||
pub use help::*;
|
||||
|
||||
pub const HELP_MARGIN: u16 = 1;
|
||||
|
|
@ -10,6 +10,7 @@ mod blocker;
|
|||
mod event;
|
||||
pub mod external;
|
||||
pub mod files;
|
||||
pub mod help;
|
||||
mod highlighter;
|
||||
pub mod input;
|
||||
pub mod manager;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue