My build of nnn with minor changes
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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