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