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.7 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. SEL_PIN,
  60. SEL_FLTR,
  61. SEL_MFLTR,
  62. SEL_HIDDEN,
  63. SEL_DETAIL,
  64. SEL_STATS,
  65. SEL_CHMODX,
  66. SEL_ARCHIVE,
  67. SEL_SORT,
  68. SEL_REDRAW,
  69. SEL_SEL,
  70. SEL_SELMUL,
  71. SEL_SELALL,
  72. SEL_SELEDIT,
  73. SEL_CP,
  74. SEL_MV,
  75. SEL_CPMVAS,
  76. SEL_RM,
  77. SEL_OPENWITH,
  78. SEL_NEW,
  79. SEL_RENAME,
  80. SEL_RENAMEMUL,
  81. SEL_UMOUNT,
  82. SEL_HELP,
  83. SEL_AUTONEXT,
  84. SEL_EDIT,
  85. SEL_PLUGIN,
  86. SEL_SHELL,
  87. SEL_LAUNCH,
  88. SEL_RUNCMD,
  89. SEL_LOCK,
  90. SEL_SESSIONS,
  91. SEL_EXPORT,
  92. SEL_TIMETYPE,
  93. SEL_QUITCTX,
  94. SEL_QUITCD,
  95. SEL_QUIT,
  96. SEL_QUITFAIL,
  97. #ifndef NOMOUSE
  98. SEL_CLICK,
  99. #endif
  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. /* Go to first file */
  139. { '\'', SEL_FIRST },
  140. /* HOME */
  141. { '~', SEL_CDHOME },
  142. /* Initial directory */
  143. { '@', SEL_CDBEGIN },
  144. /* Last visited dir */
  145. { '-', SEL_CDLAST },
  146. /* Go to / */
  147. { '`', SEL_CDROOT },
  148. /* Leader key */
  149. { 'b', SEL_BOOKMARK },
  150. { CONTROL('_'), SEL_BOOKMARK },
  151. /* Connect to server over SSHFS */
  152. { 'c', SEL_REMOTE },
  153. /* Cycle contexts in forward direction */
  154. { '\t', SEL_CYCLE },
  155. /* Cycle contexts in reverse direction */
  156. { KEY_BTAB, SEL_CYCLER },
  157. /* Go to/create context N */
  158. { '1', SEL_CTX1 },
  159. { '2', SEL_CTX2 },
  160. { '3', SEL_CTX3 },
  161. { '4', SEL_CTX4 },
  162. /* Mark a path to visit later */
  163. { ',', SEL_PIN },
  164. /* Filter */
  165. { '/', SEL_FLTR },
  166. /* Toggle filter mode */
  167. { CONTROL('N'), SEL_MFLTR },
  168. /* Toggle hide .dot files */
  169. { '.', SEL_HIDDEN },
  170. /* Detailed listing */
  171. { 'd', SEL_DETAIL },
  172. /* File details */
  173. { 'f', SEL_STATS },
  174. { CONTROL('F'), SEL_STATS },
  175. /* Toggle executable status */
  176. { '*', SEL_CHMODX },
  177. /* Create archive */
  178. { 'z', SEL_ARCHIVE },
  179. /* Sort toggles */
  180. { 't', SEL_SORT },
  181. { CONTROL('T'), SEL_SORT },
  182. /* Redraw window */
  183. { CONTROL('L'), SEL_REDRAW },
  184. /* Select current file path */
  185. { CONTROL('J'), SEL_SEL },
  186. { ' ', SEL_SEL },
  187. /* Toggle select multiple files */
  188. { 'm', SEL_SELMUL },
  189. { CONTROL('K'), SEL_SELMUL },
  190. /* Select all files in current dir */
  191. { 'a', SEL_SELALL },
  192. /* List, edit selection */
  193. { 'E', SEL_SELEDIT },
  194. /* Copy from selection buffer */
  195. { 'p', SEL_CP },
  196. { CONTROL('P'), SEL_CP },
  197. /* Move from selection buffer */
  198. { 'v', SEL_MV },
  199. { CONTROL('V'), SEL_MV },
  200. /* Copy/move from selection buffer and rename */
  201. { 'w', SEL_CPMVAS },
  202. { CONTROL('W'), SEL_CPMVAS },
  203. /* Delete from selection buffer */
  204. { 'x', SEL_RM },
  205. { CONTROL('X'), SEL_RM },
  206. /* Open in a custom application */
  207. { 'o', SEL_OPENWITH },
  208. { CONTROL('O'), SEL_OPENWITH },
  209. /* Create a new file */
  210. { 'n', SEL_NEW },
  211. /* Show rename prompt */
  212. { CONTROL('R'), SEL_RENAME },
  213. /* Rename contents of current dir */
  214. { 'r', SEL_RENAMEMUL },
  215. /* Disconnect a SSHFS mount point */
  216. { 'u', SEL_UMOUNT },
  217. /* Show help */
  218. { '?', SEL_HELP },
  219. /* Quit a context */
  220. { '+', SEL_AUTONEXT },
  221. /* Edit in EDITOR */
  222. { 'e', SEL_EDIT },
  223. /* Run a plugin */
  224. { ';', SEL_PLUGIN },
  225. { CONTROL('S'), SEL_PLUGIN },
  226. /* Run command */
  227. { '!', SEL_SHELL },
  228. { CONTROL(']'), SEL_SHELL },
  229. /* Launcher */
  230. { '=', SEL_LAUNCH },
  231. /* Run a command */
  232. { ']', SEL_RUNCMD },
  233. /* Lock screen */
  234. { '0', SEL_LOCK },
  235. /* Manage sessions */
  236. { 's', SEL_SESSIONS },
  237. /* Export list */
  238. { '>', SEL_EXPORT },
  239. /* Set time type */
  240. { 'T', SEL_TIMETYPE },
  241. /* Quit a context */
  242. { 'q', SEL_QUITCTX },
  243. /* Change dir on quit */
  244. { CONTROL('G'), SEL_QUITCD },
  245. /* Quit */
  246. { CONTROL('Q'), SEL_QUIT },
  247. /* Quit with an error code */
  248. { 'Q', SEL_QUITFAIL },
  249. #ifndef NOMOUSE
  250. { KEY_MOUSE, SEL_CLICK },
  251. #endif
  252. };