rabite0 / hunter

The fastest file manager in the galaxy!
Do What The F*ck You Want To Public License
1.32k stars 64 forks source link

Help menu #82

Open blargg opened 4 years ago

blargg commented 4 years ago

Initial commit, for review and comment. This adds a new key binding ('H' by default) for a help menu. Pressing the key generates a list of the program's current key bindings and pipes it into the pager program ($PAGER or defaults to "less").

I think we can also add information like the current program version and a description of the program to this menu, but wanted feedback on the implementation and direction first.

rabite0 commented 4 years ago

Sorry for the late reply, I quite like it and this has been a long requested feature. Using $PAGER for makes a lot of sense since the text widget is so bare bones... It's a good idea actually.

If you're still interested in working on this it would be great if you could add the default binding to the keys config file stored in config.tar.gz, too. It's easy to miss, but the default bindings in keybind.rs are completely ignored when hunter finds a ~/.config/hunter/keys instead of being merged with them. Not sure what I was thinking to be honest, but oh well.

I think we can also add information like the current program version and a description of the program to this menu

Maybe a link to the github repo and to the irc channel, too. Other than that I'd be happy to merge your changes as is.

EDIT: I'm currently improving the text widget (or rather just hooking up the key bindings), so maybe you could use that instead of relying on $PAGER? it still lacks a search feature, but on the other hand it would allow for some fomatting/coloring by just feeding it a string with the right ANSI escape codes. I think less handles this correctly with the right flags, but not all pagers do and I'm not sure how portable it is.

To get it to work you'd need to:

  1. Create a TextView. You can take the WidgetCore from FileBrowser to get the correct dimensions.
  2. Feed it the text with .set_text() or .set_lines().
  3. Call .popup() to make it run in the foreground.

For the actual color codes you can just use the stuff in term.rs. I'm not sure it's actually worth it, I'm just fond of colors personally ;).

blargg commented 4 years ago

I should be able to at least add the help text and the keys to keybinding updates.

Time permitting, I'll look into using the actual text widget. Otherwise, I might leave that as a future improvement.

rabite0 commented 4 years ago

No worries. Thanks for your work!

blargg commented 4 years ago

I updated the help text and add the keys to the config. It still uses pager. Is there a way to go from the file manager widget to the text view widget and then go back? I couldn't find a clean way to do this.

rabite0 commented 4 years ago

Ohh... right, totally forgot about that. No, there isn't, at least not directly. The kind of bindings and such are completely static at the moment, so there's no way to make one particular widget instance behave differently from any other, or have more types of actions it can handle, other than creating a whole new type.

So to actually do that you'd have to create a "HelpView" that contains the TextView and just passes on all the calls refresh(), get_drawlist() and some other methods from the Widget trait. Then this HelpView would watch for the binding that closes it (conventionally the same key that opened it). That requires implementing the Acting trait which defines the actions and where to look for the bindings. A good example would be the at the end in file_browser.rs. It just calls the appropriate methods on self.columns one way or another and in on_key() it tries to handle the key or passes it on until it's handled by a child widget (or not).

I can understand if you don't feel like doing it, I'd be happy to merge your changes as is, too.

blargg commented 4 years ago

Let's merge the changes as they currently are. It's mostly lack of time right now.

Thank you for your help on this!