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>
|
2020-12-28 21:03:52 +00:00
|
|
|
* Copyright (C) 2016-2021, 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>
|
|
|
|
|
2020-03-11 03:44:59 +00:00
|
|
|
#define CONTROL(c) ((c) & 0x1f)
|
2014-10-21 10:35:08 +00:00
|
|
|
|
2020-08-17 15:27:15 +00:00
|
|
|
#ifndef ESC
|
|
|
|
#define ESC (27)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DEL
|
|
|
|
#define DEL (127)
|
|
|
|
#endif
|
|
|
|
|
2017-06-20 04:56:31 +00:00
|
|
|
/* Supported actions */
|
|
|
|
enum action {
|
2017-12-12 20:16:50 +00:00
|
|
|
SEL_BACK = 1,
|
2020-08-15 14:51:22 +00:00
|
|
|
SEL_OPEN,
|
2018-11-26 18:54:12 +00:00
|
|
|
SEL_NAV_IN,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_NEXT,
|
|
|
|
SEL_PREV,
|
|
|
|
SEL_PGDN,
|
|
|
|
SEL_PGUP,
|
2019-04-20 20:25:15 +00:00
|
|
|
SEL_CTRL_D,
|
|
|
|
SEL_CTRL_U,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_HOME,
|
|
|
|
SEL_END,
|
2019-10-05 01:29:43 +00:00
|
|
|
SEL_FIRST,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_CDHOME,
|
|
|
|
SEL_CDBEGIN,
|
|
|
|
SEL_CDLAST,
|
2019-04-12 14:51:48 +00:00
|
|
|
SEL_CDROOT,
|
2019-12-28 19:08:03 +00:00
|
|
|
SEL_BOOKMARK,
|
2020-03-29 11:55:11 +00:00
|
|
|
SEL_REMOTE,
|
2018-11-26 21:49:37 +00:00
|
|
|
SEL_CYCLE,
|
2019-10-05 01:29:43 +00:00
|
|
|
SEL_CYCLER,
|
2019-01-19 07:39:46 +00:00
|
|
|
SEL_CTX1,
|
|
|
|
SEL_CTX2,
|
|
|
|
SEL_CTX3,
|
|
|
|
SEL_CTX4,
|
2020-05-30 01:29:45 +00:00
|
|
|
#ifdef CTX8
|
|
|
|
SEL_CTX5,
|
|
|
|
SEL_CTX6,
|
|
|
|
SEL_CTX7,
|
|
|
|
SEL_CTX8,
|
|
|
|
#endif
|
2020-07-07 02:27:43 +00:00
|
|
|
SEL_MARK,
|
2017-12-12 20:16:50 +00:00
|
|
|
SEL_FLTR,
|
|
|
|
SEL_MFLTR,
|
2020-01-18 14:25:09 +00:00
|
|
|
SEL_HIDDEN,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_DETAIL,
|
|
|
|
SEL_STATS,
|
2020-01-02 17:43:56 +00:00
|
|
|
SEL_CHMODX,
|
2018-04-24 23:34:37 +00:00
|
|
|
SEL_ARCHIVE,
|
2020-01-15 04:35:19 +00:00
|
|
|
SEL_SORT,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_REDRAW,
|
2019-08-06 20:08:51 +00:00
|
|
|
SEL_SEL,
|
|
|
|
SEL_SELMUL,
|
|
|
|
SEL_SELALL,
|
2020-11-19 19:38:53 +00:00
|
|
|
SEL_SELINV,
|
2020-01-13 18:14:19 +00:00
|
|
|
SEL_SELEDIT,
|
2018-11-10 23:29:26 +00:00
|
|
|
SEL_CP,
|
|
|
|
SEL_MV,
|
2019-10-17 18:05:49 +00:00
|
|
|
SEL_CPMVAS,
|
2018-11-10 23:29:26 +00:00
|
|
|
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,
|
2019-09-29 16:14:47 +00:00
|
|
|
SEL_RENAMEMUL,
|
2019-04-20 18:54:19 +00:00
|
|
|
SEL_UMOUNT,
|
2017-06-20 04:56:31 +00:00
|
|
|
SEL_HELP,
|
2020-03-28 19:12:20 +00:00
|
|
|
SEL_AUTONEXT,
|
2020-02-01 17:00:32 +00:00
|
|
|
SEL_EDIT,
|
2019-04-18 14:57:35 +00:00
|
|
|
SEL_PLUGIN,
|
2019-12-27 07:49:23 +00:00
|
|
|
SEL_SHELL,
|
2019-03-12 10:49:34 +00:00
|
|
|
SEL_LAUNCH,
|
2018-12-09 13:48:00 +00:00
|
|
|
SEL_RUNCMD,
|
2018-03-30 15:53:28 +00:00
|
|
|
SEL_LOCK,
|
2019-10-20 00:05:41 +00:00
|
|
|
SEL_SESSIONS,
|
2020-03-29 14:52:43 +00:00
|
|
|
SEL_EXPORT,
|
|
|
|
SEL_TIMETYPE,
|
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,
|
2020-11-13 07:10:57 +00:00
|
|
|
SEL_QUITERR,
|
2020-02-14 02:51:30 +00:00
|
|
|
#ifndef NOMOUSE
|
2019-05-08 00:38:07 +00:00
|
|
|
SEL_CLICK,
|
2020-02-14 02:51:30 +00:00
|
|
|
#endif
|
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
|
|
|
|
2017-04-23 17:42:54 +00:00
|
|
|
static struct key bindings[] = {
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Back */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ KEY_LEFT, SEL_BACK },
|
|
|
|
{ 'h', SEL_BACK },
|
|
|
|
/* Inside or select */
|
2020-08-15 14:51:22 +00:00
|
|
|
{ KEY_ENTER, SEL_OPEN },
|
|
|
|
{ '\r', SEL_OPEN },
|
2018-12-04 22:24:48 +00:00
|
|
|
/* Pure navigate inside */
|
|
|
|
{ KEY_RIGHT, SEL_NAV_IN },
|
|
|
|
{ 'l', SEL_NAV_IN },
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Next */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ 'j', SEL_NEXT },
|
|
|
|
{ KEY_DOWN, SEL_NEXT },
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Previous */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ 'k', SEL_PREV },
|
|
|
|
{ KEY_UP, SEL_PREV },
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Page down */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ KEY_NPAGE, SEL_PGDN },
|
2014-11-06 11:46:37 +00:00
|
|
|
/* Page up */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ KEY_PPAGE, SEL_PGUP },
|
2019-04-20 20:25:15 +00:00
|
|
|
/* Ctrl+D */
|
|
|
|
{ CONTROL('D'), SEL_CTRL_D },
|
|
|
|
/* Ctrl+U */
|
|
|
|
{ CONTROL('U'), SEL_CTRL_U },
|
2017-04-23 21:06:49 +00:00
|
|
|
/* First entry */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ KEY_HOME, SEL_HOME },
|
|
|
|
{ 'g', SEL_HOME },
|
|
|
|
{ CONTROL('A'), SEL_HOME },
|
2017-04-23 21:06:49 +00:00
|
|
|
/* Last entry */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ KEY_END, SEL_END },
|
|
|
|
{ 'G', SEL_END },
|
|
|
|
{ CONTROL('E'), SEL_END },
|
2019-10-05 01:29:43 +00:00
|
|
|
/* Go to first file */
|
2020-01-14 15:31:59 +00:00
|
|
|
{ '\'', SEL_FIRST },
|
2017-04-08 08:16:03 +00:00
|
|
|
/* HOME */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ '~', SEL_CDHOME },
|
2017-04-23 21:06:49 +00:00
|
|
|
/* Initial directory */
|
2019-03-12 11:13:17 +00:00
|
|
|
{ '@', SEL_CDBEGIN },
|
2017-04-08 08:16:03 +00:00
|
|
|
/* 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 },
|
2019-12-25 16:48:36 +00:00
|
|
|
/* Leader key */
|
2019-12-28 19:08:03 +00:00
|
|
|
{ 'b', SEL_BOOKMARK },
|
2019-12-29 12:28:48 +00:00
|
|
|
{ CONTROL('_'), SEL_BOOKMARK },
|
2020-03-29 11:55:11 +00:00
|
|
|
/* Connect to server over SSHFS */
|
|
|
|
{ 'c', SEL_REMOTE },
|
2018-11-26 21:49:37 +00:00
|
|
|
/* Cycle contexts in forward direction */
|
2019-12-11 14:36:12 +00:00
|
|
|
{ '\t', SEL_CYCLE },
|
2019-10-05 01:29:43 +00:00
|
|
|
/* Cycle contexts in reverse direction */
|
|
|
|
{ KEY_BTAB, SEL_CYCLER },
|
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 },
|
2020-05-30 01:29:45 +00:00
|
|
|
#ifdef CTX8
|
|
|
|
{ '5', SEL_CTX5 },
|
|
|
|
{ '6', SEL_CTX6 },
|
|
|
|
{ '7', SEL_CTX7 },
|
|
|
|
{ '8', SEL_CTX8 },
|
|
|
|
#endif
|
2017-08-20 11:17:23 +00:00
|
|
|
/* Mark a path to visit later */
|
2020-07-07 02:27:43 +00:00
|
|
|
{ ',', SEL_MARK },
|
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 */
|
2019-12-29 12:28:48 +00:00
|
|
|
{ CONTROL('N'), SEL_MFLTR },
|
2016-02-25 14:54:41 +00:00
|
|
|
/* Toggle hide .dot files */
|
2020-01-18 14:25:09 +00:00
|
|
|
{ '.', SEL_HIDDEN },
|
2017-03-29 20:21:52 +00:00
|
|
|
/* Detailed listing */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ 'd', SEL_DETAIL },
|
2017-04-02 23:35:14 +00:00
|
|
|
/* File details */
|
2020-01-14 15:31:59 +00:00
|
|
|
{ 'f', SEL_STATS },
|
2020-01-13 22:40:11 +00:00
|
|
|
{ CONTROL('F'), SEL_STATS },
|
2020-01-02 17:43:56 +00:00
|
|
|
/* Toggle executable status */
|
|
|
|
{ '*', SEL_CHMODX },
|
2018-04-24 23:34:37 +00:00
|
|
|
/* Create archive */
|
2020-01-13 13:27:46 +00:00
|
|
|
{ 'z', SEL_ARCHIVE },
|
2020-01-14 15:31:59 +00:00
|
|
|
/* Sort toggles */
|
2020-01-15 04:35:19 +00:00
|
|
|
{ 't', SEL_SORT },
|
|
|
|
{ CONTROL('T'), SEL_SORT },
|
2017-08-20 11:17:23 +00:00
|
|
|
/* Redraw window */
|
2018-12-04 22:24:48 +00:00
|
|
|
{ CONTROL('L'), SEL_REDRAW },
|
2019-09-08 08:53:00 +00:00
|
|
|
/* Select current file path */
|
2019-09-30 01:24:06 +00:00
|
|
|
{ CONTROL('J'), SEL_SEL },
|
2019-08-06 20:08:51 +00:00
|
|
|
{ ' ', SEL_SEL },
|
2019-09-08 08:53:00 +00:00
|
|
|
/* Toggle select multiple files */
|
2020-01-13 16:54:55 +00:00
|
|
|
{ 'm', SEL_SELMUL },
|
2019-01-29 21:28:42 +00:00
|
|
|
/* Select all files in current dir */
|
2019-09-29 17:29:27 +00:00
|
|
|
{ 'a', SEL_SELALL },
|
2020-11-19 19:38:53 +00:00
|
|
|
/* Invert selection in current dir */
|
|
|
|
{ 'A', SEL_SELINV },
|
2020-01-13 14:43:46 +00:00
|
|
|
/* List, edit selection */
|
2020-02-01 17:00:32 +00:00
|
|
|
{ 'E', SEL_SELEDIT },
|
2019-09-08 08:53:00 +00:00
|
|
|
/* Copy from selection buffer */
|
2020-01-13 22:00:52 +00:00
|
|
|
{ 'p', SEL_CP },
|
2020-01-14 15:31:59 +00:00
|
|
|
{ CONTROL('P'), SEL_CP },
|
2019-09-08 08:53:00 +00:00
|
|
|
/* Move from selection buffer */
|
2020-01-13 22:00:52 +00:00
|
|
|
{ 'v', SEL_MV },
|
2020-01-14 15:31:59 +00:00
|
|
|
{ CONTROL('V'), SEL_MV },
|
2019-10-17 18:05:49 +00:00
|
|
|
/* Copy/move from selection buffer and rename */
|
2020-01-14 15:31:59 +00:00
|
|
|
{ 'w', SEL_CPMVAS },
|
|
|
|
{ CONTROL('W'), SEL_CPMVAS },
|
2019-09-08 08:53:00 +00:00
|
|
|
/* Delete from selection buffer */
|
2020-01-14 15:31:59 +00:00
|
|
|
{ 'x', SEL_RM },
|
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 */
|
2020-01-14 15:31:59 +00:00
|
|
|
{ 'o', SEL_OPENWITH },
|
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 */
|
2019-09-29 16:14:47 +00:00
|
|
|
{ 'r', SEL_RENAMEMUL },
|
2019-04-20 18:54:19 +00:00
|
|
|
/* 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 },
|
2020-03-28 19:12:20 +00:00
|
|
|
/* Quit a context */
|
|
|
|
{ '+', SEL_AUTONEXT },
|
2020-02-01 17:00:32 +00:00
|
|
|
/* Edit in EDITOR */
|
|
|
|
{ 'e', SEL_EDIT },
|
2019-04-18 14:57:35 +00:00
|
|
|
/* Run a plugin */
|
2020-01-13 15:39:40 +00:00
|
|
|
{ ';', SEL_PLUGIN },
|
2019-12-27 07:49:23 +00:00
|
|
|
/* Run command */
|
|
|
|
{ '!', SEL_SHELL },
|
|
|
|
{ CONTROL(']'), SEL_SHELL },
|
2019-03-12 10:49:34 +00:00
|
|
|
/* Launcher */
|
|
|
|
{ '=', SEL_LAUNCH },
|
2018-12-09 13:48:00 +00:00
|
|
|
/* Run a command */
|
2019-12-09 19:57:51 +00:00
|
|
|
{ ']', SEL_RUNCMD },
|
2018-03-30 15:53:28 +00:00
|
|
|
/* Lock screen */
|
2020-01-13 21:30:01 +00:00
|
|
|
{ '0', SEL_LOCK },
|
2020-01-30 20:15:06 +00:00
|
|
|
/* Manage sessions */
|
|
|
|
{ 's', SEL_SESSIONS },
|
2020-03-29 14:52:43 +00:00
|
|
|
/* Export list */
|
|
|
|
{ '>', SEL_EXPORT },
|
|
|
|
/* Set time type */
|
|
|
|
{ 'T', SEL_TIMETYPE },
|
2020-01-30 20:15:06 +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
|
|
|
{ CONTROL('Q'), SEL_QUIT },
|
2020-01-16 13:55:48 +00:00
|
|
|
/* Quit with an error code */
|
2020-11-13 07:10:57 +00:00
|
|
|
{ 'Q', SEL_QUITERR },
|
2020-02-14 02:51:30 +00:00
|
|
|
#ifndef NOMOUSE
|
2019-05-08 00:38:07 +00:00
|
|
|
{ KEY_MOUSE, SEL_CLICK },
|
2020-02-14 02:51:30 +00:00
|
|
|
#endif
|
2014-11-06 11:46:37 +00:00
|
|
|
};
|