prompt.tin 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 本文件属于 PaoTin++ 的一部分。
  4. PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  5. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  6. */
  7. #var lib_ui_prompt[META] {
  8. {NAME} {提示栏插件}
  9. {DESC} {支持丰富的自定义选项,用户可用此模块定制自己的 UI。}
  10. {AUTHOR} {担子炮}
  11. };
  12. ///=== {
  13. ///// prompt 是 PaoTin++ 中非常重要的 UI 插件,现行 UI 的主要元素都是由 prompt 来支撑的。
  14. /////
  15. ///// prompt 插件把整个 TinTin++ 屏幕划分为七个区域,从上到下依次为:
  16. /////
  17. ///// Top line1
  18. ///// Top line2
  19. ///// ...
  20. ///// Top lineN
  21. ///// ----------- TopSepBar --------------
  22. ///// (游戏区)
  23. ///// ----------- MidSepBar --------------
  24. ///// Bot line1
  25. ///// Bot line2
  26. ///// ...
  27. ///// Bot lineN
  28. ///// ----------- BotSepBar --------------
  29. ///// <提示符>:(输入区)
  30. /////
  31. ///// 输入区前面的提示符部分可以用 API prompt.Change 来修改。
  32. /////
  33. ///// 除输入区和游戏区之外,剩下五个区域都可以定制,用来显示信息内容(以下称为字段)。
  34. ///// 每一行都可以有多个字段。字段在视觉上由两部分组成,字段标签和字段内容。
  35. ///// 其显示样式分别可以控制,并受到几个 prompt 特性的影响,下面会分别予以介绍。
  36. /////
  37. ///// 字段的编排是高度可定制的,每个字段的标签、内容、颜色、显示风格、行为属性,
  38. ///// 都可以通过自己修改 #list prompt-fields 来修改。下面是对 #list prompt-fields
  39. ///// 的格式说明,但不建议直接在此处修改变量,请通过 var/etc/ui-settings.tin 来修改。
  40. ///// prompt 模块在启动时会自动加载该文件。
  41. /////
  42. ///// #list prompt-fields 是一个列表,其中中每个元素是一个 tt++ table,代表一个字段。
  43. ///// tt++ table 由一组选项和与之对应的选项值来组成,用来说明想要定制的字段的选项。
  44. /////
  45. ///// 下面是所有可供设置的字段选项:
  46. /////
  47. ///// 1. place 枚举值 可选项: {Top|TopSepBar|MidSepBar|Bot|BotSepBar}
  48. ///// 希望将字段显示在屏幕上的什么位置。
  49. ///// 其中 {Top} 和 {Bot} 支持多行,其它三个只有一行。
  50. ///// 默认为 BotSepBar。
  51. /////
  52. ///// 2. line 自然数
  53. ///// 只有 place={Top|Bot} 才支持 line,代表第几行,最上面是第一行。
  54. ///// 默认为 1。
  55. /////
  56. ///// 3. order 自然数
  57. ///// 在同一行中的次序,默认按照在 list 中出现的顺序来排序。
  58. /////
  59. ///// 4. label 中英文字符串
  60. ///// 字段标签,每个字段都可以有一个标签,显示在内容前面。
  61. ///// 默认为空白。
  62. /////
  63. ///// 5. color tintin 格式的颜色代码,例如 <ddd>
  64. ///// 字段值的颜色,通过该选项可以为字段值指定一个与配色主题不一样的颜色。
  65. ///// 一般来说只有极个别选项才需要特别的颜色,没必要为每个选项都指定颜色,
  66. ///// 因为那样的话你还不如去设置配色主题,参见下面配色主题的设置。
  67. ///// 默认为空白,代表采用配色主题。
  68. /////
  69. ///// 6. name 英文字符串 不能为空
  70. ///// 字段名称,必须唯一,不能重复。
  71. /////
  72. ///// 7. width 整数
  73. ///// 字段内容的宽度,如果字段内容长度变化较大,可以设置一个固定宽度,以免晃动。
  74. ///// 默认为 0,表示按照内容长度自动适配。
  75. /////
  76. ///// 8. visibility 枚举值 {HideEmpty|HideCool|HideZero|HideLabel|Always}
  77. ///// 含义如下:
  78. ///// * HideEmpty 如果字段内容为空则不予显示。
  79. ///// * HideCool 如果内容已陈旧则不予显示。请参考 cooldown 选项。
  80. ///// * HideZero 如果倒计时归零则不予显示。请参考 countdown 选项。
  81. ///// * HideLabel 仅显示字段内容,不显示字段标签。
  82. ///// * Always 总是显示该字段的标签和内容。
  83. ///// 所有的 Hide* 选项自动拥有 HideEmpty 语义。
  84. ///// 默认为 HideEmpty。
  85. /////
  86. ///// 9. cooldown 非负整数
  87. ///// 该字段的有效时间。超过有效时间没有更新的字段将在视觉上予以弱化显示,以提醒
  88. ///// 用户。也就是说,如果 cooldown 不为 0,则该字段被更新时其标签将会以颜色主题
  89. ///// 中 HotLabel 所指定的风格显示(意指新鲜的内容),之后持续若干秒后,转为由
  90. ///// CoolLabel 所指定的风格显示(意指陈旧的内容)。
  91. ///// 持续时间由 cooldown 字段的值来决定,单位为秒。
  92. ///// 陈旧的内容遇到 visibility=HideCool 时则不予显示。
  93. ///// 如果 cooldown 为 0,则不会以 CoolLabel 风格显示。
  94. ///// 默认值为 0。
  95. /////
  96. ///// 10. countdown 枚举值 {Auto|Clock|Seconds}
  97. ///// 倒计时类型的字段。其内容为一个非负整数,代表需要倒计时的秒数,或者也可以夹杂
  98. ///// 于文字内容当中,此时文字内容中所有形如 (%d) 的内容将会被替换成倒计时显示。
  99. ///// 本插件会自动为该字段更新其内容,使得用户能够看到倒计时的效果。
  100. ///// 倒计时有两种显示样式,本选项设置为 Clock 时,显示为时钟样式(N天HH:MM:SS),
  101. ///// 设置为 Seconds 时,显示为读秒样式(N秒)。设置为 Auto 时则根据剩余时间长短,
  102. ///// 自动切换两种显示效果。
  103. ///// 倒计时类型的字段,如果同时设置了 visibility=HideZero,那么倒计时归零后会自动
  104. ///// 隐藏该字段。
  105. ///// 在倒计时存续期间,该字段的 cooldown 属性将会被抑制,直到倒计时归零后才起作用。
  106. ///// 这条规则确保倒计时字段即使设置了 visibility=HideCool,也至少会完成倒计时,而
  107. ///// 倒计时结束后,如果 cooldown 时间比倒计时时间还要长,则还会继续显示一段时间之
  108. ///// 后才会被隐藏。
  109. // };
  110. VAR {信息栏的字段列表} prompt-fields {};
  111. VAR {信息栏的默认配色主题} prompt-theme {
  112. {Disable}{<bbc>}
  113. {BusyColor}{<239>}
  114. {BattleColor}{<119>}
  115. {BattleBusyColor}{<599><119>}
  116. {TopSepBar}{<229>}
  117. {MidSepBar}{<229>}
  118. {BotSepBar}{<229>}
  119. {HotLabel}{<199><F399>}
  120. {CoolLabel}{<109>}
  121. {Value}{<299>}
  122. };
  123. VAR {信息栏的填充字符} prompt-padding {─};
  124. VAR {常用图标} prompt-icon {
  125. {DisableRefresh}{🚫}
  126. };
  127. VAR {热键绑定} global-key-bindings {
  128. {1} {{key}{\cos} {action}{prompt.ToggleSwitch}}
  129. };
  130. VAR {信息栏的顶部高度(自动计算)} prompt-top-max-line {0};
  131. VAR {信息栏的底部高度(自动计算)} prompt-bot-max-line {0};
  132. VAR {屏幕的宽度(自动更新)} prompt-screen-width {0};
  133. VAR {所有的字段值的字典} prompt-dict {};
  134. VAR {上次实际绘制屏幕的时间} prompt-refresh {
  135. {global}{false}
  136. {lines} {false}
  137. {prompt}{false}
  138. };
  139. VAR {命令输入提示符} prompt-prompt {Input};
  140. #func {lib_ui_prompt.Init} {
  141. load-file {etc/ui-settings.tin};
  142. #if { "@getenv{TERM_PROGRAM}" == "vscode" && "@getenv{TERM_PROGRAM_VERSION}" <= "1.81.1" } {
  143. #if { "$prompt-padding" == "─" } {
  144. #var prompt-padding {-};
  145. };
  146. };
  147. #local _ @prompt.ScreenWidth{};
  148. prompt.Set {};
  149. prompt.bindKey;
  150. prompt.Enable;
  151. ttevent.Handle {SCREEN RESIZE} {prompt} {lib/ui} {prompt.resize};
  152. #return true;
  153. };
  154. ///=== {
  155. ///// 下面是本模块的一些常用方法:
  156. /////
  157. // ## prompt.Set <表格>
  158. // 将表格中指定的字段和值,设置到 prompt 字典中。如果配置文件中存在该字段的配置,
  159. // 则会显示到屏幕上。
  160. //
  161. // 参数是一个由字段名和字段值组成的表格,例如:
  162. //
  163. // #nop 为 note 字段设置值。;
  164. // prompt.Set {{note}{我是一条随手笔记}};
  165. //
  166. // #nop 对大多数字段而言,将值设置为空会隐藏该字段。;
  167. // prompt.Set {{note}{}};
  168. //
  169. // #nop 也可同时为多个字段设置值。;
  170. // prompt.Set {{foo}{一些值} {bar}{另一些值}};
  171. // };
  172. #alias {prompt.Set} {
  173. #local fields {%1};
  174. #local now {};
  175. #format now {%T};
  176. #local field {};
  177. #foreach {*fields[]} {field} {
  178. #var prompt-dict[$field] {
  179. {updateTime}{$now}
  180. {showTime}{$now}
  181. {value}{$fields[$field]}
  182. };
  183. };
  184. };
  185. ///=== {
  186. // ## prompt.SetAwhile <字段名> <字段值> [<持续时间>]
  187. // 设置字段值,被设置的字段值将立即显示在屏幕上,但会在一段时间后消失。
  188. // 如果省略持续时间,则默认为 5 秒。
  189. // };
  190. #alias {prompt.SetAwhile} {
  191. #local id {%1};
  192. #local value {%2};
  193. #local secs {%3};
  194. #if { "$secs" == "" } {
  195. #local secs {5};
  196. };
  197. prompt.Set {{$id}{$value}};
  198. #line sub {VARIABLES} {
  199. #delay prompt-set-awhile-$id {
  200. prompt.Set {{$id}{}};
  201. } {$secs};
  202. };
  203. };
  204. #nop 备份的之前的内容,只有新内容与当前正在显示的内容不同时,才会刷新。;
  205. #var prompt.current-content {};
  206. #nop 显示字段值;
  207. #alias {prompt.refresh} {
  208. #local topMaxLine {0};
  209. #local botMaxLine {0};
  210. #local topLines {};
  211. #local botLines {};
  212. #local topSepBar {};
  213. #local midSepBar {};
  214. #local botSepBar {};
  215. #foreach {*prompt-fields[]} {idx} {
  216. #local field {$prompt-fields[$idx]};
  217. #nop 如果全局开关已经禁用,则跳过所有字段,除了 BotSepBar;
  218. #if { "$prompt-dict[disable][value]" != "" } {
  219. #if { "$field[place]" != "BotSepBar" } {
  220. #continue;
  221. };
  222. };
  223. #if { "$field[visibility]" == "" } {
  224. #local field[visibility] {HideEmpty};
  225. };
  226. #switch {"$field[place]"} {
  227. #case {"Top"} {
  228. #while {1} {
  229. #if { $field[line] <= $topMaxLine } {
  230. #break;
  231. };
  232. #math topMaxLine {$topMaxLine + 1};
  233. #local topLines[$topMaxLine] {};
  234. };
  235. #if { "$field[order]" == "" } {
  236. #local field[order] {@math.Eval{ @math.Max{0;*topLines[$field[line]][]} + 1 }};
  237. };
  238. #local topLines[$field[line]][$field[order]] {$field};
  239. };
  240. #case {"Bot"} {
  241. #while {1} {
  242. #if { $field[line] <= $botMaxLine } {
  243. #break;
  244. };
  245. #math botMaxLine {$botMaxLine + 1};
  246. #local botLines[$botMaxLine] {};
  247. };
  248. #if { "$field[order]" == "" } {
  249. #local field[order] {@math.Eval{ @math.Max{0;*botLines[$field[line]][]} + 1 }};
  250. };
  251. #local botLines[$field[line]][$field[order]] {$field};
  252. };
  253. #case {"TopSepBar"} {
  254. #if { "$field[order]" == "" } {
  255. #local field[order] {@math.Eval{ @math.Max{0;*topSepBar[]} + 1 }};
  256. };
  257. #local topSepBar[$field[order]] {$field};
  258. };
  259. #case {"MidSepBar"} {
  260. #if { "$field[order]" == "" } {
  261. #local field[order] {@math.Eval{ @math.Max{0;*midSepBar[]} + 1 }};
  262. };
  263. #local midSepBar[$field[order]] {$field};
  264. };
  265. #case {"BotSepBar"} {
  266. #if { "$field[order]" == "" } {
  267. #local field[order] {@math.Eval{ @math.Max{0;*botSepBar[]} + 1 }};
  268. };
  269. #local botSepBar[$field[order]] {$field};
  270. };
  271. #default {
  272. #echo {配置有误,请检查。place=[%s]} {$field[place]};
  273. };
  274. };
  275. };
  276. #local allBarColor {};
  277. #if { "$prompt-dict[busy][value]" == "true" } {
  278. #local allBarColor {$prompt-theme[BusyColor]};
  279. };
  280. #if { "$prompt-dict[battle][value]" == "true" } {
  281. #local allBarColor {$prompt-theme[BattleColor]};
  282. };
  283. #if { "$prompt-dict[battle][value]" == "true" && "$prompt-dict[busy][value]" == "true" } {
  284. #local allBarColor {$prompt-theme[BattleBusyColor]};
  285. };
  286. #if { "$prompt-dict[disable][value]" != "" } {
  287. #local allBarColor {$prompt-theme[Disable]};
  288. };
  289. #if { &topSepBar[] > 0 } {
  290. #math topMaxLine {$topMaxLine + 1};
  291. };
  292. #if { $botMaxLine == 0 && ( &midSepBar[] == 0 || &midSepBar[] == 0 ) } {
  293. #local botMaxLine {1};
  294. };
  295. #else {
  296. #math botMaxLine {$botMaxLine + 2};
  297. };
  298. #local content {};
  299. #list content create {};
  300. #local line {};
  301. #local delta {0};
  302. #foreach {*topLines[]} {line} {
  303. #local fields {$topLines[$line]};
  304. #local text {@__prompt_build_line__{{$fields}}};
  305. #if { $text[width] > 0 } {
  306. #local realLine {};
  307. #math realLine {$line - $delta};
  308. #list content {add} {{{line}{$realLine}{text}{$text[text]}}};
  309. };
  310. #else {
  311. #math delta {$delta + 1};
  312. #math topMaxLine {$topMaxLine - 1};
  313. };
  314. };
  315. #if { &topSepBar[] > 0 } {
  316. #local text {@__prompt_build_line__{{$topSepBar}}};
  317. #if { $text[width] == 0 && $topMaxLine == 1 } {
  318. #math topMaxLine {$topMaxLine - 1};
  319. };
  320. #else {
  321. #local barColor {$prompt-theme[TopSepBar]};
  322. #if { "$allBarColor" != "" } {#local barColor {$allBarColor}};
  323. #local text {@__prompt_fill_line__{{$text[text]};{$text[width]};$barColor}};
  324. #list content {add} {{{line}{$topMaxLine}{text}{$text}}};
  325. };
  326. };
  327. #if { &botSepBar[] > 0 || $botMaxLine > 0 } {
  328. #local text {@__prompt_build_line__{{$botSepBar}}};
  329. #local barColor {$prompt-theme[BotSepBar]};
  330. #if { "$allBarColor" != "" } {#local barColor {$allBarColor}};
  331. #local text {@__prompt_fill_line__{{$text[text]};{$text[width]};$barColor}};
  332. #list content {add} {{{line}{-2}{text}{$text}}};
  333. };
  334. #local delta {0};
  335. #local line {0};
  336. #if { &botLines[] > 0 } {
  337. #loop {&botLines[]} {1} {line} {
  338. #local fields {$botLines[$line]};
  339. #local text {@__prompt_build_line__{{$fields}}};
  340. #if { $text[width] > 0 } {
  341. #local realLine {};
  342. #math realLine {$line - $botMaxLine - 1};
  343. #list content {add} {{{line}{$realLine}{text}{$text[text]}}};
  344. };
  345. #else {
  346. #math botMaxLine {$botMaxLine - 1};
  347. };
  348. };
  349. };
  350. #if { &midSepBar[] > 0 || &botLines[] > 0 } {
  351. #local text {@__prompt_build_line__{{$midSepBar}}};
  352. #local barColor {$prompt-theme[MidSepBar]};
  353. #if { "$allBarColor" != "" } {#local barColor {$allBarColor}};
  354. #local text {@__prompt_fill_line__{{$text[text]};{$text[width]};$barColor}};
  355. #math line {$botMaxLine + 1};
  356. #list content {add} {{{line}{-$line}{text}{$text}}};
  357. };
  358. #if { "$prompt-top-max-line" != "$topMaxLine" || "$prompt-bot-max-line" != "$botMaxLine" } {
  359. #local lineWidth {@prompt.ScreenWidth{}};
  360. #local spaceLine {};
  361. #format spaceLine {%-${lineWidth}s} {};
  362. #local newMax {$topMaxLine};
  363. #while { $newMax < $prompt-top-max-line } {
  364. #math newMax {$newMax + 1};
  365. #echo {{$spaceLine}{$newMax}};
  366. };
  367. #local newMax {$botMaxLine + 1};
  368. #while { $newMax < $prompt-bot-max-line } {
  369. #math newMax {$newMax + 1};
  370. #echo {{$spaceLine}{-$newMax}};
  371. };
  372. #var prompt-top-max-line {$topMaxLine};
  373. #var prompt-bot-max-line {$botMaxLine};
  374. #split {$topMaxLine} {$botMaxLine};
  375. #var prompt.current-content {};
  376. #buffer end;
  377. };
  378. #local idx {};
  379. #foreach {*content[]} {idx} {
  380. #local line {$content[$idx]};
  381. #if { {$prompt.current-content[=$line[line]]} === {$line[text]} } {
  382. #continue;
  383. };
  384. #var prompt.current-content[=$line[line]] {$line[text]};
  385. #echo {{%s}{$line[line]}} {$line[text]};
  386. };
  387. #local prompt {$prompt-prompt};
  388. #if { "$prompt" != "" } {
  389. #echo {{$prompt}{-1}};
  390. };
  391. #cursor {redraw input};
  392. };
  393. #func {__prompt_build_line__} {
  394. #local fields {%1};
  395. #local text {};
  396. #local order {};
  397. #local lineWidth {0};
  398. #foreach {*fields[]} {order} {
  399. #local field {$fields[$order]};
  400. #local name {$field[name]};
  401. #local label {$field[label]};
  402. #local color {$field[color]};
  403. #local width {$field[width]};
  404. #local value {$prompt-dict[$name]};
  405. #local now {};
  406. #format now {%T};
  407. #nop 所有的 Hide* 选项自动拥有 HideEmpty 语义。;
  408. #if { "$field[visibility]" == "Hide%*" && "$value[value]" == "" } {
  409. #continue;
  410. };
  411. #nop 检查是否是倒计时,以及倒计时是否已经归零;
  412. #local zero {undef};
  413. #if { "$field[countdown]" != "" } {
  414. #local seconds {};
  415. #math seconds {$now - $prompt-dict[$name][showTime]};
  416. #replace value[value] {^%+1..d$} {@__prompt_countdown__{&1;$seconds}};
  417. #replace value[value] {(%+1..d)} {(@__prompt_countdown__{&1;$seconds})};
  418. #if { "$value[value]" != "{[1-9][0-9]*|.*\([1-9][0-9]*\).*}" } {
  419. #local zero {true};
  420. };
  421. #else {
  422. #local zero {false};
  423. };
  424. #var {prompt-dict[$name][showTime]} {$now};
  425. #var {prompt-dict[$name][value]} {$value[value]};
  426. #replace value[value] {^%+1..d$} {@__prompt_show_countdown__{$field[countdown];&1}};
  427. #replace value[value] {(%+1..d)} {(@__prompt_show_countdown__{$field[countdown];&1})};
  428. };
  429. #nop 如果设置了 HideZero,那么倒计时归零时,不予显示该字段。;
  430. #if { "$field[visibility]" == "HideZero" && "$zero" == "true" } {
  431. #continue;
  432. };
  433. #nop 检查是否已经是冷却了的字段,倒计时字段当倒计时持续时不会变为冷却;
  434. #local cool {false};
  435. #if { $field[cooldown] > 0 && $now - $value[updateTime] > $field[cooldown] && "$zero" != "false" } {
  436. #local cool {true};
  437. };
  438. #nop 如果设置了 HideCool,那么内容冷却之后则不予显示;
  439. #if { "$field[visibility]" == "HideCool" && "$cool" == "true" } {
  440. #continue;
  441. };
  442. #nop 如果设置了 HideLabel,那么不显示标签;
  443. #if { "$field[visibility]" == "HideLabel" } {
  444. #local label {};
  445. };
  446. #if { "$label" != "" } {
  447. #nop 如果全局开关已经禁用,则忽略所有配色,全部显示为禁用色;
  448. #if { "$prompt-dict[disable][value]" != "" } {
  449. #replace label {^<{[a-zA-Z0-9]+}>} {};
  450. #local label {$prompt-theme[Disable]$label};
  451. };
  452. #else {
  453. #nop 否则根据内容的新鲜程度自动改变颜色;
  454. #if { "$cool" == "true" } {
  455. #replace label {^<{[a-zA-Z0-9]+}>} {};
  456. #local label {$prompt-theme[CoolLabel]$label};
  457. };
  458. #else {
  459. #local label {$prompt-theme[HotLabel]$label};
  460. };
  461. };
  462. #local label {$label<299> };
  463. };
  464. #if { "$field[visibility]" == "HideLabel" } {
  465. #local label {};
  466. };
  467. #if { "$color" == "" } {
  468. #local color {$prompt-theme[Value]};
  469. };
  470. #format value {$color%-${width}s<299>} {$value[value]};
  471. #math lineWidth {$lineWidth + @str.Width{$label} + @str.Width{$value}};
  472. #if { "$text" == "" } {
  473. #local text {$label$value};
  474. };
  475. #elseif { "$label$value" != "" } {
  476. #local text {$text $label$value};
  477. #math lineWidth {$lineWidth + 1};
  478. };
  479. };
  480. #return {{width}{$lineWidth}{text}{$text}};
  481. };
  482. #func {__prompt_countdown__} {
  483. #local value {%1};
  484. #local count {%2};
  485. #math value {$value - $count};
  486. #if { $value < 0 } {
  487. #local value {0};
  488. };
  489. #return {$value};
  490. };
  491. #func {__prompt_show_countdown__} {
  492. #local type {%1};
  493. #local secs {%2};
  494. #local ret {};
  495. #if { "$type" == "Seconds" } {
  496. #local ret {${secs}s};
  497. };
  498. #elseif { "$type" == "Auto" } {
  499. #if { $secs > 86400 } {
  500. #local day {};
  501. #math day {$secs / 86400};
  502. #local hour {};
  503. #math hour {($secs % 86400) / 3600};
  504. #format ret {%d天%d小时} {$day} {$hour};
  505. };
  506. #elseif { $secs > 3600 } {
  507. #local hour {};
  508. #math hour {$secs / 3600};
  509. #local mins {($secs % 3600) / 60};
  510. #format ret {%d小时%d分} {$hour} {$mins};
  511. };
  512. #elseif { $secs > 180 } {
  513. #local mins {};
  514. #math mins {$secs / 60};
  515. #math secs {$secs % 60};
  516. #format ret {00:%%02d:%%02d} {$mins} {$secs};
  517. };
  518. #else {
  519. #local ret {${secs}s};
  520. };
  521. };
  522. #elseif { "$type" == "Clock" } {
  523. #if { $secs > 86400 } {
  524. #local day {};
  525. #math day {$secs / 86400};
  526. #math secs {$secs % 86400};
  527. #format ret {%d天} {$day};
  528. };
  529. #local hour {};
  530. #local mins {};
  531. #math hour {$secs / 3600};
  532. #math secs {$secs % 3600};
  533. #math mins {$secs / 60};
  534. #math secs {$secs % 60};
  535. #format ret {%s%%02d:%%02d:%%02d} {$ret} {$hour} {$mins} {$secs};
  536. };
  537. #return {$ret};
  538. };
  539. #func {__prompt_fill_line__} {
  540. #local text {%1};
  541. #local width {%2};
  542. #local color {%3};
  543. #local newText {@str.Trim{$text}};
  544. #math width {$width + @str.Width{$newText} - @str.Width{$text}};
  545. #local screenWidth {$prompt-screen-width};
  546. #local leftLen {0};
  547. #local rightLen {0};
  548. #math leftLen {($screenWidth - $width) / 2 - 1};
  549. #math rightLen {$screenWidth - $leftLen - $width - 2};
  550. #local left {};
  551. #format {left} {%${leftLen}s} {};
  552. #replace {left} { } {$prompt-padding};
  553. #local right {};
  554. #format {right} {%${rightLen}s} {};
  555. #replace {right} { } {$prompt-padding};
  556. #if { $leftLen < 0 } {
  557. #format {newText} {%$screenWidth.${screenWidth}s} {$newText};
  558. #return {$newText};
  559. };
  560. #elseif { "$newText" == "" } {
  561. #return {$color$left$prompt-padding$prompt-padding$right<099>};
  562. };
  563. #else {
  564. #return {$color$left<299> $newText $color$right<099>};
  565. };
  566. };
  567. #alias {prompt.resize} {
  568. #var prompt-top-max-line {0};
  569. #var prompt-bot-max-line {0};
  570. #var prompt-screen-width {0};
  571. #local _ @prompt.ScreenWidth{};
  572. prompt.refresh;
  573. #buffer end;
  574. };
  575. #event {CATCH IAC SB NAWS} {#0};
  576. ///=== {
  577. // ## prompt.Disable
  578. // 禁止 prompt 更新。一般用作调试,可以防止 prompt 自身的运行产生的大量日志干扰调试。
  579. // 参见 prompt.Enable。
  580. // };
  581. #alias {prompt.Disable} {
  582. prompt.Set {{disable}{$prompt-icon[DisableRefresh]}};
  583. prompt.refresh;
  584. #untick prompt.refresh;
  585. };
  586. ///=== {
  587. // ## prompt.Enable
  588. // 允许 prompt 更新。
  589. // 参见 prompt.Disable。
  590. // };
  591. #alias {prompt.Enable} {
  592. prompt.Set {{disable}{}};
  593. Tick prompt.refresh {prompt.refresh} 1;
  594. };
  595. ///=== {
  596. // ## prompt.ToggleSwitch
  597. // 在 prompt.Disable 和 prompt.Enable 之间切换。
  598. // };
  599. #alias {prompt.ToggleSwitch} {
  600. #if { "$prompt-dict[disable][value]" == "" } {
  601. prompt.Disable;
  602. };
  603. #else {
  604. prompt.Enable;
  605. };
  606. };
  607. #alias {prompt.bindKey} {
  608. #local idx {};
  609. #foreach {*global-key-bindings[]} {idx} {
  610. #local key {$global-key-bindings[$idx][key]};
  611. #local code {$global-key-bindings[$idx][action]};
  612. #line sub var #macro {$key} {$code};
  613. };
  614. };
  615. ///=== {
  616. // ## prompt.Change <提示符>
  617. // 设置提示符,提示符位于屏幕最下方输入区的首部,用作指示整个游戏所处的状态。
  618. // };
  619. #alias {prompt.Change} {
  620. #local text {%1};
  621. #var prompt-prompt {$text};
  622. #echo {{\r\e[K$prompt-prompt}{-1}};
  623. };
  624. ///=== {
  625. // ## prompt.HotKeys
  626. // 显示系统已配置的热键清单。
  627. // 本命令也可写作 HOTKEYS,作用相同。
  628. // };
  629. #alias {HOTKEYS} {prompt.HotKeys};
  630. #alias {prompt.HotKeys} {
  631. #echo;
  632. #echo { <128>%-20s %-30s %-40s} {快捷键} {含义} {对应代码};
  633. #draw Yellow scroll line 1 1 1 90;
  634. #local idx {};
  635. #foreach {*global-key-bindings[]} {idx} {
  636. #local key {$global-key-bindings[$idx][key]};
  637. #local meaning {$global-key-bindings[$idx][meaning]};
  638. #local code {$global-key-bindings[$idx][action]};
  639. #replace key {\\c} {Ctrl+};
  640. #replace key {Ctrl+%.%+1..*} {Ctrl+&1 &2};
  641. #echo { %-20s %-30s %-40s}
  642. {$key} {$meaning} {$code};
  643. };
  644. #echo;
  645. okLog 快捷键中如果存在多个按键序列的,带加号的为一组,需要同时按下,其余依次按下即可。请注意区分大小写。;
  646. okLog 例如 Ctrl+o k 的正确按法是,先按下 Ctrl+o,然后松开双手,再按下 k。;
  647. okLog 如果快捷键以 ^ 开头,则意味着只有输入框为空时,它才会生效。;
  648. #echo;
  649. };
  650. ///=== {
  651. // ## prompt.Note <文本>
  652. // 发表一条随手笔记。随手笔记是个很实用的功能,可以把短期内需要用户注意的事情醒目地显示在屏幕上。
  653. // 本命令也可写作 NOTE,作用相同。
  654. // };
  655. #alias {NOTE} {prompt.Note};
  656. #alias {prompt.Note} {
  657. prompt.Set {{note}{%0}};
  658. #if { @isEmpty{%0} } {
  659. okLog 你轻轻地从笔记本上撕下一页,捏成一个纸团丢到了垃圾桶里。;
  660. };
  661. #else {
  662. okLog 你抬头看着远方,若有所思,接着又奋笔疾书,在笔记本上记下一些东西。;
  663. };
  664. };
  665. ///=== {
  666. // #@ prompt.ScreenWidth
  667. // 返回屏幕宽度。
  668. // };
  669. #func {prompt.ScreenWidth} {
  670. #if { $prompt-screen-width == 0 } {
  671. #screen get COLS prompt-screen-width;
  672. };
  673. #return {$prompt-screen-width};
  674. };
  675. #alias {prompt.test} {
  676. #local fullme {<219>很久没有进行机器人检查(fullme)了,任务奖励将受到影响。<299>};
  677. #local fullme {http://pkuxkx.com/antirobot/robot.php?filename=1576762922984895};
  678. prompt.Set { {URL}{$fullme} };
  679. prompt.Set {
  680. {pot}{357.75万}
  681. {exp}{7510.56万}
  682. {expSpd}{11.88万/小时}
  683. {profit}{308金币/小时}
  684. };
  685. prompt.Set {
  686. {job}{<171>乔峰}
  687. {stage}{寻找NPC}
  688. {area}{建康}
  689. {room}{中城}
  690. {npc}{庞九公}
  691. {type}{杀死}
  692. };
  693. };