Add help screen on keybinds

This commit is contained in:
Arun Prakash Jana 2017-04-03 22:33:46 +05:30
parent 418c9f2654
commit 4b66029762
No known key found for this signature in database
GPG key ID: A75979F35C080412
5 changed files with 126 additions and 71 deletions

View file

@ -1,5 +1,6 @@
Copyright (c) 2014-2016 Lazaros Koromilas <lostd@2f30.org> Copyright (c) 2014-2016 Lazaros Koromilas <lostd@2f30.org>
Copyright (c) 2014-2016 Dimitris Papastamos <sin@2f30.org> Copyright (c) 2014-2016 Dimitris Papastamos <sin@2f30.org>
Copyright (c) 2016-2017 Arun Prakash Jana <engineerarun@gmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View file

@ -109,29 +109,30 @@ Start nnn (default: current directory):
| Key | Function | | Key | Function |
| --- | --- | | --- | --- |
| `Up`, `k`, `^P` | previous entry | | `Up`, `k`, `^P` | Previous entry |
| `Down`, `j`, `^N` | next entry | | `Down`, `j`, `^N` | Next entry |
| `PgUp`, `^U` | scroll half page up | | `PgUp`, `^U` | Scroll half page up |
| `PgDn`, `^D` | scroll half page down | | `PgDn`, `^D` | Scroll half page down |
| `Home`, `^`, `^A` | jump to first dir entry | | `Home`, `^`, `^A` | Jump to first dir entry |
| `End`, `$`, `^E` | jump to last dir entry | | `End`, `$`, `^E` | Jump to last dir entry |
| `Right`, `Enter`, `l`, `^M` | open file or enter dir | | `Right`, `Enter`, `l`, `^M` | Open file or enter dir |
| `Left`, `Backspace`, `h`, `^H` | parent dir | | `Left`, `Backspace`, `h`, `^H` | Go to parent dir |
| `~` | jump to home dir | | `~` | Jump to HOME dir |
| `/`, `&` | filter dir contents | | `/`, `&` | Filter dir contents |
| `c` | show change dir prompt | | `c` | Show change dir prompt |
| `d` | toggle detail view | | `d` | Toggle detail view |
| `D` | show details of selected file | | `D` | Show details of selected file |
| `.` | toggle hide dot files | | `.` | Toggle hide .dot files |
| `s` | toggle sort by file size | | `s` | Toggle sort by file size |
| `t` | toggle sort by modified time | | `t` | Toggle sort by modified time |
| `!` | spawn `SHELL` in `PWD` (fallback sh) | | `!` | Spawn `SHELL` in `PWD` (fallback sh) |
| `z` | run `top` | | `z` | Run `top` |
| `e` | edit entry in `EDITOR` (fallback vi) | | `e` | Edit entry in `EDITOR` (fallback vi) |
| `p` | open entry with `PAGER` (fallback less) | | `p` | Open entry in `PAGER` (fallback less) |
| `^K` | invoke file name copier | | `^K` | Invoke file name copier |
| `^L` | redraw window | | `^L` | Force a redraw |
| `q` | quit | | `?` | Show help |
| `q` | Quit |
### Filters ### Filters

View file

@ -23,60 +23,62 @@ struct assoc assocs[] = {
struct key bindings[] = { struct key bindings[] = {
/* Quit */ /* Quit */
{ 'q', SEL_QUIT, "\0", "\0" }, { 'q', SEL_QUIT, "", "" },
/* Back */ /* Back */
{ KEY_BACKSPACE, SEL_BACK, "\0", "\0" }, { KEY_BACKSPACE, SEL_BACK, "", "" },
{ KEY_LEFT, SEL_BACK, "\0", "\0" }, { KEY_LEFT, SEL_BACK, "", "" },
{ 'h', SEL_BACK, "\0", "\0" }, { 'h', SEL_BACK, "", "" },
{ CONTROL('H'), SEL_BACK, "\0", "\0" }, { CONTROL('H'), SEL_BACK, "", "" },
/* Inside */ /* Inside */
{ KEY_ENTER, SEL_GOIN, "\0", "\0" }, { KEY_ENTER, SEL_GOIN, "", "" },
{ '\r', SEL_GOIN, "\0", "\0" }, { '\r', SEL_GOIN, "", "" },
{ KEY_RIGHT, SEL_GOIN, "\0", "\0" }, { KEY_RIGHT, SEL_GOIN, "", "" },
{ 'l', SEL_GOIN, "\0", "\0" }, { 'l', SEL_GOIN, "", "" },
/* Filter */ /* Filter */
{ '/', SEL_FLTR, "\0", "\0" }, { '/', SEL_FLTR, "", "" },
{ '&', SEL_FLTR, "\0", "\0" }, { '&', SEL_FLTR, "", "" },
/* Next */ /* Next */
{ 'j', SEL_NEXT, "\0", "\0" }, { 'j', SEL_NEXT, "", "" },
{ KEY_DOWN, SEL_NEXT, "\0", "\0" }, { KEY_DOWN, SEL_NEXT, "", "" },
{ CONTROL('N'), SEL_NEXT, "\0", "\0" }, { CONTROL('N'), SEL_NEXT, "", "" },
/* Previous */ /* Previous */
{ 'k', SEL_PREV, "\0", "\0" }, { 'k', SEL_PREV, "", "" },
{ KEY_UP, SEL_PREV, "\0", "\0" }, { KEY_UP, SEL_PREV, "", "" },
{ CONTROL('P'), SEL_PREV, "\0", "\0" }, { CONTROL('P'), SEL_PREV, "", "" },
/* Page down */ /* Page down */
{ KEY_NPAGE, SEL_PGDN, "\0", "\0" }, { KEY_NPAGE, SEL_PGDN, "", "" },
{ CONTROL('D'), SEL_PGDN, "\0", "\0" }, { CONTROL('D'), SEL_PGDN, "", "" },
/* Page up */ /* Page up */
{ KEY_PPAGE, SEL_PGUP, "\0", "\0" }, { KEY_PPAGE, SEL_PGUP, "", "" },
{ CONTROL('U'), SEL_PGUP, "\0", "\0" }, { CONTROL('U'), SEL_PGUP, "", "" },
/* Home */ /* Home */
{ KEY_HOME, SEL_HOME, "\0", "\0" }, { KEY_HOME, SEL_HOME, "", "" },
{ CONTROL('A'), SEL_HOME, "\0", "\0" }, { CONTROL('A'), SEL_HOME, "", "" },
{ '^', SEL_HOME, "\0", "\0" }, { '^', SEL_HOME, "", "" },
/* End */ /* End */
{ KEY_END, SEL_END, "\0", "\0" }, { KEY_END, SEL_END, "", "" },
{ CONTROL('E'), SEL_END, "\0", "\0" }, { CONTROL('E'), SEL_END, "", "" },
{ '$', SEL_END, "\0", "\0" }, { '$', SEL_END, "", "" },
/* Change dir */ /* Change dir */
{ 'c', SEL_CD, "\0", "\0" }, { 'c', SEL_CD, "", "" },
{ '~', SEL_CDHOME, "\0", "\0" }, { '~', SEL_CDHOME, "", "" },
/* Toggle hide .dot files */ /* Toggle hide .dot files */
{ '.', SEL_TOGGLEDOT, "\0", "\0" }, { '.', SEL_TOGGLEDOT, "", "" },
/* Detailed listing */ /* Detailed listing */
{ 'd', SEL_DETAIL, "\0", "\0" }, { 'd', SEL_DETAIL, "", "" },
/* File details */ /* File details */
{ 'D', SEL_STATS, "\0", "\0" }, { 'D', SEL_STATS, "", "" },
/* Toggle sort by size */ /* Toggle sort by size */
{ 's', SEL_FSIZE, "\0", "\0" }, { 's', SEL_FSIZE, "", "" },
/* Toggle sort by time */ /* Toggle sort by time */
{ 't', SEL_MTIME, "\0", "\0" }, { 't', SEL_MTIME, "", "" },
{ CONTROL('L'), SEL_REDRAW, "\0", "\0" }, { CONTROL('L'), SEL_REDRAW, "", "" },
/* Copy currently selected file path */ /* Copy currently selected file path */
{ CONTROL('K'), SEL_COPY, "\0", "\0" }, { CONTROL('K'), SEL_COPY, "", "" },
/* Show help */
{ '?', SEL_HELP, "", "" },
/* Run command */ /* Run command */
{ 'z', SEL_RUN, "top", "\0" }, { 'z', SEL_RUN, "top", "" },
{ '!', SEL_RUN, "sh", "SHELL" }, { '!', SEL_RUN, "sh", "SHELL" },
/* Run command with argument */ /* Run command with argument */
{ 'e', SEL_RUNARG, "vi", "EDITOR" }, { 'e', SEL_RUNARG, "vi", "EDITOR" },

24
nnn.1
View file

@ -22,25 +22,25 @@ supports both vi-like and emacs-like key bindings in the default
configuration. The default key bindings are listed below. configuration. The default key bindings are listed below.
.Pp .Pp
.Bl -tag -width "l, [Right], [Return] or C-mXXXX" -offset indent -compact .Bl -tag -width "l, [Right], [Return] or C-mXXXX" -offset indent -compact
.It Ic k, [Up] or C-p .It Ic [Up], k, ^P
Move to previous entry Move to previous entry
.It Ic j, [Down] or C-n .It Ic [Down], j, ^N
Move to next entry Move to next entry
.It Ic [Pgup] or C-u .It Ic [PgUp], ^U
Scroll up half a page Scroll up half a page
.It Ic [Pgdown] or C-d .It Ic [PgDn], ^D
Scroll down half a page Scroll down half a page
.It Ic [Home], ^ or C-a .It Ic [Home], ^, ^A
Move to the first entry Move to the first entry
.It Ic [End], $ or C-e .It Ic [End], $, ^E
Move to the last entry Move to the last entry
.It Ic l, [Right], [Return] or C-m .It Ic [Right], [Enter], l, ^M
Open file or enter directory Open file or enter directory
.It Ic h, C-h, [Left] or [Backspace] .It Ic [Left], [Backspace], h, ^H
Back up one directory level Back up one directory level
.It Ic ~ .It Ic ~
Change to the HOME directory Change to the HOME directory
.It Ic / or & .It Ic /, &
Change filter (more information below) Change filter (more information below)
.It Ic c .It Ic c
Change into the given directory Change into the given directory
@ -62,10 +62,12 @@ Run the system top utility.
Open current entry in EDITOR (fallback vi) Open current entry in EDITOR (fallback vi)
.It Ic p .It Ic p
Open current entry in PAGER (fallback less) Open current entry in PAGER (fallback less)
.It Ic C-k .It Ic ^K
Invoke file name copier Invoke file name copier
.It Ic C-l .It Ic ^L
Force a redraw Force a redraw
.It Ic \&?
Show help
.It Ic q .It Ic q
Quit Quit
.El .El

49
nnn.c
View file

@ -69,6 +69,7 @@ enum action {
SEL_MTIME, SEL_MTIME,
SEL_REDRAW, SEL_REDRAW,
SEL_COPY, SEL_COPY,
SEL_HELP,
SEL_RUN, SEL_RUN,
SEL_RUNARG, SEL_RUNARG,
}; };
@ -815,6 +816,48 @@ show_stats(char* fpath, char* fname, struct stat *sb)
return; return;
} }
void
show_help(void)
{
char c;
clear();
printw("\n\
<< Key >> << Function >>\n\n\
[Up], k, ^P Previous entry\n\
[Down], j, ^N Next entry\n\
[PgUp], ^U Scroll half page up\n\
[PgDn], ^D Scroll half page down\n\
[Home], ^, ^A Jump to first dir entry\n\
[End], $, ^E Jump to last dir entry\n\
[Right], [Enter], l, ^M Open file or enter dir\n\
[Left], [Backspace], h, ^H Go to parent dir\n\
~ Jump to HOME dir\n\
/, & Filter dir contents\n\
c Show change dir prompt\n\
d Toggle detail view\n\
D Show details of selected file\n\
. Toggle hide .dot files\n\
s Toggle sort by file size\n\
t Toggle sort by modified time\n\
! Spawn SHELL in PWD (fallback sh)\n\
z Run top\n\
e Edit entry in EDITOR (fallback vi)\n\
p Open entry in PAGER (fallback less)\n\
^K Invoke file name copier\n\
^L Force a redraw\n\
? Show help\n\
q Quit\n");
/* Show exit keys */
printw("\n\n << (q/Esc)");
while (c = getch())
if (c == 'q' || c == 27)
return;
}
static int static int
dentfill(char *path, struct entry **dents, dentfill(char *path, struct entry **dents,
int (*filter)(regex_t *, char *), regex_t *re) int (*filter)(regex_t *, char *), regex_t *re)
@ -1269,6 +1312,12 @@ nochange:
} else if (!copier) } else if (!copier)
printmsg("NNN_COPIER is not set"); printmsg("NNN_COPIER is not set");
goto nochange; goto nochange;
case SEL_HELP:
show_help();
/* Save current */
if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
goto begin;
case SEL_RUN: case SEL_RUN:
run = xgetenv(env, run); run = xgetenv(env, run);
exitcurses(); exitcurses();