My build of nnn with minor changes
 
 
 
 
 
 

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