"Fossies" - the Fresh Open Source Software Archive

Member "nnn-4.2/src/nnn.h" (21 Jul 2021, 7117 Bytes) of package /linux/misc/nnn-v4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "nnn.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: v4.1.1_vs_v4.2.

    1 /*
    2  * BSD 2-Clause License
    3  *
    4  * Copyright (C) 2014-2016, Lazaros Koromilas <lostd@2f30.org>
    5  * Copyright (C) 2014-2016, Dimitris Papastamos <sin@2f30.org>
    6  * Copyright (C) 2016-2021, Arun Prakash Jana <engineerarun@gmail.com>
    7  * All rights reserved.
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions are met:
   11  *
   12  * * Redistributions of source code must retain the above copyright notice, this
   13  *   list of conditions and the following disclaimer.
   14  *
   15  * * Redistributions in binary form must reproduce the above copyright notice,
   16  *   this list of conditions and the following disclaimer in the documentation
   17  *   and/or other materials provided with the distribution.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   29  */
   30 
   31 #pragma once
   32 
   33 #include <curses.h>
   34 
   35 #define CONTROL(c) ((c) & 0x1f)
   36 
   37 #ifndef ESC
   38 #define ESC (27)
   39 #endif
   40 
   41 #ifndef DEL
   42 #define DEL (127)
   43 #endif
   44 
   45 /* Supported actions */
   46 enum action {
   47     SEL_BACK = 1,
   48     SEL_OPEN,
   49     SEL_NAV_IN,
   50     SEL_NEXT,
   51     SEL_PREV,
   52     SEL_PGDN,
   53     SEL_PGUP,
   54     SEL_CTRL_D,
   55     SEL_CTRL_U,
   56     SEL_HOME,
   57     SEL_END,
   58     SEL_FIRST,
   59     SEL_CDHOME,
   60     SEL_CDBEGIN,
   61     SEL_CDLAST,
   62     SEL_CDROOT,
   63     SEL_BOOKMARK,
   64     SEL_REMOTE,
   65     SEL_CYCLE,
   66     SEL_CYCLER,
   67     SEL_CTX1,
   68     SEL_CTX2,
   69     SEL_CTX3,
   70     SEL_CTX4,
   71 #ifdef CTX8
   72     SEL_CTX5,
   73     SEL_CTX6,
   74     SEL_CTX7,
   75     SEL_CTX8,
   76 #endif
   77     SEL_MARK,
   78     SEL_FLTR,
   79     SEL_MFLTR,
   80     SEL_HIDDEN,
   81     SEL_DETAIL,
   82     SEL_STATS,
   83     SEL_CHMODX,
   84     SEL_ARCHIVE,
   85     SEL_SORT,
   86     SEL_REDRAW,
   87     SEL_SEL,
   88     SEL_SELMUL,
   89     SEL_SELALL,
   90     SEL_SELINV,
   91     SEL_SELEDIT,
   92     SEL_CP,
   93     SEL_MV,
   94     SEL_CPMVAS,
   95     SEL_RM,
   96     SEL_OPENWITH,
   97     SEL_NEW,
   98     SEL_RENAME,
   99     SEL_RENAMEMUL,
  100     SEL_UMOUNT,
  101     SEL_HELP,
  102     SEL_AUTONEXT,
  103     SEL_EDIT,
  104     SEL_PLUGIN,
  105     SEL_SHELL,
  106     SEL_LAUNCH,
  107     SEL_PROMPT,
  108     SEL_LOCK,
  109     SEL_SESSIONS,
  110     SEL_EXPORT,
  111     SEL_TIMETYPE,
  112     SEL_QUITCTX,
  113     SEL_QUITCD,
  114     SEL_QUIT,
  115     SEL_QUITERR,
  116 #ifndef NOMOUSE
  117     SEL_CLICK,
  118 #endif
  119 };
  120 
  121 /* Associate a pressed key to an action */
  122 struct key {
  123     int sym;         /* Key pressed */
  124     enum action act; /* Action */
  125 };
  126 
  127 static struct key bindings[] = {
  128     /* Back */
  129     { KEY_LEFT,       SEL_BACK },
  130     { 'h',            SEL_BACK },
  131     /* Inside or select */
  132     { KEY_ENTER,      SEL_OPEN },
  133     { '\r',           SEL_OPEN },
  134     /* Pure navigate inside */
  135     { KEY_RIGHT,      SEL_NAV_IN },
  136     { 'l',            SEL_NAV_IN },
  137     /* Next */
  138     { 'j',            SEL_NEXT },
  139     { KEY_DOWN,       SEL_NEXT },
  140     /* Previous */
  141     { 'k',            SEL_PREV },
  142     { KEY_UP,         SEL_PREV },
  143     /* Page down */
  144     { KEY_NPAGE,      SEL_PGDN },
  145     /* Page up */
  146     { KEY_PPAGE,      SEL_PGUP },
  147     /* Ctrl+D */
  148     { CONTROL('D'),   SEL_CTRL_D },
  149     /* Ctrl+U */
  150     { CONTROL('U'),   SEL_CTRL_U },
  151     /* First entry */
  152     { KEY_HOME,       SEL_HOME },
  153     { 'g',            SEL_HOME },
  154     { CONTROL('A'),   SEL_HOME },
  155     /* Last entry */
  156     { KEY_END,        SEL_END },
  157     { 'G',            SEL_END },
  158     { CONTROL('E'),   SEL_END },
  159     /* Go to first file */
  160     { '\'',           SEL_FIRST },
  161     /* HOME */
  162     { '~',            SEL_CDHOME },
  163     /* Initial directory */
  164     { '@',            SEL_CDBEGIN },
  165     /* Last visited dir */
  166     { '-',            SEL_CDLAST },
  167     /* Go to / */
  168     { '`',            SEL_CDROOT },
  169     /* Leader key */
  170     { 'b',            SEL_BOOKMARK },
  171     { CONTROL('_'),   SEL_BOOKMARK },
  172     /* Connect to server over SSHFS */
  173     { 'c',            SEL_REMOTE },
  174     /* Cycle contexts in forward direction */
  175     { '\t',           SEL_CYCLE },
  176     /* Cycle contexts in reverse direction */
  177     { KEY_BTAB,       SEL_CYCLER },
  178     /* Go to/create context N */
  179     { '1',            SEL_CTX1 },
  180     { '2',            SEL_CTX2 },
  181     { '3',            SEL_CTX3 },
  182     { '4',            SEL_CTX4 },
  183 #ifdef CTX8
  184     { '5',            SEL_CTX5 },
  185     { '6',            SEL_CTX6 },
  186     { '7',            SEL_CTX7 },
  187     { '8',            SEL_CTX8 },
  188 #endif
  189     /* Mark a path to visit later */
  190     { ',',            SEL_MARK },
  191     /* Filter */
  192     { '/',            SEL_FLTR },
  193     /* Toggle filter mode */
  194     { CONTROL('N'),   SEL_MFLTR },
  195     /* Toggle hide .dot files */
  196     { '.',            SEL_HIDDEN },
  197     /* Detailed listing */
  198     { 'd',            SEL_DETAIL },
  199     /* File details */
  200     { 'f',            SEL_STATS },
  201     { CONTROL('F'),   SEL_STATS },
  202     /* Toggle executable status */
  203     { '*',            SEL_CHMODX },
  204     /* Create archive */
  205     { 'z',            SEL_ARCHIVE },
  206     /* Sort toggles */
  207     { 't',            SEL_SORT },
  208     { CONTROL('T'),   SEL_SORT },
  209     /* Redraw window */
  210     { CONTROL('L'),   SEL_REDRAW },
  211     /* Select current file path */
  212     { CONTROL('J'),   SEL_SEL },
  213     { ' ',            SEL_SEL },
  214     /* Toggle select multiple files */
  215     { 'm',            SEL_SELMUL },
  216     /* Select all files in current dir */
  217     { 'a',            SEL_SELALL },
  218     /* Invert selection in current dir */
  219     { 'A',            SEL_SELINV },
  220     /* List, edit selection */
  221     { 'E',            SEL_SELEDIT },
  222     /* Copy from selection buffer */
  223     { 'p',            SEL_CP },
  224     { CONTROL('P'),   SEL_CP },
  225     /* Move from selection buffer */
  226     { 'v',            SEL_MV },
  227     { CONTROL('V'),   SEL_MV },
  228     /* Copy/move from selection buffer and rename */
  229     { 'w',            SEL_CPMVAS },
  230     { CONTROL('W'),   SEL_CPMVAS },
  231     /* Delete from selection buffer */
  232     { 'x',            SEL_RM },
  233     { CONTROL('X'),   SEL_RM },
  234     /* Open in a custom application */
  235     { 'o',            SEL_OPENWITH },
  236     { CONTROL('O'),   SEL_OPENWITH },
  237     /* Create a new file */
  238     { 'n',            SEL_NEW },
  239     /* Show rename prompt */
  240     { CONTROL('R'),   SEL_RENAME },
  241     /* Rename contents of current dir */
  242     { 'r',            SEL_RENAMEMUL },
  243     /* Disconnect a SSHFS mount point */
  244     { 'u',            SEL_UMOUNT },
  245     /* Show help */
  246     { '?',            SEL_HELP },
  247     /* Quit a context */
  248     { '+',            SEL_AUTONEXT },
  249     /* Edit in EDITOR */
  250     { 'e',            SEL_EDIT },
  251     /* Run a plugin */
  252     { ';',            SEL_PLUGIN },
  253     /* Run command */
  254     { '!',            SEL_SHELL },
  255     { CONTROL(']'),   SEL_SHELL },
  256     /* Launcher */
  257     { '=',            SEL_LAUNCH },
  258     /* Show command prompt */
  259     { ']',            SEL_PROMPT },
  260     /* Lock screen */
  261     { '0',            SEL_LOCK },
  262     /* Manage sessions */
  263     { 's',            SEL_SESSIONS },
  264     /* Export list */
  265     { '>',            SEL_EXPORT },
  266     /* Set time type */
  267     { 'T',            SEL_TIMETYPE },
  268     /* Quit a context */
  269     { 'q',            SEL_QUITCTX },
  270     /* Change dir on quit */
  271     { CONTROL('G'),   SEL_QUITCD },
  272     /* Quit */
  273     { CONTROL('Q'),   SEL_QUIT },
  274     /* Quit with an error code */
  275     { 'Q',            SEL_QUITERR },
  276 #ifndef NOMOUSE
  277     { KEY_MOUSE,      SEL_CLICK },
  278 #endif
  279 };