My build of nnn with minor changes
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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