My build of nnn with minor changes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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