Saner key bindings

pull/3/head
Arijit Basu 3 years ago
parent c0ca596539
commit 7cbb9d2baf
No known key found for this signature in database
GPG Key ID: 7D7BF809E7378863

2
Cargo.lock generated

@ -1123,7 +1123,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "xplr" name = "xplr"
version = "0.2.12" version = "0.2.13"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"criterion", "criterion",

@ -1,6 +1,6 @@
[package] [package]
name = "xplr" name = "xplr"
version = "0.2.12" # Update app.rs version = "0.2.13" # Update app.rs
authors = ["Arijit Basu <sayanarijit@gmail.com>"] authors = ["Arijit Basu <sayanarijit@gmail.com>"]
edition = "2018" edition = "2018"
description = "An experimental, minimal, configurable TUI file explorer, stealing ideas from nnn and fzf." description = "An experimental, minimal, configurable TUI file explorer, stealing ideas from nnn and fzf."

@ -13,7 +13,7 @@ use std::fs;
use std::io; use std::io;
use std::path::PathBuf; use std::path::PathBuf;
pub const VERSION: &str = "v0.2.12"; // Update Cargo.toml pub const VERSION: &str = "v0.2.13"; // Update Cargo.toml
pub const TEMPLATE_TABLE_ROW: &str = "TEMPLATE_TABLE_ROW"; pub const TEMPLATE_TABLE_ROW: &str = "TEMPLATE_TABLE_ROW";

@ -245,50 +245,72 @@ impl Default for KeyBindings {
let on_key: BTreeMap<String, Action> = serde_yaml::from_str( let on_key: BTreeMap<String, Action> = serde_yaml::from_str(
r###" r###"
up: up:
help: up help: up [k]
messages:
- FocusPrevious
k:
messages: messages:
- FocusPrevious - FocusPrevious
down: down:
help: down help: down [j]
messages:
- FocusNext
j:
messages: messages:
- FocusNext - FocusNext
right: right:
help: enter help: enter [l]
messages:
- Enter
l:
messages: messages:
- Enter - Enter
left: left:
help: back help: back [h]
messages:
- Back
h:
messages: messages:
- Back - Back
g: g:
help: go to help: go to
messages: messages:
- SwitchMode: goto - SwitchMode: go to
G: G:
help: bottom help: go to bottom
messages: messages:
- FocusLast - FocusLast
s: ctrl-f:
help: shell help: search [/]
messages: messages:
- Call: - Call:
command: bash command: bash
args: [] args:
- Explore - -c
- |
PTH=$(echo -e "${XPLR_DIRECTORY_NODES:?}" | fzf)
if [ -d "$PTH" ]; then
echo "ChangeDirectory: ${PTH:?}" >> "${XPLR_PIPE_MSG_IN:?}"
elif [ -f "$PTH" ]; then
echo "FocusPath: ${PTH:?}" >> "${XPLR_PIPE_MSG_IN:?}"
fi
/: /:
help: search
messages: messages:
- Call: - Call:
command: bash command: bash
args: args:
- "-c" - -c
- | - |
PTH=$(echo -e "${XPLR_DIRECTORY_NODES:?}" | fzf) PTH=$(echo -e "${XPLR_DIRECTORY_NODES:?}" | fzf)
if [ -d "$PTH" ]; then if [ -d "$PTH" ]; then
@ -297,89 +319,46 @@ impl Default for KeyBindings {
echo "FocusPath: ${PTH:?}" >> "${XPLR_PIPE_MSG_IN:?}" echo "FocusPath: ${PTH:?}" >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
space:
help: toggle selection
messages:
- ToggleSelection
- FocusNext
n:
help: create new
messages:
- SwitchMode: create
d: d:
help: delete help: delete
messages: messages:
- SwitchMode: delete - SwitchMode: delete
c: ":":
help: copy here help: action
messages: messages:
- Call: - SwitchMode: action
command: bash
args:
- -c
- |
while IFS= read -r line; do
cp -v "${line:?}" ./
done <<< "${XPLR_SELECTION:?}"
read -p "[enter to continue]"
- ClearSelection
- Explore
m:
help: move here
messages:
- Call:
command: bash
args:
- -c
- |
while IFS= read -r line; do
mv -v "${line:?}" ./
done <<< "${XPLR_SELECTION:?}"
read -p "[enter to continue]"
- Explore
enter: space:
help: quit with result help: toggle selection [v]
messages: messages:
- PrintResultAndQuit - ToggleSelection
- FocusNext
o: v:
help: open
messages: messages:
- Call: - ToggleSelection
command: bash - FocusNext
args:
- -c
- |
xdg-open "${XPLR_FOCUS_PATH:?}" &> /dev/null
ctrl-l: enter:
help: clear help: quit with result
messages: messages:
- ClearScreen - PrintResultAndQuit
- Refresh
"#": "#":
help: quit with debug
messages: messages:
- PrintAppStateAndQuit - PrintAppStateAndQuit
esc: ctrl-c:
help: cancel & quit help: cancel & quit [q|esc]
messages: messages:
- Terminate - Terminate
q: q:
help: cancel & quit
messages: messages:
- Terminate - Terminate
ctrl-c: esc:
help: cancel & quit
messages: messages:
- Terminate - Terminate
"###, "###,
@ -461,6 +440,104 @@ impl Default for Config {
- FocusFirst - FocusFirst
- SwitchMode: default - SwitchMode: default
x:
help: open in gui
messages:
- Call:
command: bash
args:
- -c
- |
xdg-open "${XPLR_FOCUS_PATH:?}" &> /dev/null
- SwitchMode: default
ctrl-c:
help: cancel & quit
messages:
- Terminate
default:
messages:
- SwitchMode: default
"###,
)
.unwrap();
let action_mode: Mode = serde_yaml::from_str(
r###"
name: action to
key_bindings:
on_key:
"!":
help: shell
messages:
- Call:
command: bash
- Explore
- SwitchMode: default
n:
help: create new
messages:
- SwitchMode: create
s:
help: selection operations
messages:
- SwitchMode: selection ops
ctrl-c:
help: cancel & quit [q]
messages:
- Terminate
q:
messages:
- Terminate
default:
messages:
- SwitchMode: default
"###,
)
.unwrap();
let selection_ops_mode: Mode = serde_yaml::from_str(
r###"
name: selection ops
key_bindings:
on_key:
c:
help: copy here
messages:
- Call:
command: bash
args:
- -c
- |
while IFS= read -r line; do
cp -v "${line:?}" ./
done <<< "${XPLR_SELECTION:?}"
read -p "[enter to continue]"
- ClearSelection
- Explore
- SwitchMode: default
m:
help: move here
messages:
- Call:
command: bash
args:
- -c
- |
while IFS= read -r line; do
mv -v "${line:?}" ./
done <<< "${XPLR_SELECTION:?}"
read -p "[enter to continue]"
- Explore
- SwitchMode: default
ctrl-c: ctrl-c:
help: cancel & quit help: cancel & quit
messages: messages:
@ -479,14 +556,26 @@ impl Default for Config {
key_bindings: key_bindings:
on_key: on_key:
up: up:
help: go up help: to up [k]
messages:
- FocusPreviousByRelativeIndexFromInput
- ResetInputBuffer
- SwitchMode: default
k:
messages: messages:
- FocusPreviousByRelativeIndexFromInput - FocusPreviousByRelativeIndexFromInput
- ResetInputBuffer - ResetInputBuffer
- SwitchMode: default - SwitchMode: default
down: down:
help: go down help: to down [j]
messages:
- FocusNextByRelativeIndexFromInput
- ResetInputBuffer
- SwitchMode: default
j:
messages: messages:
- FocusNextByRelativeIndexFromInput - FocusNextByRelativeIndexFromInput
- ResetInputBuffer - ResetInputBuffer
@ -617,10 +706,12 @@ impl Default for Config {
let mut modes: HashMap<String, Mode> = Default::default(); let mut modes: HashMap<String, Mode> = Default::default();
modes.insert("default".into(), Mode::default()); modes.insert("default".into(), Mode::default());
modes.insert("goto".into(), goto_mode); modes.insert("go to".into(), goto_mode);
modes.insert("number".into(), number_mode); modes.insert("number".into(), number_mode);
modes.insert("create".into(), create_mode); modes.insert("create".into(), create_mode);
modes.insert("delete".into(), delete_mode); modes.insert("delete".into(), delete_mode);
modes.insert("action".into(), action_mode);
modes.insert("selection ops".into(), selection_ops_mode);
Self { Self {
version: VERSION.into(), version: VERSION.into(),

@ -353,7 +353,7 @@ fn draw_help_menu<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, _: &
.borders(Borders::ALL) .borders(Borders::ALL)
.title(format!(" Help [{}] ", &mode.name)), .title(format!(" Help [{}] ", &mode.name)),
) )
.widths(&[TUIConstraint::Percentage(40), TUIConstraint::Percentage(60)]); .widths(&[TUIConstraint::Percentage(30), TUIConstraint::Percentage(70)]);
f.render_widget(help_menu, rect); f.render_widget(help_menu, rect);
} }

@ -1,16 +0,0 @@
use xplr::*;
#[test]
fn test_key_down() {
let mut app = app::App::create().expect("failed to create app");
assert_eq!(app.focus(), Some(0));
let actions = app.actions_from_key(&input::Key::Down).unwrap();
for action in actions {
app = app.handle(&action).unwrap()
}
assert_eq!(app.directory_buffer.focus, Some(1));
}
Loading…
Cancel
Save