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.
 
 
 
 
 
 

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