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

230 行
7.5 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_NEXT,
  38. SEL_PREV,
  39. SEL_PGDN,
  40. SEL_PGUP,
  41. SEL_HOME,
  42. SEL_END,
  43. SEL_CD,
  44. SEL_CDHOME,
  45. SEL_CDBEGIN,
  46. SEL_CDLAST,
  47. SEL_CDBM,
  48. SEL_PIN,
  49. SEL_VISIT,
  50. SEL_FLTR,
  51. SEL_MFLTR,
  52. SEL_SEARCH,
  53. SEL_TOGGLEDOT,
  54. SEL_DETAIL,
  55. SEL_STATS,
  56. SEL_MEDIA,
  57. SEL_FMEDIA,
  58. SEL_DFB,
  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_QUOTE,
  71. SEL_OPEN,
  72. SEL_NEW,
  73. SEL_RENAME,
  74. SEL_RENAMEALL,
  75. SEL_HELP,
  76. SEL_RUN,
  77. SEL_RUNSCRIPT,
  78. SEL_RUNARG,
  79. SEL_LOCK,
  80. SEL_CDQUIT,
  81. SEL_QUIT,
  82. };
  83. /* Associate a pressed key to an action */
  84. struct key {
  85. int sym; /* Key pressed */
  86. enum action act; /* Action */
  87. char *run; /* Program to run or program option */
  88. char *env; /* Environment variable to run */
  89. };
  90. /* Extension pattern and mime combination */
  91. struct assoc {
  92. char *regex; /* Regex to match on filename */
  93. char *mime; /* File type */
  94. };
  95. static struct assoc assocs[] = {
  96. { "\\.(c|cpp|h|log|md|py|rb|sh|txt)$", "text" },
  97. };
  98. static struct key bindings[] = {
  99. /* Back */
  100. { KEY_BACKSPACE, SEL_BACK, "", "" },
  101. { 8 /* BS */, SEL_BACK, "", "" },
  102. { 127 /* DEL */, SEL_BACK, "", "" },
  103. { KEY_LEFT, SEL_BACK, "", "" },
  104. { 'h', SEL_BACK, "", "" },
  105. { CONTROL('H'), SEL_BACK, "", "" },
  106. /* Inside */
  107. { KEY_ENTER, SEL_GOIN, "", "" },
  108. { '\r', SEL_GOIN, "", "" },
  109. { KEY_RIGHT, SEL_GOIN, "", "" },
  110. { 'l', SEL_GOIN, "", "" },
  111. /* Next */
  112. { 'j', SEL_NEXT, "", "" },
  113. { KEY_DOWN, SEL_NEXT, "", "" },
  114. { CONTROL('N'), SEL_NEXT, "", "" },
  115. /* Previous */
  116. { 'k', SEL_PREV, "", "" },
  117. { KEY_UP, SEL_PREV, "", "" },
  118. { CONTROL('P'), SEL_PREV, "", "" },
  119. /* Page down */
  120. { KEY_NPAGE, SEL_PGDN, "", "" },
  121. { CONTROL('D'), SEL_PGDN, "", "" },
  122. /* Page up */
  123. { KEY_PPAGE, SEL_PGUP, "", "" },
  124. { CONTROL('U'), SEL_PGUP, "", "" },
  125. /* First entry */
  126. { KEY_HOME, SEL_HOME, "", "" },
  127. { 'g', SEL_HOME, "", "" },
  128. { CONTROL('A'), SEL_HOME, "", "" },
  129. { '^', SEL_HOME, "", "" },
  130. /* Last entry */
  131. { KEY_END, SEL_END, "", "" },
  132. { 'G', SEL_END, "", "" },
  133. { CONTROL('E'), SEL_END, "", "" },
  134. { '$', SEL_END, "", "" },
  135. /* Change dir */
  136. { 'c', SEL_CD, "", "" },
  137. /* HOME */
  138. { '~', SEL_CDHOME, "", "" },
  139. /* Initial directory */
  140. { '&', SEL_CDBEGIN, "", "" },
  141. /* Last visited dir */
  142. { '-', SEL_CDLAST, "", "" },
  143. /* Change dir using bookmark */
  144. { CONTROL('B'), SEL_CDBM, "", "" },
  145. /* Mark a path to visit later */
  146. { 'b', SEL_PIN, "", "" },
  147. /* Visit marked directory */
  148. { CONTROL('V'), SEL_VISIT, "", "" },
  149. /* Filter */
  150. { '/', SEL_FLTR, "", "" },
  151. /* Toggle filter mode */
  152. { KEY_IC, SEL_MFLTR, "", "" },
  153. { CONTROL('I'), SEL_MFLTR, "", "" },
  154. /* Desktop search */
  155. { CONTROL('_'), SEL_SEARCH, "", "" },
  156. /* Toggle hide .dot files */
  157. { '.', SEL_TOGGLEDOT, "", "" },
  158. /* Detailed listing */
  159. { 'd', SEL_DETAIL, "", "" },
  160. /* File details */
  161. { 'D', SEL_STATS, "", "" },
  162. /* Show media info short, run is hacked */
  163. { 'm', SEL_MEDIA, NULL, "" },
  164. /* Show media info full, run is hacked */
  165. { 'M', SEL_FMEDIA, "-f", "" },
  166. /* Open dir in desktop file manager */
  167. { 'o', SEL_DFB, "", "" },
  168. /* Create archive */
  169. { 'f', SEL_ARCHIVE, "", "" },
  170. /* List archive */
  171. { 'F', SEL_LIST, "-l", "" },
  172. /* Extract archive */
  173. { CONTROL('F'), SEL_EXTRACT, "-x", "" },
  174. /* Toggle sort by size */
  175. { 's', SEL_FSIZE, "", "" },
  176. /* Sort by apparent size including dir contents */
  177. { 'S', SEL_ASIZE, "", "" },
  178. /* Sort by total block count including dir contents */
  179. { CONTROL('J'), SEL_BSIZE, "", "" },
  180. /* Toggle sort by time */
  181. { 't', SEL_MTIME, "", "" },
  182. /* Redraw window */
  183. { CONTROL('L'), SEL_REDRAW, "", "" },
  184. { KEY_F(5), SEL_REDRAW, "", "" }, /* Undocumented */
  185. /* Copy currently selected file path */
  186. { CONTROL('K'), SEL_COPY, "", "" },
  187. { ' ', SEL_COPY, "", "" },
  188. /* Toggle copy multiple file paths */
  189. { CONTROL('Y'), SEL_COPYMUL, "", "" },
  190. /* Show list of copied files */
  191. { 'y', SEL_COPYLIST, "", "" },
  192. /* Toggle quote on while copy */
  193. { CONTROL('T'), SEL_QUOTE, "", "" },
  194. /* Open in a custom application */
  195. { CONTROL('O'), SEL_OPEN, "", "" },
  196. /* Create a new file */
  197. { 'n', SEL_NEW, "", "" },
  198. /* Show rename prompt */
  199. { CONTROL('R'), SEL_RENAME, "", "" },
  200. { KEY_F(2), SEL_RENAME, "", "" }, /* Undocumented */
  201. /* Rename contents of current dir */
  202. { 'r', SEL_RENAMEALL, "", "" },
  203. /* Show help */
  204. { '?', SEL_HELP, "", "" },
  205. /* Run command */
  206. { '!', SEL_RUN, "sh", "SHELL" },
  207. { CONTROL(']'), SEL_RUN, "sh", "SHELL" },
  208. /* Run a custom script */
  209. { 'R', SEL_RUNSCRIPT, "sh", "SHELL" },
  210. /* Run command with argument */
  211. { 'e', SEL_RUNARG, "", "VISUAL" },
  212. { 'p', SEL_RUNARG, "less", "PAGER" },
  213. /* Lock screen */
  214. { 'L', SEL_LOCK, "", "" },
  215. /* Change dir on quit */
  216. { 'Q', SEL_CDQUIT, "", "" },
  217. { CONTROL('G'), SEL_CDQUIT, "", "" },
  218. /* Quit */
  219. { 'q', SEL_QUIT, "", "" },
  220. { CONTROL('X'), SEL_QUIT, "", "" },
  221. };