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.
 
 
 
 
 
 

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