sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

nnn.h (7432B)


      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-2023, 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 #include <wchar.h>
     35 
     36 #define CONTROL(c) ((c) & 0x1f)
     37 
     38 #ifndef ESC
     39 #define ESC (27)
     40 #endif
     41 
     42 #ifndef DEL
     43 #define DEL (127)
     44 #endif
     45 
     46 /* Supported actions */
     47 enum action {
     48 	SEL_BACK = 1,
     49 	SEL_OPEN,
     50 	SEL_NAV_IN,
     51 	SEL_NEXT,
     52 	SEL_PREV,
     53 	SEL_PGDN,
     54 	SEL_PGUP,
     55 	SEL_CTRL_D,
     56 	SEL_CTRL_U,
     57 	SEL_HOME,
     58 	SEL_END,
     59 	SEL_FIRST,
     60 	SEL_JUMP,
     61 	SEL_YOUNG,
     62 	SEL_CDHOME,
     63 	SEL_CDBEGIN,
     64 	SEL_CDLAST,
     65 	SEL_CDROOT,
     66 	SEL_BMOPEN,
     67 	SEL_REMOTE,
     68 	SEL_CYCLE,
     69 	SEL_CYCLER,
     70 	SEL_CTX1,
     71 	SEL_CTX2,
     72 	SEL_CTX3,
     73 	SEL_CTX4,
     74 #ifdef CTX8
     75 	SEL_CTX5,
     76 	SEL_CTX6,
     77 	SEL_CTX7,
     78 	SEL_CTX8,
     79 #endif
     80 	SEL_MARK,
     81 	SEL_BMARK,
     82 	SEL_FLTR,
     83 	SEL_MFLTR,
     84 	SEL_HIDDEN,
     85 	SEL_DETAIL,
     86 	SEL_STATS,
     87 	SEL_CHMODX,
     88 	SEL_ARCHIVE,
     89 	SEL_SORT,
     90 	SEL_REDRAW,
     91 	SEL_SEL,
     92 	SEL_SELMUL,
     93 	SEL_SELALL,
     94 	SEL_SELINV,
     95 	SEL_SELEDIT,
     96 	SEL_CP,
     97 	SEL_MV,
     98 	SEL_CPMVAS,
     99 	SEL_RM,
    100 	SEL_OPENWITH,
    101 	SEL_NEW,
    102 	SEL_RENAME,
    103 	SEL_RENAMEMUL,
    104 	SEL_UMOUNT,
    105 	SEL_HELP,
    106 	SEL_AUTONEXT,
    107 	SEL_EDIT,
    108 	SEL_PLUGIN,
    109 	SEL_SELSIZE,
    110 	SEL_SHELL,
    111 	SEL_LAUNCH,
    112 	SEL_PROMPT,
    113 	SEL_LOCK,
    114 	SEL_SESSIONS,
    115 	SEL_EXPORT,
    116 	SEL_TIMETYPE,
    117 	SEL_QUITCTX,
    118 	SEL_QUITCD,
    119 	SEL_QUIT,
    120 	SEL_QUITERR,
    121 #ifndef NOMOUSE
    122 	SEL_CLICK,
    123 #endif
    124 };
    125 
    126 /* Associate a pressed key to an action */
    127 struct key {
    128 	wint_t sym;      /* Key pressed */
    129 	enum action act; /* Action */
    130 };
    131 
    132 static struct key bindings[] = {
    133 	/* Back */
    134 	{ KEY_LEFT,       SEL_BACK },
    135 	{ 'h',            SEL_BACK },
    136 	/* Inside or select */
    137 	{ KEY_ENTER,      SEL_OPEN },
    138 	{ '\r',           SEL_OPEN },
    139 	/* Pure navigate inside */
    140 	{ KEY_RIGHT,      SEL_NAV_IN },
    141 	{ 'l',            SEL_NAV_IN },
    142 	/* Next */
    143 	{ 'j',            SEL_NEXT },
    144 	{ KEY_DOWN,       SEL_NEXT },
    145 	/* Previous */
    146 	{ 'k',            SEL_PREV },
    147 	{ KEY_UP,         SEL_PREV },
    148 	/* Page down */
    149 	{ KEY_NPAGE,      SEL_PGDN },
    150 	/* Page up */
    151 	{ KEY_PPAGE,      SEL_PGUP },
    152 	/* Ctrl+D */
    153 	{ CONTROL('D'),   SEL_CTRL_D },
    154 	/* Ctrl+U */
    155 	{ CONTROL('U'),   SEL_CTRL_U },
    156 	/* First entry */
    157 	{ KEY_HOME,       SEL_HOME },
    158 	{ 'g',            SEL_HOME },
    159 	{ CONTROL('A'),   SEL_HOME },
    160 	/* Last entry */
    161 	{ KEY_END,        SEL_END },
    162 	{ 'G',            SEL_END },
    163 	{ CONTROL('E'),   SEL_END },
    164 	/* Go to first file */
    165 	{ '\'',           SEL_FIRST },
    166 	/* Jump to an entry number/offset */
    167 	{ 'J',            SEL_JUMP },
    168 	{ CONTROL('Y'),   SEL_YOUNG },
    169 	/* HOME */
    170 	{ '~',            SEL_CDHOME },
    171 	/* Initial directory */
    172 	{ '@',            SEL_CDBEGIN },
    173 	/* Last visited dir */
    174 	{ '-',            SEL_CDLAST },
    175 	/* Go to / */
    176 	{ '`',            SEL_CDROOT },
    177 	/* Leader key */
    178 	{ 'b',            SEL_BMOPEN },
    179 	{ CONTROL('_'),   SEL_BMOPEN },
    180 	/* Connect to server over SSHFS */
    181 	{ 'c',            SEL_REMOTE },
    182 	/* Cycle contexts in forward direction */
    183 	{ '\t',           SEL_CYCLE },
    184 	/* Cycle contexts in reverse direction */
    185 	{ KEY_BTAB,       SEL_CYCLER },
    186 	/* Go to/create context N */
    187 	{ '1',            SEL_CTX1 },
    188 	{ '2',            SEL_CTX2 },
    189 	{ '3',            SEL_CTX3 },
    190 	{ '4',            SEL_CTX4 },
    191 #ifdef CTX8
    192 	{ '5',            SEL_CTX5 },
    193 	{ '6',            SEL_CTX6 },
    194 	{ '7',            SEL_CTX7 },
    195 	{ '8',            SEL_CTX8 },
    196 #endif
    197 	/* Mark a path to visit later */
    198 	{ ',',            SEL_MARK },
    199 	/* Create a bookmark */
    200 	{ 'B',            SEL_BMARK },
    201 	/* Filter */
    202 	{ '/',            SEL_FLTR },
    203 	/* Toggle filter mode */
    204 	{ CONTROL('N'),   SEL_MFLTR },
    205 	/* Toggle hide .dot files */
    206 	{ '.',            SEL_HIDDEN },
    207 	/* Detailed listing */
    208 	{ 'd',            SEL_DETAIL },
    209 	/* File details */
    210 	{ 'f',            SEL_STATS },
    211 	{ CONTROL('F'),   SEL_STATS },
    212 	/* Toggle executable status */
    213 	{ '*',            SEL_CHMODX },
    214 	/* Create archive */
    215 	{ 'z',            SEL_ARCHIVE },
    216 	/* Sort toggles */
    217 	{ 't',            SEL_SORT },
    218 	{ CONTROL('T'),   SEL_SORT },
    219 	/* Redraw window */
    220 	{ CONTROL('L'),   SEL_REDRAW },
    221 	/* Select current file path */
    222 	{ ' ',            SEL_SEL },
    223 	{ '+',            SEL_SEL },
    224 	/* Toggle select multiple files */
    225 	{ 'm',            SEL_SELMUL },
    226 	/* Select all files in current dir */
    227 	{ 'a',            SEL_SELALL },
    228 	/* Invert selection in current dir */
    229 	{ 'A',            SEL_SELINV },
    230 	/* List, edit selection */
    231 	{ 'E',            SEL_SELEDIT },
    232 	/* Copy from selection buffer */
    233 	{ 'p',            SEL_CP },
    234 	{ CONTROL('P'),   SEL_CP },
    235 	/* Move from selection buffer */
    236 	{ 'v',            SEL_MV },
    237 	{ CONTROL('V'),   SEL_MV },
    238 	/* Copy/move from selection buffer and rename */
    239 	{ 'w',            SEL_CPMVAS },
    240 	{ CONTROL('W'),   SEL_CPMVAS },
    241 	/* Delete from selection buffer */
    242 	{ 'x',            SEL_RM },
    243 	{ CONTROL('X'),   SEL_RM },
    244 	/* Open in a custom application */
    245 	{ 'o',            SEL_OPENWITH },
    246 	{ CONTROL('O'),   SEL_OPENWITH },
    247 	/* Create a new file */
    248 	{ 'n',            SEL_NEW },
    249 	/* Show rename prompt */
    250 	{ CONTROL('R'),   SEL_RENAME },
    251 	/* Rename contents of current dir */
    252 	{ 'r',            SEL_RENAMEMUL },
    253 	/* Disconnect a SSHFS mount point */
    254 	{ 'u',            SEL_UMOUNT },
    255 	/* Show help */
    256 	{ '?',            SEL_HELP },
    257 	/* Toggle auto-advance on file open */
    258 	{ CONTROL('J'),   SEL_AUTONEXT },
    259 	/* Edit in EDITOR */
    260 	{ 'e',            SEL_EDIT },
    261 	/* Run a plugin */
    262 	{ ';',            SEL_PLUGIN },
    263 	/* Show total size of listed selection */
    264 	{ 'S',            SEL_SELSIZE },
    265 	/* Run command */
    266 	{ '!',            SEL_SHELL },
    267 	{ CONTROL(']'),   SEL_SHELL },
    268 	/* Launcher */
    269 	{ '=',            SEL_LAUNCH },
    270 	/* Show command prompt */
    271 	{ ']',            SEL_PROMPT },
    272 	/* Lock screen */
    273 	{ '0',            SEL_LOCK },
    274 	/* Manage sessions */
    275 	{ 's',            SEL_SESSIONS },
    276 	/* Export list */
    277 	{ '>',            SEL_EXPORT },
    278 	/* Set time type */
    279 	{ 'T',            SEL_TIMETYPE },
    280 	/* Quit a context */
    281 	{ 'q',            SEL_QUITCTX },
    282 	/* Change dir on quit */
    283 	{ CONTROL('G'),   SEL_QUITCD },
    284 	/* Quit */
    285 	{ CONTROL('Q'),   SEL_QUIT },
    286 	/* Quit with an error code */
    287 	{ 'Q',            SEL_QUITERR },
    288 #ifndef NOMOUSE
    289 	{ KEY_MOUSE,      SEL_CLICK },
    290 #endif
    291 };