My build of nnn with minor changes
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

262 satır
6.8 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_MEDIA,
  64. SEL_FMEDIA,
  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_MTIME,
  72. SEL_WILD,
  73. SEL_REDRAW,
  74. SEL_COPY,
  75. SEL_COPYMUL,
  76. SEL_COPYALL,
  77. SEL_COPYLIST,
  78. SEL_CP,
  79. SEL_MV,
  80. SEL_RMMUL,
  81. SEL_RM,
  82. SEL_OPENWITH,
  83. SEL_NEW,
  84. SEL_RENAME,
  85. SEL_RENAMEALL,
  86. SEL_SSHFS,
  87. SEL_UMOUNT,
  88. SEL_HELP,
  89. SEL_EXEC,
  90. SEL_SHELL,
  91. SEL_PLUGIN,
  92. SEL_LAUNCH,
  93. SEL_RUNCMD,
  94. SEL_RUNEDIT,
  95. SEL_RUNPAGE,
  96. SEL_NOTE,
  97. SEL_LOCK,
  98. SEL_QUITCTX,
  99. SEL_QUITCD,
  100. SEL_QUIT,
  101. SEL_CLICK,
  102. };
  103. /* Associate a pressed key to an action */
  104. struct key {
  105. int sym; /* Key pressed */
  106. enum action act; /* Action */
  107. };
  108. static struct key bindings[] = {
  109. /* Back */
  110. { KEY_LEFT, SEL_BACK },
  111. { 'h', SEL_BACK },
  112. /* Inside or select */
  113. { KEY_ENTER, SEL_GOIN },
  114. { '\r', SEL_GOIN },
  115. /* Pure navigate inside */
  116. { KEY_RIGHT, SEL_NAV_IN },
  117. { 'l', SEL_NAV_IN },
  118. /* Next */
  119. { 'j', SEL_NEXT },
  120. { KEY_DOWN, SEL_NEXT },
  121. /* Previous */
  122. { 'k', SEL_PREV },
  123. { KEY_UP, SEL_PREV },
  124. /* Page down */
  125. { KEY_NPAGE, SEL_PGDN },
  126. /* Page up */
  127. { KEY_PPAGE, SEL_PGUP },
  128. /* Ctrl+D */
  129. { CONTROL('D'), SEL_CTRL_D },
  130. /* Ctrl+U */
  131. { CONTROL('U'), SEL_CTRL_U },
  132. /* First entry */
  133. { KEY_HOME, SEL_HOME },
  134. { 'g', SEL_HOME },
  135. { CONTROL('A'), SEL_HOME },
  136. /* Last entry */
  137. { KEY_END, SEL_END },
  138. { 'G', SEL_END },
  139. { CONTROL('E'), SEL_END },
  140. /* HOME */
  141. { '~', SEL_CDHOME },
  142. /* Initial directory */
  143. { '@', SEL_CDBEGIN },
  144. /* Last visited dir */
  145. { '-', SEL_CDLAST },
  146. /* Go to / */
  147. { '`', SEL_CDROOT },
  148. /* Visit marked directory */
  149. { CONTROL('B'), SEL_VISIT },
  150. /* Leader key */
  151. { CONTROL('_'), SEL_LEADER },
  152. { ',', SEL_LEADER },
  153. /* Cycle contexts in forward direction */
  154. { '\t', SEL_CYCLE },
  155. { CONTROL('I'), SEL_CYCLE },
  156. /* Go to/create context N */
  157. { '1', SEL_CTX1 },
  158. { '2', SEL_CTX2 },
  159. { '3', SEL_CTX3 },
  160. { '4', SEL_CTX4 },
  161. /* Mark a path to visit later */
  162. { 'b', SEL_PIN },
  163. /* Filter */
  164. { '/', SEL_FLTR },
  165. /* Toggle filter mode */
  166. { KEY_IC, SEL_MFLTR },
  167. { CONTROL('T'), SEL_MFLTR },
  168. /* Toggle hide .dot files */
  169. { '.', SEL_TOGGLEDOT },
  170. /* Detailed listing */
  171. { 'd', SEL_DETAIL },
  172. /* File details */
  173. { 'D', SEL_STATS },
  174. /* Show media info short, run is hacked */
  175. { 'm', SEL_MEDIA },
  176. /* Show media info full, run is hacked */
  177. { 'M', SEL_FMEDIA },
  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. { 'S', SEL_ASIZE },
  188. /* Sort by total block count including dir contents */
  189. { CONTROL('J'), SEL_BSIZE },
  190. /* Toggle sort by time */
  191. { 't', SEL_MTIME },
  192. /* Wild load */
  193. { CONTROL('W'), SEL_WILD },
  194. /* Redraw window */
  195. { CONTROL('L'), SEL_REDRAW },
  196. /* Copy currently selected file path */
  197. { CONTROL('K'), SEL_COPY },
  198. { ' ', SEL_COPY },
  199. /* Toggle copy multiple file paths */
  200. { 'K', SEL_COPYMUL },
  201. { CONTROL('Y'), SEL_COPYMUL },
  202. /* Select all files in current dir */
  203. { 'Y', SEL_COPYALL },
  204. /* Show list of copied files */
  205. { 'y', SEL_COPYLIST },
  206. /* Copy from copy buffer */
  207. { 'P', SEL_CP },
  208. /* Move from copy buffer */
  209. { 'V', SEL_MV },
  210. /* Delete from copy buffer */
  211. { 'X', SEL_RMMUL },
  212. /* Delete currently selected */
  213. { CONTROL('X'), SEL_RM },
  214. /* Open in a custom application */
  215. { CONTROL('O'), SEL_OPENWITH },
  216. /* Create a new file */
  217. { 'n', SEL_NEW },
  218. /* Show rename prompt */
  219. { CONTROL('R'), SEL_RENAME },
  220. /* Rename contents of current dir */
  221. { 'r', SEL_RENAMEALL },
  222. /* Connect to server over SSHFS */
  223. { 'c', SEL_SSHFS },
  224. /* Disconnect a SSHFS mount point */
  225. { 'u', SEL_UMOUNT },
  226. /* Show help */
  227. { '?', SEL_HELP },
  228. /* Execute file */
  229. { 'C', SEL_EXEC },
  230. /* Run command */
  231. { '!', SEL_SHELL },
  232. { CONTROL(']'), SEL_SHELL },
  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. };