My build of nnn with minor changes
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

267 行
7.0 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_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_VISIT,
  52. SEL_LEADER,
  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_TOGGLEDOT,
  63. SEL_DETAIL,
  64. SEL_STATS,
  65. SEL_ARCHIVE,
  66. SEL_ARCHIVELS,
  67. SEL_EXTRACT,
  68. SEL_FSIZE, /* file size */
  69. SEL_ASIZE, /* apparent size */
  70. SEL_BSIZE, /* block size */
  71. SEL_EXTN, /* order by extension */
  72. SEL_MTIME,
  73. SEL_REDRAW,
  74. SEL_SEL,
  75. SEL_SELMUL,
  76. SEL_SELALL,
  77. SEL_SELLST,
  78. SEL_SELEDIT,
  79. SEL_CP,
  80. SEL_MV,
  81. SEL_RMMUL,
  82. SEL_RM,
  83. SEL_OPENWITH,
  84. SEL_NEW,
  85. SEL_RENAME,
  86. SEL_RENAMEMUL,
  87. SEL_SSHFS,
  88. SEL_UMOUNT,
  89. SEL_HELP,
  90. SEL_EXEC,
  91. SEL_SHELL,
  92. SEL_PLUGKEY,
  93. SEL_PLUGIN,
  94. SEL_LAUNCH,
  95. SEL_RUNCMD,
  96. SEL_RUNEDIT,
  97. SEL_RUNPAGE,
  98. SEL_LOCK,
  99. SEL_QUITCTX,
  100. SEL_QUITCD,
  101. SEL_QUIT,
  102. SEL_CLICK,
  103. };
  104. /* Associate a pressed key to an action */
  105. struct key {
  106. int sym; /* Key pressed */
  107. enum action act; /* Action */
  108. };
  109. static struct key bindings[] = {
  110. /* Back */
  111. { KEY_LEFT, SEL_BACK },
  112. { 'h', SEL_BACK },
  113. /* Inside or select */
  114. { KEY_ENTER, SEL_GOIN },
  115. { '\r', SEL_GOIN },
  116. /* Pure navigate inside */
  117. { KEY_RIGHT, SEL_NAV_IN },
  118. { 'l', SEL_NAV_IN },
  119. /* Next */
  120. { 'j', SEL_NEXT },
  121. { KEY_DOWN, SEL_NEXT },
  122. /* Previous */
  123. { 'k', SEL_PREV },
  124. { KEY_UP, SEL_PREV },
  125. /* Page down */
  126. { KEY_NPAGE, SEL_PGDN },
  127. /* Page up */
  128. { KEY_PPAGE, SEL_PGUP },
  129. /* Ctrl+D */
  130. { CONTROL('D'), SEL_CTRL_D },
  131. /* Ctrl+U */
  132. { CONTROL('U'), SEL_CTRL_U },
  133. /* First entry */
  134. { KEY_HOME, SEL_HOME },
  135. { 'g', SEL_HOME },
  136. { CONTROL('A'), SEL_HOME },
  137. /* Last entry */
  138. { KEY_END, SEL_END },
  139. { 'G', SEL_END },
  140. { CONTROL('E'), SEL_END },
  141. /* Go to first file */
  142. { '\'', SEL_FIRST },
  143. /* HOME */
  144. { '~', SEL_CDHOME },
  145. /* Initial directory */
  146. { '@', SEL_CDBEGIN },
  147. /* Last visited dir */
  148. { '-', SEL_CDLAST },
  149. /* Go to / */
  150. { '`', SEL_CDROOT },
  151. /* Visit marked directory */
  152. { CONTROL('B'), SEL_VISIT },
  153. /* Leader key */
  154. { CONTROL('_'), SEL_LEADER },
  155. { ',', SEL_LEADER },
  156. /* Cycle contexts in forward direction */
  157. { '\t', SEL_CYCLE },
  158. /* Cycle contexts in reverse direction */
  159. { KEY_BTAB, SEL_CYCLER },
  160. /* Go to/create context N */
  161. { '1', SEL_CTX1 },
  162. { '2', SEL_CTX2 },
  163. { '3', SEL_CTX3 },
  164. { '4', SEL_CTX4 },
  165. /* Mark a path to visit later */
  166. { 'b', SEL_PIN },
  167. /* Filter */
  168. { '/', SEL_FLTR },
  169. /* Toggle filter mode */
  170. { KEY_IC, SEL_MFLTR },
  171. { CONTROL('N'), SEL_MFLTR },
  172. /* Toggle hide .dot files */
  173. { '.', SEL_TOGGLEDOT },
  174. /* Detailed listing */
  175. { 'd', SEL_DETAIL },
  176. /* File details */
  177. { 'D', SEL_STATS },
  178. /* Create archive */
  179. { 'f', SEL_ARCHIVE },
  180. /* List archive */
  181. { 'F', SEL_ARCHIVELS },
  182. /* Extract archive */
  183. { CONTROL('F'), SEL_EXTRACT },
  184. /* Toggle sort by size */
  185. { 's', SEL_FSIZE },
  186. /* Sort by apparent size including dir contents */
  187. { 'A', SEL_ASIZE },
  188. /* Sort by total block count including dir contents */
  189. { 'S', SEL_BSIZE },
  190. /* Sort by file extension */
  191. { 'E', SEL_EXTN },
  192. /* Toggle sort by time */
  193. { 't', SEL_MTIME },
  194. /* Redraw window */
  195. { CONTROL('L'), SEL_REDRAW },
  196. { KEY_F(5), SEL_REDRAW },
  197. /* Select current file path */
  198. { CONTROL('J'), SEL_SEL },
  199. { ' ', SEL_SEL },
  200. /* Toggle select multiple files */
  201. { 'm', SEL_SELMUL },
  202. { CONTROL('K'), SEL_SELMUL },
  203. /* Select all files in current dir */
  204. { 'a', SEL_SELALL },
  205. /* Show list of copied files */
  206. { 'M', SEL_SELLST },
  207. /* Edit selection buffer */
  208. { 'K', SEL_SELEDIT },
  209. /* Copy from selection buffer */
  210. { 'P', SEL_CP },
  211. /* Move from selection buffer */
  212. { 'V', SEL_MV },
  213. /* Delete from selection buffer */
  214. { 'X', SEL_RMMUL },
  215. /* Delete currently selected */
  216. { CONTROL('X'), SEL_RM },
  217. /* Open in a custom application */
  218. { CONTROL('O'), SEL_OPENWITH },
  219. /* Create a new file */
  220. { 'n', SEL_NEW },
  221. /* Show rename prompt */
  222. { CONTROL('R'), SEL_RENAME },
  223. { KEY_F(2), SEL_RENAME },
  224. /* Rename contents of current dir */
  225. { 'r', SEL_RENAMEMUL },
  226. /* Connect to server over SSHFS */
  227. { 'c', SEL_SSHFS },
  228. /* Disconnect a SSHFS mount point */
  229. { 'u', SEL_UMOUNT },
  230. /* Show help */
  231. { '?', SEL_HELP },
  232. /* Execute file */
  233. { 'C', SEL_EXEC },
  234. /* Run command */
  235. { '!', SEL_SHELL },
  236. { CONTROL(']'), SEL_SHELL },
  237. /* Plugin key */
  238. { 'x', SEL_PLUGKEY },
  239. { ':', SEL_PLUGKEY },
  240. /* Run a plugin */
  241. { 'R', SEL_PLUGIN },
  242. { CONTROL('V'), SEL_PLUGIN },
  243. /* Launcher */
  244. { '=', SEL_LAUNCH },
  245. /* Run a command */
  246. { CONTROL('P'), SEL_RUNCMD },
  247. /* Open in EDITOR or PAGER */
  248. { 'e', SEL_RUNEDIT },
  249. { 'p', SEL_RUNPAGE },
  250. /* Lock screen */
  251. { 'L', SEL_LOCK },
  252. /* Quit a context */
  253. { 'q', SEL_QUITCTX },
  254. /* Change dir on quit */
  255. { CONTROL('G'), SEL_QUITCD },
  256. /* Quit */
  257. { 'Q', SEL_QUIT },
  258. { CONTROL('Q'), SEL_QUIT },
  259. { KEY_MOUSE, SEL_CLICK },
  260. };