summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/conf/format.rs9
-rw-r--r--src/display/displayable_tree.rs52
-rw-r--r--src/display/git_status_display.rs4
-rw-r--r--src/display/permissions.rs8
-rw-r--r--src/filesystems/mount_space_display.rs4
-rw-r--r--src/help/help_state.rs2
-rw-r--r--src/help/help_verbs.rs12
-rw-r--r--src/image/svg.rs6
-rw-r--r--src/keys.rs12
-rw-r--r--src/syntactic/syntaxer.rs8
-rw-r--r--src/verb/verb.rs15
12 files changed, 66 insertions, 67 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3bbfe5a..72ac0a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
### next
- better nushell integration (no need to quote arguments anymore, fix path extension broken by new version of nushell) - Thanks @stevenxxiu
+- don't show modal only keys in help page when modal mode isn't enabled
### v1.20.2 - 2023-02-19
<a name="v1.20.2"></a>
diff --git a/src/conf/format.rs b/src/conf/format.rs
index 4c57c95..c544560 100644
--- a/src/conf/format.rs
+++ b/src/conf/format.rs
@@ -13,8 +13,9 @@ use {
/// Formats usable for reading configuration files
-#[derive(PartialEq, Eq, Debug, Clone, Copy)]
+#[derive(Default, PartialEq, Eq, Debug, Clone, Copy)]
pub enum SerdeFormat {
+ #[default]
Hjson,
Toml,
}
@@ -68,9 +69,3 @@ impl SerdeFormat {
}
}
}
-
-impl Default for SerdeFormat {
- fn default() -> Self {
- SerdeFormat::Hjson
- }
-}
diff --git a/src/display/displayable_tree.rs b/src/display/displayable_tree.rs
index 6eda9c6..8abb636 100644
--- a/src/display/displayable_tree.rs
+++ b/src/display/displayable_tree.rs
@@ -98,9 +98,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
style
}
- fn write_line_count<'w, W: Write>(
+ fn write_line_count<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
line: &TreeLine,
count_len: usize,
selected: bool,
@@ -116,9 +116,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
}
#[cfg(unix)]
- fn write_line_device_id<'w, W: Write>(
+ fn write_line_device_id<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
line: &TreeLine,
selected: bool,
) -> Result<usize, termimad::Error> {
@@ -132,9 +132,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
Ok(0)
}
- fn write_line_selection_mark<'w, W: Write>(
+ fn write_line_selection_mark<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
style: &CompoundStyle,
selected: bool,
) -> Result<usize, termimad::Error> {
@@ -146,9 +146,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
})
}
- fn write_line_size<'w, W: Write>(
+ fn write_line_size<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
line: &TreeLine,
style: &CompoundStyle,
_selected: bool,
@@ -166,9 +166,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
/// only makes sense when there's only one level
/// (so in sort mode)
- fn write_line_size_with_bar<'w, W: Write>(
+ fn write_line_size_with_bar<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
line: &TreeLine,
label_style: &CompoundStyle,
total_size: FileSum,
@@ -192,9 +192,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
})
}
- fn write_line_git_status<'w, W: Write>(
+ fn write_line_git_status<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
line: &TreeLine,
selected: bool,
) -> Result<usize, termimad::Error> {
@@ -216,9 +216,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
Ok(0)
}
- fn write_date<'w, W: Write>(
+ fn write_date<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
seconds: i64,
selected: bool,
) -> Result<usize, termimad::Error> {
@@ -234,9 +234,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
Ok(1)
}
- fn write_branch<'w, W: Write>(
+ fn write_branch<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
line_index: usize,
line: &TreeLine,
selected: bool,
@@ -275,9 +275,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
}
/// write the symbol showing whether the path is staged
- fn write_line_stage_mark<'w, W: Write>(
+ fn write_line_stage_mark<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
style: &CompoundStyle,
staged: bool,
) -> Result<usize, termimad::Error> {
@@ -290,9 +290,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
}
/// write the name or subpath, depending on the pattern_object
- fn write_line_label<'w, W: Write>(
+ fn write_line_label<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
line: &TreeLine,
style: &CompoundStyle,
pattern_object: PatternObject,
@@ -367,9 +367,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
Ok(1)
}
- fn write_content_extract<'w, W: Write>(
+ fn write_content_extract<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
extract: ContentMatch,
selected: bool,
) -> Result<(), ProgramError> {
@@ -389,9 +389,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
Ok(())
}
- pub fn write_root_line<'w, W: Write>(
+ pub fn write_root_line<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
selected: bool,
) -> Result<(), ProgramError> {
cond_bg!(style, self, selected, self.skin.directory);
@@ -432,9 +432,9 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
}
/// if in app, extend the background till the end of screen row
- pub fn extend_line_bg<'w, W: Write>(
+ pub fn extend_line_bg<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
selected: bool,
) -> Result<(), ProgramError> {
if self.in_app && !cw.is_full() {
diff --git a/src/display/git_status_display.rs b/src/display/git_status_display.rs
index 77c287f..7bd5cf8 100644
--- a/src/display/git_status_display.rs
+++ b/src/display/git_status_display.rs
@@ -49,9 +49,9 @@ impl<'a, 's> GitStatusDisplay<'a, 's> {
}
}
- pub fn write<'w, W>(
+ pub fn write<W>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
selected: bool,
) -> Result<(), ProgramError>
where
diff --git a/src/display/permissions.rs b/src/display/permissions.rs
index b4c0ccc..241795d 100644
--- a/src/display/permissions.rs
+++ b/src/display/permissions.rs
@@ -39,9 +39,9 @@ impl<'s> PermWriter<'s> {
Self::new(skin, max_user_len, max_group_len)
}
- fn write_mode<'w, W: Write>(
+ fn write_mode<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
mode: Mode,
selected: bool,
) -> Result<(), termimad::Error> {
@@ -102,9 +102,9 @@ impl<'s> PermWriter<'s> {
}
#[cfg(not(any(target_family = "windows", target_os = "android")))]
- pub fn write_permissions<'w, W: Write>(
+ pub fn write_permissions<W: Write>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
line: &TreeLine,
selected: bool,
) -> Result<usize, ProgramError> {
diff --git a/src/filesystems/mount_space_display.rs b/src/filesystems/mount_space_display.rs
index be6c583..7563dc8 100644
--- a/src/filesystems/mount_space_display.rs
+++ b/src/filesystems/mount_space_display.rs
@@ -30,9 +30,9 @@ impl<'m, 's> MountSpaceDisplay<'m, 's> {
}
}
- pub fn write<'w, W>(
+ pub fn write<W>(
&self,
- cw: &mut CropWriter<'w, W>,
+ cw: &mut CropWriter<W>,
selected: bool,
) -> Result<(), ProgramError>
where
diff --git a/src/help/help_state.rs b/src/help/help_state.rs
index dbf4e5b..90fae28 100644
--- a/src/help/help_state.rs
+++ b/src/help/help_state.rs
@@ -141,7 +141,7 @@ impl PanelState for HelpState {
.sub("verb-rows")
.set_md("name", row.name())
.set_md("shortcut", row.shortcut())
- .set("key", &row.verb.keys_desc);
+ .set("key", &row.keys_desc);
if row.verb.description.code {
sub.set("description", "");
sub.set("execution", &row.verb.description.content);
diff --git a/src/help/help_verbs.rs b/src/help/help_verbs.rs
index db75531..2fe9b7a 100644
--- a/src/help/help_verbs.rs
+++ b/src/help/help_verbs.rs
@@ -1,6 +1,7 @@
use {
crate::{
app::AppContext,
+ keys,
pattern::*,
verb::*,
},
@@ -12,6 +13,7 @@ pub struct MatchingVerbRow<'v> {
name: Option<String>,
shortcut: Option<String>,
pub verb: &'v Verb,
+ pub keys_desc: String,
}
impl MatchingVerbRow<'_> {
@@ -68,9 +70,19 @@ pub fn matching_verb_rows<'v>(
continue;
}
}
+ let keys_desc = verb
+ .keys
+ .iter()
+ .filter(|&&k| {
+ con.modal || !keys::is_key_only_modal(k)
+ })
+ .map(|&k| keys::KEY_FORMAT.to_string(k))
+ .collect::<Vec<String>>() // no way to join an iterator today ?
+ .join(", ");
rows.push(MatchingVerbRow {
name,
shortcut,
+ keys_desc,
verb,
});
}
diff --git a/src/image/svg.rs b/src/image/svg.rs
index c2347a0..4176983 100644
--- a/src/image/svg.rs
+++ b/src/image/svg.rs
@@ -34,8 +34,10 @@ pub fn render<P: Into<PathBuf>>(
max_height: u32,
) -> Result<DynamicImage, SvgError> {
let path: PathBuf = path.into();
- let mut opt = usvg::Options::default();
- opt.resources_dir = Some(path.clone());
+ let opt = usvg::Options {
+ resources_dir: Some(path.clone()),
+ ..Default::default()
+ };
let mut fontdb = fontdb::Database::new();
fontdb.load_system_fonts();
let svg_data = std::fs::read(path)?;
diff --git a/src/keys.rs b/src/keys.rs
index 60cb392..fa5be5b 100644
--- a/src/keys.rs
+++ b/src/keys.rs
@@ -19,6 +19,13 @@ pub fn is_reserved(key: KeyEvent) -> bool {
key == key!(backspace) || key == key!(delete) || key == key!(esc)
}
+pub fn is_key_only_modal(
+ key: KeyEvent,
+) -> bool {
+ matches!(key, KeyEvent { code: KeyCode::Char(_), modifiers: KeyModifiers::NONE })
+ || matches!(key, KeyEvent { code: KeyCode::Char(_), modifiers: KeyModifiers::SHIFT })
+}
+
pub fn is_key_allowed_for_verb(
key: KeyEvent,
mode: Mode,
@@ -30,10 +37,7 @@ pub fn is_key_allowed_for_verb(
if key==key!(left) || key==key!(right) {
input_is_empty
} else {
- !(
- matches!(key, KeyEvent { code: KeyCode::Char(_), modifiers: KeyModifiers::NONE })
- || matches!(key, KeyEvent { code: KeyCode::Char(_), modifiers: KeyModifiers::SHIFT })
- )
+ !is_key_only_modal(key)
}
}
Mode::Command => true,
diff --git a/src/syntactic/syntaxer.rs b/src/syntactic/syntaxer.rs
index 8816bac..37d3e32 100644
--- a/src/syntactic/syntaxer.rs
+++ b/src/syntactic/syntaxer.rs
@@ -36,11 +36,11 @@ impl Syntaxer {
self.theme_set.themes.keys()
}
- pub fn highlighter_for<'s, 'p>(
- &'s self,
- path: &'p Path,
+ pub fn highlighter_for(
+ &self,
+ path: &Path,
con: &AppContext,
- ) -> Option<HighlightLines<'s>> {
+ ) -> Option<HighlightLines<'_>> {
path.extension()
.and_then(|e| e.to_str())
.and_then(|ext| self.syntax_set.find_syntax_by_extension(ext))
diff --git a/src/verb/verb.rs b/src/verb/verb.rs
index 55aba13..f3de14c 100644
--- a/src/verb/verb.rs
+++ b/src/verb/verb.rs
@@ -3,7 +3,6 @@ use {
crate::{
app::*,
errors::ConfError,
- keys::KEY_FORMAT,
path::PathAnchor,
},
crokey::crossterm::event::KeyEvent,
@@ -39,9 +38,6 @@ pub struct Verb {
/// key shortcuts
pub keys: Vec<KeyEvent>,
- /// description of the optional keyboard key(s) triggering that verb
- pub keys_desc: String,
-
/// how the input must be checked and interpreted
/// Can be empty if the verb is only called with a key shortcut.
pub invocation_parser: Option<InvocationParser>,
@@ -114,7 +110,6 @@ impl Verb {
Ok(Self {
names,
keys: Vec::new(),
- keys_desc: "".to_string(),
invocation_parser,
execution,
description,
@@ -127,24 +122,14 @@ impl Verb {
panels: Vec::new(),
})
}
- fn update_key_desc(&mut self) {
- self.keys_desc = self
- .keys
- .iter()
- .map(|&k| KEY_FORMAT.to_string(k))
- .collect::<Vec<String>>() // no way to join an iterator today ?
- .join(", ");
- }
pub fn with_key(mut self, key: KeyEvent) -> Self {
self.keys.push(key);
- self.update_key_desc();
self
}
pub fn add_keys(&mut self, keys: Vec<KeyEvent>) {
for key in keys {
self.keys.push(key);
}
- self.update_key_desc();
}
pub fn no_doc(mut self) -> Self {
self.show_in_doc = false;