Add support for un-mapping keys.

Use `remaps: {key: null}` to un-map a key.

Also,
- `gx` will now open only the file under focus.
- `:sx` will open the selected files.

And other minor improvements.

Discussion: https://github.com/sayanarijit/xplr/discussions/146
pull/148/head v0.9
Arijit Basu 3 years ago committed by Arijit Basu
parent 57a0a49aae
commit 8e98da5004

2
Cargo.lock generated

@ -1193,7 +1193,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "xplr"
version = "0.9.0"
version = "0.9.1"
dependencies = [
"anyhow",
"chrono",

@ -1,6 +1,6 @@
[package]
name = "xplr"
version = "0.9.0" # Update config.yml, config.rs
version = "0.9.1" # Update config.yml, config.rs
authors = ["Arijit Basu <sayanarijit@gmail.com>"]
edition = "2018"
description = "A hackable, minimal, fast TUI file explorer"

@ -1686,10 +1686,9 @@ impl App {
let key_str = key.to_string();
let default = kb.default().clone();
let msgs = kb
.remaps()
.on_key()
.get(&key_str)
.and_then(|k| kb.on_key().get(k))
.or_else(|| kb.on_key().get(&key_str))
.to_owned()
.map(|a| Some(a.messages().clone()))
.unwrap_or_else(|| {
if key.is_alphabet() {
@ -2522,7 +2521,7 @@ impl App {
.key_bindings()
.remaps()
.iter()
.filter(|(_, t)| t == &k)
.filter(|(_, maybeto)| maybeto.as_ref().map(|to| to == k).unwrap_or(false))
.map(|(f, _)| f.clone())
.collect::<Vec<String>>()
.join(", ");

@ -9,6 +9,7 @@ use crate::ui::Constraint;
use crate::ui::Layout;
use crate::ui::Style;
use anyhow::Result;
use indexmap::IndexMap;
use indexmap::IndexSet;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
@ -649,7 +650,7 @@ impl GeneralConfig {
#[serde(deny_unknown_fields)]
pub struct KeyBindings {
#[serde(default)]
remaps: BTreeMap<String, String>,
remaps: IndexMap<String, Option<String>>,
#[serde(default)]
on_key: BTreeMap<String, Action>,
@ -682,13 +683,22 @@ impl KeyBindings {
.on_special_character
.and_then(|a| a.sanitized(read_only));
self.default = self.default.and_then(|a| a.sanitized(read_only));
self.remaps = self
.remaps
.clone()
.into_iter()
.filter(|(_, v)| self.on_key.contains_key(v))
.collect();
};
let mut remaps = IndexMap::new();
for (from, maybe_to) in self.remaps.into_iter() {
if let Some(to) = maybe_to.as_ref() {
let mapped = self.on_key.get(to).cloned();
if let Some(a) = mapped {
self.on_key.insert(from.clone(), a.clone());
remaps.insert(from, maybe_to);
}
} else {
self.on_key.remove(&from);
}
}
self.remaps = remaps;
self
}
@ -703,7 +713,7 @@ impl KeyBindings {
}
/// Get a reference to the key bindings's remaps.
pub fn remaps(&self) -> &BTreeMap<String, String> {
pub fn remaps(&self) -> &IndexMap<String, Option<String>> {
&self.remaps
}
@ -784,7 +794,17 @@ impl Mode {
self.key_bindings
.on_key
.iter()
.filter(|(k, _)| !self.key_bindings.remaps.contains_key(&k.to_string()))
.filter(|(k, v)| {
!self
.key_bindings
.remaps
.get(*k)
.and_then(|mt| {
mt.as_ref()
.map(|t| self.key_bindings.on_key.get(t) == Some(v))
})
.unwrap_or(false)
})
.filter_map(|(k, a)| {
a.help.clone().map(|h| HelpMenuLine::KeyMap(k.into(), h))
}),
@ -1255,6 +1275,7 @@ impl Config {
pub fn is_compatible(&self) -> Result<bool> {
let result = match self.parsed_version()? {
(0, 9, 1) => true,
(0, 9, 0) => true,
(_, _, _) => false,
};
@ -1264,7 +1285,8 @@ impl Config {
pub fn upgrade_notification(&self) -> Result<Option<&str>> {
let result = match self.parsed_version()? {
(0, 9, 0) => None,
(0, 9, 1) => None,
(0, 9, 0) => Some("App version updated. Improved remap feature"),
(_, _, _) => None,
};

@ -1,4 +1,4 @@
version: v0.9.0
version: v0.9.1
layouts:
custom: {}
builtin:
@ -139,7 +139,7 @@ general:
- format: ├─
- format: ├─
- format: ╰─
col_spacing: 0
col_spacing: 1
col_widths:
- Percentage: 10
- Percentage: 50
@ -361,6 +361,26 @@ modes:
read -p "[enter to continue]"
- PopMode
- Refresh
x:
help: open in gui
messages:
- BashExecSilently: |
if [ -z "$OPENER" ]; then
if command -v xdg-open; then
OPENER=xdg-open
elif command -v open; then
OPENER=open
else
echo 'LogError: $OPENER not found' >> "${XPLR_PIPE_MSG_IN:?}"
exit 1
fi
fi
(while IFS= read -r line; do
$OPENER "${line:?}" > /dev/null 2>&1
done < "${XPLR_PIPE_RESULT_OUT:?}")
- ClearScreen
- PopMode
- Refresh
ctrl-c:
help: terminate
messages:
@ -841,7 +861,8 @@ modes:
help: global help menu
messages:
- BashExec: |
cat -- "${XPLR_PIPE_GLOBAL_HELP_MENU_OUT}" | ${PAGER:-less}
[ -z "$PAGER" ] && PAGER="less -+F"
cat -- "${XPLR_PIPE_GLOBAL_HELP_MENU_OUT}" | ${PAGER:?}
'~':
help: go home
messages:
@ -866,6 +887,7 @@ modes:
help: switch layout
messages:
- SwitchModeBuiltin: switch_layout
- Refresh
d:
help: delete
messages:
@ -884,7 +906,7 @@ modes:
help: go to
messages:
- PopMode
- SwitchModeBuiltin: go to
- SwitchModeBuiltin: go_to
- Refresh
left:
help: back
@ -999,9 +1021,7 @@ modes:
exit 1
fi
fi
(while IFS= read -r line; do
$OPENER "${line:?}" &> /dev/null &
done < "${XPLR_PIPE_RESULT_OUT:?}")
$OPENER "${XPLR_FOCUS_PATH:?}" > /dev/null 2>&1
- ClearScreen
- PopMode
- Refresh
@ -1167,7 +1187,8 @@ modes:
help: logs
messages:
- BashExec: |
cat -- "${XPLR_PIPE_LOGS_OUT}" | ${PAGER:-less}
[ -z "$PAGER" ] && PAGER="less -+F"
cat -- "${XPLR_PIPE_LOGS_OUT}" | ${PAGER:?}
- PopMode
- Refresh
ctrl-c:

@ -659,7 +659,7 @@ fn draw_help_menu<B: Backend>(
.key_bindings()
.remaps()
.iter()
.filter(|(_, t)| t == &&k)
.filter(|(_, maybeto)| maybeto.as_ref().map(|to| to == &k).unwrap_or(false))
.map(|(f, _)| f.clone())
.collect::<Vec<String>>()
.join("|");

Loading…
Cancel
Save