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]]
name = "xplr"
version = "0.2.12"
version = "0.2.13"
dependencies = [
"anyhow",
"criterion",

@ -1,6 +1,6 @@
[package]
name = "xplr"
version = "0.2.12" # Update app.rs
version = "0.2.13" # Update app.rs
authors = ["Arijit Basu <sayanarijit@gmail.com>"]
edition = "2018"
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::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";

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

@ -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