My build of nnn with minor changes
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

277 行
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-2020, 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) & 0x1f)
  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_BOOKMARK,
  52. SEL_REMOTE,
  53. SEL_CYCLE,
  54. SEL_CYCLER,
  55. SEL_CTX1,
  56. SEL_CTX2,
  57. SEL_CTX3,
  58. SEL_CTX4,
  59. #ifdef CTX8
  60. SEL_CTX5,
  61. SEL_CTX6,
  62. SEL_CTX7,
  63. SEL_CTX8,
  64. #endif
  65. SEL_MARK,
  66. SEL_FLTR,
  67. SEL_MFLTR,
  68. SEL_HIDDEN,
  69. SEL_DETAIL,
  70. SEL_STATS,
  71. SEL_CHMODX,
  72. SEL_ARCHIVE,
  73. SEL_SORT,
  74. SEL_REDRAW,
  75. SEL_SEL,
  76. SEL_SELMUL,
  77. SEL_SELALL,
  78. SEL_SELEDIT,
  79. SEL_CP,
  80. SEL_MV,
  81. SEL_CPMVAS,
  82. SEL_RM,
  83. SEL_OPENWITH,
  84. SEL_NEW,
  85. SEL_RENAME,
  86. SEL_RENAMEMUL,
  87. SEL_UMOUNT,
  88. SEL_HELP,
  89. SEL_AUTONEXT,
  90. SEL_EDIT,
  91. SEL_PLUGIN,
  92. SEL_SHELL,
  93. SEL_LAUNCH,
  94. SEL_RUNCMD,
  95. SEL_LOCK,
  96. SEL_SESSIONS,
  97. SEL_EXPORT,
  98. SEL_TIMETYPE,
  99. SEL_QUITCTX,
  100. SEL_QUITCD,
  101. SEL_QUIT,
  102. SEL_QUITFAIL,
  103. #ifndef NOFIFO
  104. SEL_FIFO,
  105. #endif
  106. #ifndef NOMOUSE
  107. SEL_CLICK,
  108. #endif
  109. };
  110. /* Associate a pressed key to an action */
  111. struct key {
  112. int sym; /* Key pressed */
  113. enum action act; /* Action */
  114. };
  115. static struct key bindings[] = {
  116. /* Back */
  117. { KEY_LEFT, SEL_BACK },
  118. { 'h', SEL_BACK },
  119. /* Inside or select */
  120. { KEY_ENTER, SEL_GOIN },
  121. { '\r', SEL_GOIN },
  122. /* Pure navigate inside */
  123. { KEY_RIGHT, SEL_NAV_IN },
  124. { 'l', SEL_NAV_IN },
  125. /* Next */
  126. { 'j', SEL_NEXT },
  127. { KEY_DOWN, SEL_NEXT },
  128. /* Previous */
  129. { 'k', SEL_PREV },
  130. { KEY_UP, SEL_PREV },
  131. /* Page down */
  132. { KEY_NPAGE, SEL_PGDN },
  133. /* Page up */
  134. { KEY_PPAGE, SEL_PGUP },
  135. /* Ctrl+D */
  136. { CONTROL('D'), SEL_CTRL_D },
  137. /* Ctrl+U */
  138. { CONTROL('U'), SEL_CTRL_U },
  139. /* First entry */
  140. { KEY_HOME, SEL_HOME },
  141. { 'g', SEL_HOME },
  142. { CONTROL('A'), SEL_HOME },
  143. /* Last entry */
  144. { KEY_END, SEL_END },
  145. { 'G', SEL_END },
  146. { CONTROL('E'), SEL_END },
  147. /* Go to first file */
  148. { '\'', SEL_FIRST },
  149. /* HOME */
  150. { '~', SEL_CDHOME },
  151. /* Initial directory */
  152. { '@', SEL_CDBEGIN },
  153. /* Last visited dir */
  154. { '-', SEL_CDLAST },
  155. /* Go to / */
  156. { '`', SEL_CDROOT },
  157. /* Leader key */
  158. { 'b', SEL_BOOKMARK },
  159. { CONTROL('_'), SEL_BOOKMARK },
  160. /* Connect to server over SSHFS */
  161. { 'c', SEL_REMOTE },
  162. /* Cycle contexts in forward direction */
  163. { '\t', SEL_CYCLE },
  164. /* Cycle contexts in reverse direction */
  165. { KEY_BTAB, SEL_CYCLER },
  166. /* Go to/create context N */
  167. { '1', SEL_CTX1 },
  168. { '2', SEL_CTX2 },
  169. { '3', SEL_CTX3 },
  170. { '4', SEL_CTX4 },
  171. #ifdef CTX8
  172. { '5', SEL_CTX5 },
  173. { '6', SEL_CTX6 },
  174. { '7', SEL_CTX7 },
  175. { '8', SEL_CTX8 },
  176. #endif
  177. /* Mark a path to visit later */
  178. { ',', SEL_MARK },
  179. /* Filter */
  180. { '/', SEL_FLTR },
  181. /* Toggle filter mode */
  182. { CONTROL('N'), SEL_MFLTR },
  183. /* Toggle hide .dot files */
  184. { '.', SEL_HIDDEN },
  185. /* Detailed listing */
  186. { 'd', SEL_DETAIL },
  187. /* File details */
  188. { 'f', SEL_STATS },
  189. { CONTROL('F'), SEL_STATS },
  190. /* Toggle executable status */
  191. { '*', SEL_CHMODX },
  192. /* Create archive */
  193. { 'z', SEL_ARCHIVE },
  194. /* Sort toggles */
  195. { 't', SEL_SORT },
  196. { CONTROL('T'), SEL_SORT },
  197. /* Redraw window */
  198. { CONTROL('L'), SEL_REDRAW },
  199. /* Select current file path */
  200. { CONTROL('J'), SEL_SEL },
  201. { ' ', SEL_SEL },
  202. /* Toggle select multiple files */
  203. { 'm', SEL_SELMUL },
  204. { CONTROL('K'), SEL_SELMUL },
  205. /* Select all files in current dir */
  206. { 'a', SEL_SELALL },
  207. /* List, edit selection */
  208. { 'E', SEL_SELEDIT },
  209. /* Copy from selection buffer */
  210. { 'p', SEL_CP },
  211. { CONTROL('P'), SEL_CP },
  212. /* Move from selection buffer */
  213. { 'v', SEL_MV },
  214. { CONTROL('V'), SEL_MV },
  215. /* Copy/move from selection buffer and rename */
  216. { 'w', SEL_CPMVAS },
  217. { CONTROL('W'), SEL_CPMVAS },
  218. /* Delete from selection buffer */
  219. { 'x', SEL_RM },
  220. { CONTROL('X'), SEL_RM },
  221. /* Open in a custom application */
  222. { 'o', SEL_OPENWITH },
  223. { CONTROL('O'), SEL_OPENWITH },
  224. /* Create a new file */
  225. { 'n', SEL_NEW },
  226. /* Show rename prompt */
  227. { CONTROL('R'), SEL_RENAME },
  228. /* Rename contents of current dir */
  229. { 'r', SEL_RENAMEMUL },
  230. /* Disconnect a SSHFS mount point */
  231. { 'u', SEL_UMOUNT },
  232. /* Show help */
  233. { '?', SEL_HELP },
  234. /* Quit a context */
  235. { '+', SEL_AUTONEXT },
  236. /* Edit in EDITOR */
  237. { 'e', SEL_EDIT },
  238. /* Run a plugin */
  239. { ';', SEL_PLUGIN },
  240. /* Run command */
  241. { '!', SEL_SHELL },
  242. { CONTROL(']'), SEL_SHELL },
  243. /* Launcher */
  244. { '=', SEL_LAUNCH },
  245. /* Run a command */
  246. { ']', SEL_RUNCMD },
  247. /* Lock screen */
  248. { '0', SEL_LOCK },
  249. /* Manage sessions */
  250. { 's', SEL_SESSIONS },
  251. /* Export list */
  252. { '>', SEL_EXPORT },
  253. /* Set time type */
  254. { 'T', SEL_TIMETYPE },
  255. /* Quit a context */
  256. { 'q', SEL_QUITCTX },
  257. /* Change dir on quit */
  258. { CONTROL('G'), SEL_QUITCD },
  259. /* Quit */
  260. { CONTROL('Q'), SEL_QUIT },
  261. /* Quit with an error code */
  262. { 'Q', SEL_QUITFAIL },
  263. #ifndef NOFIFO
  264. /* Send hovered path to NNN_FIFO */
  265. { 27, SEL_FIFO },
  266. #endif
  267. #ifndef NOMOUSE
  268. { KEY_MOUSE, SEL_CLICK },
  269. #endif
  270. };