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