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