Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help menu #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified config.tar.gz
Binary file not shown.
34 changes: 33 additions & 1 deletion src/file_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,37 @@ impl FileBrowser {
.log();
}

pub fn help_menu(&mut self) -> HResult<()> {
self.core.get_sender().send(Events::InputEnabled(false))?;
self.preview_widget().map(|preview| preview.cancel_animation()).log();
self.core.screen.suspend().log();

let pager_result = (|| {
let pager = std::env::var("PAGER").unwrap_or("less".into());
let mut pager_proc = std::process::Command::new(pager.as_str())
.stdin(std::process::Stdio::piped())
.spawn()?;
let pager_stdin = pager_proc.stdin.as_mut().unwrap();
writeln!(pager_stdin, "hunter version {}", env!("CARGO_PKG_VERSION"))?;
writeln!(pager_stdin, "github: https://github.com/rabite0/hunter")?;
writeln!(pager_stdin, "irc: #hunter @ Freenode https://webchat.freenode.net/#hunter")?;
writeln!(pager_stdin)?;
write!(pager_stdin, "{}", self.core.config().keybinds)?;
pager_proc.wait()
})();

self.core.screen.activate().log();
self.core.get_sender().send(Events::InputEnabled(true))?;

match pager_result {
Err(err) =>
self.core.show_status(&format!("Couldn't open help menu: {}", err)).log(),
Ok(_) => {}
}

Ok(())
}

pub fn quit_with_dir(&self) -> HResult<()> {
let cwd = self.cwd()?.clone().path;
let selected_file = self.selected_file()?;
Expand Down Expand Up @@ -1631,7 +1662,8 @@ impl Acting for FileBrowser {
ToggleColumns => self.toggle_colums(),
ZoomPreview => self.zoom_preview(),
// Tab implementation needs to call exec_cmd because ALL files are needed
ExecCmd => Err(HError::FileBrowserNeedTabFiles)?
ExecCmd => Err(HError::FileBrowserNeedTabFiles)?,
HelpMenu => self.help_menu()?,
}
Ok(())
}
Expand Down
96 changes: 83 additions & 13 deletions src/keybind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,74 @@ impl Default for KeyBinds {
}
}

impl Display for KeyBinds {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

writeln!(f, "[movement]")?;
display_group(f, &self.movement)?;
writeln!(f)?;

writeln!(f, "[filebrowser]")?;
display_group(f, &self.filebrowser)?;
writeln!(f)?;

writeln!(f, "[filelist]")?;
display_group(f, &self.filelist)?;
writeln!(f)?;

writeln!(f, "[tab]")?;
display_group(f, &self.tab)?;
writeln!(f)?;

writeln!(f, "[media]")?;
display_group(f, &self.media)?;
writeln!(f)?;

writeln!(f, "[bookmark]")?;
display_group(f, &self.bookmark)?;
writeln!(f)?;

writeln!(f, "[process]")?;
display_group(f, &self.process)?;
writeln!(f)?;

writeln!(f, "[minibuffer]")?;
display_group(f, &self.minibuffer)?;
writeln!(f)?;

writeln!(f, "[fold]")?;
display_group(f, &self.fold)?;
writeln!(f)?;

writeln!(f, "[log]")?;
display_group(f, &self.log)?;
writeln!(f)?;

writeln!(f, "[quickaction]")?;
display_group(f, &self.quickaction)?;
Ok(())
}
}

fn display_group<A>(f: &mut std::fmt::Formatter<'_>, bindings: &Bindings<A>) -> std::fmt::Result
where
A: Display + Ord
{
let mut by_action = std::collections::BTreeMap::new();
for (key, action) in bindings.0.iter() {
by_action.entry(action).or_insert(vec![]).push(key);
}

for (action, keys) in by_action {
let key_str = keys
.into_iter()
.map(|k| k.to_string())
.collect::<Vec<_>>()
.join(", ");
writeln!(f, "{} = {}", action, key_str)?;
}
Ok(())
}

impl KeyBinds {
pub fn load() -> HResult<KeyBinds> {
Expand Down Expand Up @@ -448,7 +516,7 @@ where



#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Movement {
Up(usize),
Down(usize),
Expand All @@ -462,7 +530,7 @@ pub enum Movement {



#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum FileBrowserAction {
LeftColumnDown,
LeftColumnUp,
Expand All @@ -482,12 +550,13 @@ pub enum FileBrowserAction {
RunSubshell,
ToggleColumns,
ZoomPreview,
ExecCmd
ExecCmd,
HelpMenu,
}



#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum FileListAction {
Search,
SearchNext,
Expand All @@ -508,7 +577,7 @@ pub enum FileListAction {



#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum TabAction {
NewTab,
CloseTab,
Expand All @@ -519,7 +588,7 @@ pub enum TabAction {



#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum MediaAction {
TogglePause,
ToggleMute,
Expand All @@ -529,7 +598,7 @@ pub enum MediaAction {



#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum BookmarkAction {
GotoLastCwd,
Goto(char),
Expand All @@ -538,7 +607,7 @@ pub enum BookmarkAction {



#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum ProcessAction {
Close,
Remove,
Expand All @@ -554,7 +623,7 @@ pub enum ProcessAction {



#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum MiniBufferAction {
InsertChar(char),
InsertTab(usize),
Expand All @@ -573,17 +642,17 @@ pub enum MiniBufferAction {
CursorToEnd
}

#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum FoldAction {
ToggleFold
}

#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum LogAction {
Close
}

#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug)]
#[derive(EnumString, EnumIter, Copy, Clone, Display, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum QuickActionAction {
Close,
SelectOrRun(char)
Expand Down Expand Up @@ -688,7 +757,8 @@ impl Default for Bindings<FileBrowserAction> {
RunSubshell => Char('z'),
ToggleColumns => Char('c'),
ZoomPreview => Char('C'),
ExecCmd => Char('!')
ExecCmd => Char('!'),
HelpMenu => Char('H'),
};

filebrowser.insert(key, action.as_default());
Expand Down