My build of nnn with minor changes
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

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