My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

259 lines
6.8 KiB

  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-2019, 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. #pragma once
  31. #include <curses.h>
  32. #define CONTROL(c) ((c) ^ 0x40)
  33. /* Supported actions */
  34. enum action {
  35. SEL_BACK = 1,
  36. SEL_GOIN,
  37. SEL_NAV_IN,
  38. SEL_NEXT,
  39. SEL_PREV,
  40. SEL_PGDN,
  41. SEL_PGUP,
  42. SEL_CTRL_D,
  43. SEL_CTRL_U,
  44. SEL_HOME,
  45. SEL_END,
  46. SEL_CDHOME,
  47. SEL_CDBEGIN,
  48. SEL_CDLAST,
  49. SEL_CDROOT,
  50. SEL_VISIT,
  51. SEL_LEADER,
  52. SEL_CYCLE,
  53. SEL_CTX1,
  54. SEL_CTX2,
  55. SEL_CTX3,
  56. SEL_CTX4,
  57. SEL_PIN,
  58. SEL_FLTR,
  59. SEL_MFLTR,
  60. SEL_TOGGLEDOT,
  61. SEL_DETAIL,
  62. SEL_STATS,
  63. SEL_ARCHIVE,
  64. SEL_ARCHIVELS,
  65. SEL_EXTRACT,
  66. SEL_FSIZE, /* file size */
  67. SEL_ASIZE, /* apparent size */
  68. SEL_BSIZE, /* block size */
  69. SEL_EXTN, /* order by extension */
  70. SEL_MTIME,
  71. SEL_REDRAW,
  72. SEL_SEL,
  73. SEL_SELMUL,
  74. SEL_SELALL,
  75. SEL_SELLST,
  76. SEL_CP,
  77. SEL_MV,
  78. SEL_RMMUL,
  79. SEL_RM,
  80. SEL_OPENWITH,
  81. SEL_NEW,
  82. SEL_RENAME,
  83. SEL_RENAMEMUL,
  84. SEL_SSHFS,
  85. SEL_UMOUNT,
  86. SEL_HELP,
  87. SEL_EXEC,
  88. SEL_SHELL,
  89. SEL_PLUGKEY,
  90. SEL_PLUGIN,
  91. SEL_LAUNCH,
  92. SEL_RUNCMD,
  93. SEL_RUNEDIT,
  94. SEL_RUNPAGE,
  95. SEL_LOCK,
  96. SEL_QUITCTX,
  97. SEL_QUITCD,
  98. SEL_QUIT,
  99. SEL_CLICK,
  100. };
  101. /* Associate a pressed key to an action */
  102. struct key {
  103. int sym; /* Key pressed */
  104. enum action act; /* Action */
  105. };
  106. static struct key bindings[] = {
  107. /* Back */
  108. { KEY_LEFT, SEL_BACK },
  109. { 'h', SEL_BACK },
  110. /* Inside or select */
  111. { KEY_ENTER, SEL_GOIN },
  112. { '\r', SEL_GOIN },
  113. /* Pure navigate inside */
  114. { KEY_RIGHT, SEL_NAV_IN },
  115. { 'l', SEL_NAV_IN },
  116. /* Next */
  117. { 'j', SEL_NEXT },
  118. { KEY_DOWN, SEL_NEXT },
  119. /* Previous */
  120. { 'k', SEL_PREV },
  121. { KEY_UP, SEL_PREV },
  122. /* Page down */
  123. { KEY_NPAGE, SEL_PGDN },
  124. /* Page up */
  125. { KEY_PPAGE, SEL_PGUP },
  126. /* Ctrl+D */
  127. { CONTROL('D'), SEL_CTRL_D },
  128. /* Ctrl+U */
  129. { CONTROL('U'), SEL_CTRL_U },
  130. /* First entry */
  131. { KEY_HOME, SEL_HOME },
  132. { 'g', SEL_HOME },
  133. { CONTROL('A'), SEL_HOME },
  134. /* Last entry */
  135. { KEY_END, SEL_END },
  136. { 'G', SEL_END },
  137. { CONTROL('E'), SEL_END },
  138. /* HOME */
  139. { '~', SEL_CDHOME },
  140. /* Initial directory */
  141. { '@', SEL_CDBEGIN },
  142. /* Last visited dir */
  143. { '-', SEL_CDLAST },
  144. /* Go to / */
  145. { '`', SEL_CDROOT },
  146. /* Visit marked directory */
  147. { CONTROL('B'), SEL_VISIT },
  148. /* Leader key */
  149. { CONTROL('_'), SEL_LEADER },
  150. { ',', SEL_LEADER },
  151. /* Cycle contexts in forward direction */
  152. { '\t', SEL_CYCLE },
  153. { CONTROL('I'), SEL_CYCLE },
  154. /* Go to/create context N */
  155. { '1', SEL_CTX1 },
  156. { '2', SEL_CTX2 },
  157. { '3', SEL_CTX3 },
  158. { '4', SEL_CTX4 },
  159. /* Mark a path to visit later */
  160. { 'b', SEL_PIN },
  161. /* Filter */
  162. { '/', SEL_FLTR },
  163. /* Toggle filter mode */
  164. { KEY_IC, SEL_MFLTR },
  165. { CONTROL('T'), SEL_MFLTR },
  166. /* Toggle hide .dot files */
  167. { '.', SEL_TOGGLEDOT },
  168. /* Detailed listing */
  169. { 'd', SEL_DETAIL },
  170. /* File details */
  171. { 'D', SEL_STATS },
  172. /* Create archive */
  173. { 'f', SEL_ARCHIVE },
  174. /* List archive */
  175. { 'F', SEL_ARCHIVELS },
  176. /* Extract archive */
  177. { CONTROL('F'), SEL_EXTRACT },
  178. /* Toggle sort by size */
  179. { 's', SEL_FSIZE },
  180. /* Sort by apparent size including dir contents */
  181. { 'A', SEL_ASIZE },
  182. /* Sort by total block count including dir contents */
  183. { 'S', SEL_BSIZE },
  184. /* Sort by file extension */
  185. { 'E', SEL_EXTN },
  186. /* Toggle sort by time */
  187. { 't', SEL_MTIME },
  188. /* Redraw window */
  189. { CONTROL('L'), SEL_REDRAW },
  190. { KEY_F(5), SEL_REDRAW },
  191. /* Select current file path */
  192. { CONTROL('J'), SEL_SEL },
  193. { ' ', SEL_SEL },
  194. /* Toggle select multiple files */
  195. { 'm', SEL_SELMUL },
  196. { CONTROL('S'), SEL_SELMUL },
  197. /* Select all files in current dir */
  198. { 'a', SEL_SELALL },
  199. /* Show list of copied files */
  200. { 'y', SEL_SELLST },
  201. /* Copy from selection buffer */
  202. { 'P', SEL_CP },
  203. /* Move from selection buffer */
  204. { 'V', SEL_MV },
  205. /* Delete from selection buffer */
  206. { 'X', SEL_RMMUL },
  207. /* Delete currently selected */
  208. { CONTROL('X'), SEL_RM },
  209. /* Open in a custom application */
  210. { CONTROL('O'), SEL_OPENWITH },
  211. /* Create a new file */
  212. { 'n', SEL_NEW },
  213. /* Show rename prompt */
  214. { CONTROL('R'), SEL_RENAME },
  215. { KEY_F(2), SEL_RENAME },
  216. /* Rename contents of current dir */
  217. { 'r', SEL_RENAMEMUL },
  218. /* Connect to server over SSHFS */
  219. { 'c', SEL_SSHFS },
  220. /* Disconnect a SSHFS mount point */
  221. { 'u', SEL_UMOUNT },
  222. /* Show help */
  223. { '?', SEL_HELP },
  224. /* Execute file */
  225. { 'C', SEL_EXEC },
  226. /* Run command */
  227. { '!', SEL_SHELL },
  228. { CONTROL(']'), SEL_SHELL },
  229. /* Plugin key */
  230. { 'x', SEL_PLUGKEY },
  231. { ':', SEL_PLUGKEY },
  232. /* Run a plugin */
  233. { 'R', SEL_PLUGIN },
  234. { CONTROL('V'), SEL_PLUGIN },
  235. /* Launcher */
  236. { '=', SEL_LAUNCH },
  237. /* Run a command */
  238. { CONTROL('P'), SEL_RUNCMD },
  239. /* Open in EDITOR or PAGER */
  240. { 'e', SEL_RUNEDIT },
  241. { 'p', SEL_RUNPAGE },
  242. /* Lock screen */
  243. { 'L', SEL_LOCK },
  244. /* Quit a context */
  245. { 'q', SEL_QUITCTX },
  246. /* Change dir on quit */
  247. { CONTROL('G'), SEL_QUITCD },
  248. /* Quit */
  249. { 'Q', SEL_QUIT },
  250. { CONTROL('Q'), SEL_QUIT },
  251. { KEY_MOUSE, SEL_CLICK },
  252. };