nnn/src/nnn.h

260 lines
6.8 KiB
C
Raw Normal View History

2018-09-07 15:50:10 +00:00
/*
2018-10-04 19:08:57 +00:00
* BSD 2-Clause License
*
2019-02-23 09:25:01 +00:00
* Copyright (C) 2014-2016, Lazaros Koromilas <lostd@2f30.org>
* Copyright (C) 2014-2016, Dimitris Papastamos <sin@2f30.org>
* Copyright (C) 2016-2019, Arun Prakash Jana <engineerarun@gmail.com>
2018-09-07 15:50:10 +00:00
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
2018-10-04 19:08:57 +00:00
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
2018-09-07 15:50:10 +00:00
*
2018-10-04 19:08:57 +00:00
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
2018-09-07 15:50:10 +00:00
*
2018-10-04 19:08:57 +00:00
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2018-09-07 15:50:10 +00:00
*/
2018-11-03 08:20:03 +00:00
#pragma once
#include <curses.h>
2017-06-20 04:56:31 +00:00
#define CONTROL(c) ((c) ^ 0x40)
2017-06-20 04:56:31 +00:00
/* Supported actions */
enum action {
2017-12-12 20:16:50 +00:00
SEL_BACK = 1,
2017-06-20 04:56:31 +00:00
SEL_GOIN,
SEL_NAV_IN,
2017-06-20 04:56:31 +00:00
SEL_NEXT,
SEL_PREV,
SEL_PGDN,
SEL_PGUP,
SEL_CTRL_D,
SEL_CTRL_U,
2017-06-20 04:56:31 +00:00
SEL_HOME,
SEL_END,
SEL_CDHOME,
SEL_CDBEGIN,
SEL_CDLAST,
2019-04-12 14:51:48 +00:00
SEL_CDROOT,
SEL_VISIT,
2018-11-11 21:34:17 +00:00
SEL_LEADER,
2018-11-26 21:49:37 +00:00
SEL_CYCLE,
2019-01-19 07:39:46 +00:00
SEL_CTX1,
SEL_CTX2,
SEL_CTX3,
SEL_CTX4,
2017-09-01 14:27:36 +00:00
SEL_PIN,
2017-12-12 20:16:50 +00:00
SEL_FLTR,
SEL_MFLTR,
2017-06-20 04:56:31 +00:00
SEL_TOGGLEDOT,
SEL_DETAIL,
SEL_STATS,
SEL_MEDIA,
SEL_FMEDIA,
2018-04-24 23:34:37 +00:00
SEL_ARCHIVE,
2018-12-08 06:21:22 +00:00
SEL_ARCHIVELS,
2017-09-27 14:49:42 +00:00
SEL_EXTRACT,
2018-10-04 18:56:31 +00:00
SEL_FSIZE, /* file size */
SEL_ASIZE, /* apparent size */
SEL_BSIZE, /* block size */
2017-06-20 04:56:31 +00:00
SEL_MTIME,
2019-02-27 15:33:14 +00:00
SEL_WILD,
2017-06-20 04:56:31 +00:00
SEL_REDRAW,
SEL_COPY,
SEL_COPYMUL,
2019-01-29 21:28:42 +00:00
SEL_COPYALL,
SEL_COPYLIST,
SEL_CP,
SEL_MV,
SEL_RMMUL,
SEL_RM,
2018-12-16 15:00:44 +00:00
SEL_OPENWITH,
2017-09-10 07:35:25 +00:00
SEL_NEW,
2017-08-22 19:16:58 +00:00
SEL_RENAME,
2018-02-24 14:16:58 +00:00
SEL_RENAMEALL,
2019-04-20 18:54:19 +00:00
SEL_SSHFS,
SEL_UMOUNT,
2017-06-20 04:56:31 +00:00
SEL_HELP,
2018-12-08 12:52:06 +00:00
SEL_EXEC,
2018-12-08 10:48:46 +00:00
SEL_SHELL,
2019-04-18 14:57:35 +00:00
SEL_PLUGIN,
SEL_LAUNCH,
2018-12-09 13:48:00 +00:00
SEL_RUNCMD,
SEL_RUNEDIT,
SEL_RUNPAGE,
2019-01-19 09:08:47 +00:00
SEL_NOTE,
2018-03-30 15:53:28 +00:00
SEL_LOCK,
2018-11-08 14:46:08 +00:00
SEL_QUITCTX,
2018-11-25 15:36:47 +00:00
SEL_QUITCD,
2017-12-12 20:16:50 +00:00
SEL_QUIT,
2017-06-20 04:56:31 +00:00
};
/* Associate a pressed key to an action */
struct key {
int sym; /* Key pressed */
enum action act; /* Action */
2019-03-11 14:38:03 +00:00
};
2017-06-20 04:56:31 +00:00
static struct key bindings[] = {
/* Back */
2018-12-04 22:24:48 +00:00
{ KEY_LEFT, SEL_BACK },
{ 'h', SEL_BACK },
/* Inside or select */
{ KEY_ENTER, SEL_GOIN },
{ '\r', SEL_GOIN },
/* Pure navigate inside */
{ KEY_RIGHT, SEL_NAV_IN },
{ 'l', SEL_NAV_IN },
/* Next */
2018-12-04 22:24:48 +00:00
{ 'j', SEL_NEXT },
{ KEY_DOWN, SEL_NEXT },
/* Previous */
2018-12-04 22:24:48 +00:00
{ 'k', SEL_PREV },
{ KEY_UP, SEL_PREV },
/* Page down */
2018-12-04 22:24:48 +00:00
{ KEY_NPAGE, SEL_PGDN },
/* Page up */
2018-12-04 22:24:48 +00:00
{ KEY_PPAGE, SEL_PGUP },
/* Ctrl+D */
{ CONTROL('D'), SEL_CTRL_D },
/* Ctrl+U */
{ CONTROL('U'), SEL_CTRL_U },
/* First entry */
2018-12-04 22:24:48 +00:00
{ KEY_HOME, SEL_HOME },
{ 'g', SEL_HOME },
{ CONTROL('A'), SEL_HOME },
/* Last entry */
2018-12-04 22:24:48 +00:00
{ KEY_END, SEL_END },
{ 'G', SEL_END },
{ CONTROL('E'), SEL_END },
/* HOME */
2018-12-04 22:24:48 +00:00
{ '~', SEL_CDHOME },
/* Initial directory */
2019-03-12 11:13:17 +00:00
{ '@', SEL_CDBEGIN },
/* Last visited dir */
2018-12-04 22:24:48 +00:00
{ '-', SEL_CDLAST },
2019-04-12 14:51:48 +00:00
/* Go to / */
{ '`', SEL_CDROOT },
/* Visit marked directory */
2019-01-26 02:58:51 +00:00
{ CONTROL('B'), SEL_VISIT },
2018-11-11 21:34:17 +00:00
/* Leader key */
2018-12-04 22:24:48 +00:00
{ CONTROL('_'), SEL_LEADER },
{ ',', SEL_LEADER },
2018-11-26 21:49:37 +00:00
/* Cycle contexts in forward direction */
2018-12-04 22:24:48 +00:00
{ '\t', SEL_CYCLE },
2018-12-05 00:14:33 +00:00
{ CONTROL('I'), SEL_CYCLE },
2019-01-19 07:39:46 +00:00
/* Go to/create context N */
{ '1', SEL_CTX1 },
{ '2', SEL_CTX2 },
{ '3', SEL_CTX3 },
{ '4', SEL_CTX4 },
/* Mark a path to visit later */
2018-12-04 22:24:48 +00:00
{ 'b', SEL_PIN },
2017-12-12 20:16:50 +00:00
/* Filter */
2018-12-04 22:24:48 +00:00
{ '/', SEL_FLTR },
2017-12-12 20:16:50 +00:00
/* Toggle filter mode */
2018-12-04 22:24:48 +00:00
{ KEY_IC, SEL_MFLTR },
{ CONTROL('T'), SEL_MFLTR },
/* Toggle hide .dot files */
2018-12-04 22:24:48 +00:00
{ '.', SEL_TOGGLEDOT },
/* Detailed listing */
2018-12-04 22:24:48 +00:00
{ 'd', SEL_DETAIL },
/* File details */
2018-12-04 22:24:48 +00:00
{ 'D', SEL_STATS },
2017-07-02 18:27:41 +00:00
/* Show media info short, run is hacked */
2018-12-04 22:24:48 +00:00
{ 'm', SEL_MEDIA },
2017-07-02 18:27:41 +00:00
/* Show media info full, run is hacked */
2018-12-04 22:24:48 +00:00
{ 'M', SEL_FMEDIA },
2018-04-24 23:34:37 +00:00
/* Create archive */
2018-12-04 22:24:48 +00:00
{ 'f', SEL_ARCHIVE },
2017-09-27 14:49:42 +00:00
/* List archive */
2018-12-08 06:21:22 +00:00
{ 'F', SEL_ARCHIVELS },
2017-09-27 14:49:42 +00:00
/* Extract archive */
2018-12-04 22:24:48 +00:00
{ CONTROL('F'), SEL_EXTRACT },
/* Toggle sort by size */
2018-12-04 22:24:48 +00:00
{ 's', SEL_FSIZE },
2018-10-04 18:56:31 +00:00
/* Sort by apparent size including dir contents */
2018-12-04 22:24:48 +00:00
{ 'S', SEL_ASIZE },
2017-06-22 04:09:17 +00:00
/* Sort by total block count including dir contents */
2018-12-04 22:24:48 +00:00
{ CONTROL('J'), SEL_BSIZE },
2015-02-05 15:53:50 +00:00
/* Toggle sort by time */
2018-12-04 22:24:48 +00:00
{ 't', SEL_MTIME },
2019-03-20 03:44:39 +00:00
/* Wild load */
2019-02-27 15:33:14 +00:00
{ CONTROL('W'), SEL_WILD },
/* Redraw window */
2018-12-04 22:24:48 +00:00
{ CONTROL('L'), SEL_REDRAW },
/* Copy currently selected file path */
2018-12-04 22:24:48 +00:00
{ CONTROL('K'), SEL_COPY },
{ ' ', SEL_COPY },
/* Toggle copy multiple file paths */
2019-02-23 14:43:04 +00:00
{ 'K', SEL_COPYMUL },
2018-12-04 22:24:48 +00:00
{ CONTROL('Y'), SEL_COPYMUL },
2019-01-29 21:28:42 +00:00
/* Select all files in current dir */
{ 'Y', SEL_COPYALL },
/* Show list of copied files */
2018-12-04 22:24:48 +00:00
{ 'y', SEL_COPYLIST },
/* Copy from copy buffer */
2018-12-04 22:24:48 +00:00
{ 'P', SEL_CP },
/* Move from copy buffer */
2018-12-04 22:24:48 +00:00
{ 'V', SEL_MV },
/* Delete from copy buffer */
2018-12-04 22:24:48 +00:00
{ 'X', SEL_RMMUL },
/* Delete currently selected */
2018-12-04 22:24:48 +00:00
{ CONTROL('X'), SEL_RM },
2017-12-25 10:25:53 +00:00
/* Open in a custom application */
2018-12-16 15:00:44 +00:00
{ CONTROL('O'), SEL_OPENWITH },
2017-09-10 07:35:25 +00:00
/* Create a new file */
2018-12-04 22:24:48 +00:00
{ 'n', SEL_NEW },
2017-08-22 19:16:58 +00:00
/* Show rename prompt */
2018-12-04 22:24:48 +00:00
{ CONTROL('R'), SEL_RENAME },
2018-02-24 14:16:58 +00:00
/* Rename contents of current dir */
2018-12-04 22:24:48 +00:00
{ 'r', SEL_RENAMEALL },
2019-04-20 18:54:19 +00:00
/* Connect to server over SSHFS */
{ 'c', SEL_SSHFS },
/* Disconnect a SSHFS mount point */
{ 'u', SEL_UMOUNT },
2017-04-03 17:03:46 +00:00
/* Show help */
2018-12-04 22:24:48 +00:00
{ '?', SEL_HELP },
2018-12-08 12:52:06 +00:00
/* Execute file */
2018-12-09 13:48:00 +00:00
{ 'C', SEL_EXEC },
/* Run command */
2018-12-08 10:48:46 +00:00
{ '!', SEL_SHELL },
{ CONTROL(']'), SEL_SHELL },
2019-04-18 14:57:35 +00:00
/* Run a plugin */
{ 'R', SEL_PLUGIN },
{ CONTROL('V'), SEL_PLUGIN },
/* Launcher */
{ '=', SEL_LAUNCH },
2018-12-09 13:48:00 +00:00
/* Run a command */
{ CONTROL('P'), SEL_RUNCMD },
2018-12-09 13:48:00 +00:00
/* Open in EDITOR or PAGER */
2018-12-04 22:24:48 +00:00
{ 'e', SEL_RUNEDIT },
{ 'p', SEL_RUNPAGE },
2019-01-19 09:08:47 +00:00
/* Open notes file */
2019-01-23 16:19:56 +00:00
{ CONTROL('N'), SEL_NOTE },
2018-03-30 15:53:28 +00:00
/* Lock screen */
2018-12-04 22:24:48 +00:00
{ 'L', SEL_LOCK },
2018-11-08 14:46:08 +00:00
/* Quit a context */
2018-12-04 22:24:48 +00:00
{ 'q', SEL_QUITCTX },
2017-12-12 20:16:50 +00:00
/* Change dir on quit */
2018-12-04 22:24:48 +00:00
{ CONTROL('G'), SEL_QUITCD },
2017-12-12 20:16:50 +00:00
/* Quit */
2018-12-04 22:24:48 +00:00
{ 'Q', SEL_QUIT },
{ CONTROL('Q'), SEL_QUIT },
};