prompt.tin 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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-icon {
  124. {DisableRefresh}{🚫}
  125. };
  126. VAR {热键绑定} global-key-bindings {
  127. {1} {{key}{\cos} {action}{prompt.ToggleSwitch}}
  128. };
  129. VAR {信息栏的顶部高度(自动计算)} prompt-top-max-line {0};
  130. VAR {信息栏的底部高度(自动计算)} prompt-bot-max-line {0};
  131. VAR {屏幕的宽度(自动更新)} prompt-screen-width {0};
  132. VAR {所有的字段值的字典} prompt-dict {};
  133. VAR {上次实际绘制屏幕的时间} prompt-refresh {
  134. {global}{false}
  135. {lines} {false}
  136. {prompt}{false}
  137. };
  138. VAR {命令输入提示符} prompt-prompt {Input};
  139. #func {lib_ui_prompt.Init} {
  140. load-file {etc/ui-settings.tin};
  141. #local _ @prompt.ScreenWidth{};
  142. prompt.Set {};
  143. prompt.bindKey;
  144. prompt.Enable;
  145. #return true;
  146. };
  147. #nop 设置字段值,被设置的字段值将立即显示在屏幕上;
  148. #alias {prompt.Set} {
  149. #local fields {%1};
  150. #local now {};
  151. #format now {%T};
  152. #local field {};
  153. #foreach {*fields[]} {field} {
  154. #var prompt-dict[$field] {
  155. {updateTime}{$now}
  156. {showTime}{$now}
  157. {value}{$fields[$field]}
  158. };
  159. };
  160. };
  161. #nop 设置提示符,提示符位于屏幕最下方输入区的首部,用作指示整个游戏所处的状态;
  162. #alias {prompt.Change} {
  163. #local text {%1};
  164. #var prompt-prompt {$text};
  165. #echo {{\r\e[K$prompt-prompt}{-1}};
  166. };
  167. #nop 设置字段值,被设置的字段值将立即显示在屏幕上,但会在一段时间后消失;
  168. #alias {prompt.SetAwhile} {
  169. #local id {%1};
  170. #local value {%2};
  171. #local secs {%3};
  172. #if { "$secs" == "" } {
  173. #local secs {5};
  174. };
  175. prompt.Set {{$id}{$value}};
  176. #line sub {VARIABLES} {
  177. #delay prompt-set-awhile-$id {
  178. prompt.Set {{$id}{}};
  179. } {$secs};
  180. };
  181. };
  182. #nop 显示字段值;
  183. #alias {prompt.refresh} {
  184. #local topMaxLine {0};
  185. #local botMaxLine {0};
  186. #local topLines {};
  187. #local botLines {};
  188. #local topSepBar {};
  189. #local midSepBar {};
  190. #local botSepBar {};
  191. #foreach {*{prompt-fields[]}} {idx} {
  192. #local field {${prompt-fields[$idx]}};
  193. #if { "$field[visibility]" == "" } {
  194. #local field[visibility] {HideEmpty};
  195. };
  196. #switch {"$field[place]"} {
  197. #case {"Top"} {
  198. #while {1} {
  199. #if { $field[line] <= $topMaxLine } {
  200. #break;
  201. };
  202. #math topMaxLine {$topMaxLine + 1};
  203. #local topLines[$topMaxLine] {};
  204. };
  205. #if { "$field[order]" == "" } {
  206. #local field[order] {@math.Eval{ @math.Max{0;*topLines[$field[line]][]} + 1 }};
  207. };
  208. #local topLines[$field[line]][$field[order]] {$field};
  209. };
  210. #case {"Bot"} {
  211. #while {1} {
  212. #if { $field[line] <= $botMaxLine } {
  213. #break;
  214. };
  215. #math botMaxLine {$botMaxLine + 1};
  216. #local botLines[$botMaxLine] {};
  217. };
  218. #if { "$field[order]" == "" } {
  219. #local field[order] {@math.Eval{ @math.Max{0;*botLines[$field[line]][]} + 1 }};
  220. };
  221. #local botLines[$field[line]][$field[order]] {$field};
  222. };
  223. #case {"TopSepBar"} {
  224. #if { "$field[order]" == "" } {
  225. #local field[order] {@math.Eval{ @math.Max{0;*topSepBar[]} + 1 }};
  226. };
  227. #local topSepBar[$field[order]] {$field};
  228. };
  229. #case {"MidSepBar"} {
  230. #if { "$field[order]" == "" } {
  231. #local field[order] {@math.Eval{ @math.Max{0;*midSepBar[]} + 1 }};
  232. };
  233. #local midSepBar[$field[order]] {$field};
  234. };
  235. #case {"BotSepBar"} {
  236. #if { "$field[order]" == "" } {
  237. #local field[order] {@math.Eval{ @math.Max{0;*botSepBar[]} + 1 }};
  238. };
  239. #local botSepBar[$field[order]] {$field};
  240. };
  241. #default {
  242. #echo {配置有误,请检查。place=[%s]} {$field[place]};
  243. };
  244. };
  245. };
  246. #local allBarColor {};
  247. #if { "${prompt-dict[busy][value]}" == "true" } {
  248. #local allBarColor {${prompt-theme[BusyColor]}};
  249. };
  250. #if { "${prompt-dict[battle][value]}" == "true" } {
  251. #local allBarColor {${prompt-theme[BattleColor]}};
  252. };
  253. #if { "${prompt-dict[battle][value]}" == "true" && "${prompt-dict[busy][value]}" == "true" } {
  254. #local allBarColor {${prompt-theme[BattleBusyColor]}};
  255. };
  256. #if { "${prompt-dict[disable][value]}" != "" } {
  257. #local allBarColor {${prompt-theme[Disable]}};
  258. };
  259. #if { &topSepBar[] > 0 } {
  260. #math topMaxLine {$topMaxLine + 1};
  261. };
  262. #if { $botMaxLine == 0 && ( &midSepBar[] == 0 || &midSepBar[] == 0 ) } {
  263. #local botMaxLine {1};
  264. };
  265. #else {
  266. #math botMaxLine {$botMaxLine + 2};
  267. };
  268. #local content {};
  269. #list content create {};
  270. #local line {};
  271. #local delta {0};
  272. #foreach {*topLines[]} {line} {
  273. #local fields {$topLines[$line]};
  274. #local text {@__prompt_build_line__{{$fields}}};
  275. #if { $text[width] > 0 } {
  276. #local realLine {};
  277. #math realLine {$line - $delta};
  278. #list content {add} {{{line}{$realLine}{text}{$text[text]}}};
  279. };
  280. #else {
  281. #math delta {$delta + 1};
  282. #math topMaxLine {$topMaxLine - 1};
  283. };
  284. };
  285. #if { &topSepBar[] > 0 } {
  286. #local text {@__prompt_build_line__{{$topSepBar}}};
  287. #if { $text[width] == 0 && $topMaxLine == 1 } {
  288. #math topMaxLine {$topMaxLine - 1};
  289. };
  290. #else {
  291. #local barColor {${prompt-theme[TopSepBar]}};
  292. #if { "$allBarColor" != "" } {#local barColor {$allBarColor}};
  293. #local text {@__prompt_fill_line__{{$text[text]};{$text[width]};$barColor}};
  294. #list content {add} {{{line}{$topMaxLine}{text}{$text}}};
  295. };
  296. };
  297. #if { &botSepBar[] > 0 || $botMaxLine > 0 } {
  298. #local text {@__prompt_build_line__{{$botSepBar}}};
  299. #local barColor {${prompt-theme[BotSepBar]}};
  300. #if { "$allBarColor" != "" } {#local barColor {$allBarColor}};
  301. #local text {@__prompt_fill_line__{{$text[text]};{$text[width]};$barColor}};
  302. #list content {add} {{{line}{-2}{text}{$text}}};
  303. };
  304. #local delta {0};
  305. #local line {0};
  306. #if { &botLines[] > 0 } {
  307. #loop {&botLines[]} {1} {line} {
  308. #local fields {$botLines[$line]};
  309. #local text {@__prompt_build_line__{{$fields}}};
  310. #if { $text[width] > 0 } {
  311. #local realLine {};
  312. #math realLine {$line - $botMaxLine - 1};
  313. #list content {add} {{{line}{$realLine}{text}{$text[text]}}};
  314. };
  315. #else {
  316. #math botMaxLine {$botMaxLine - 1};
  317. };
  318. };
  319. };
  320. #if { &midSepBar[] > 0 || &botLines[] > 0 } {
  321. #local text {@__prompt_build_line__{{$midSepBar}}};
  322. #local barColor {${prompt-theme[MidSepBar]}};
  323. #if { "$allBarColor" != "" } {#local barColor {$allBarColor}};
  324. #local text {@__prompt_fill_line__{{$text[text]};{$text[width]};$barColor}};
  325. #math line {$botMaxLine + 1};
  326. #list content {add} {{{line}{-$line}{text}{$text}}};
  327. };
  328. #if { "${prompt-top-max-line}" != "$topMaxLine" || "${prompt-bot-max-line}" != "$botMaxLine" } {
  329. #local lineWidth {@prompt.ScreenWidth{}};
  330. #local spaceLine {};
  331. #format spaceLine {%-${lineWidth}s} {};
  332. #local newMax {$topMaxLine};
  333. #while { $newMax < ${prompt-top-max-line} } {
  334. #math newMax {$newMax + 1};
  335. #echo {{$spaceLine}{$newMax}};
  336. };
  337. #local newMax {$botMaxLine + 1};
  338. #while { $newMax < ${prompt-bot-max-line} } {
  339. #math newMax {$newMax + 1};
  340. #echo {{$spaceLine}{-$newMax}};
  341. };
  342. #var prompt-top-max-line {$topMaxLine};
  343. #var prompt-bot-max-line {$botMaxLine};
  344. #split {$topMaxLine} {$botMaxLine};
  345. #buffer end;
  346. };
  347. #local idx {};
  348. #foreach {*content[]} {idx} {
  349. #local line {$content[$idx]};
  350. #echo {{%s}{$line[line]}} {$line[text]};
  351. };
  352. #local prompt {${prompt-prompt}};
  353. #if { "$prompt" != "" } {
  354. #local prompt {$prompt};
  355. #echo {{$prompt}{-1}};
  356. };
  357. };
  358. #func {__prompt_build_line__} {
  359. #local fields {%1};
  360. #local text {};
  361. #local order {};
  362. #local lineWidth {0};
  363. #foreach {*fields[]} {order} {
  364. #local field {$fields[$order]};
  365. #local name {$field[name]};
  366. #local label {$field[label]};
  367. #local color {$field[color]};
  368. #local width {$field[width]};
  369. #local value {${prompt-dict[$name]}};
  370. #local now {};
  371. #format now {%T};
  372. #nop 所有的 Hide* 选项自动拥有 HideEmpty 语义。;
  373. #if { "$field[visibility]" == "Hide%*" && "$value[value]" == "" } {
  374. #continue;
  375. };
  376. #nop 检查是否是倒计时,以及倒计时是否已经归零;
  377. #local zero {undef};
  378. #if { "$field[countdown]" != "" } {
  379. #local seconds {};
  380. #math seconds {$now - ${prompt-dict[$name][showTime]}};
  381. #replace value[value] {^%+1..d$} {@__prompt_countdown__{&1;$seconds}};
  382. #replace value[value] {(%+1..d)} {(@__prompt_countdown__{&1;$seconds})};
  383. #if { "$value[value]" != "{[1-9][0-9]*|.*\([1-9][0-9]*\).*}" } {
  384. #local zero {true};
  385. };
  386. #else {
  387. #local zero {false};
  388. };
  389. #var {prompt-dict[$name][showTime]} {$now};
  390. #var {prompt-dict[$name][value]} {$value[value]};
  391. #replace value[value] {^%+1..d$} {@__prompt_show_countdown__{$field[countdown];&1}};
  392. #replace value[value] {(%+1..d)} {(@__prompt_show_countdown__{$field[countdown];&1})};
  393. };
  394. #nop 如果设置了 HideZero,那么倒计时归零时,不予显示该字段。;
  395. #if { "$field[visibility]" == "HideZero" && "$zero" == "true" } {
  396. #continue;
  397. };
  398. #nop 检查是否已经是冷却了的字段,倒计时字段当倒计时持续时不会变为冷却;
  399. #local cool {false};
  400. #if { $field[cooldown] > 0 && $now - $value[updateTime] > $field[cooldown] && "$zero" != "false" } {
  401. #local cool {true};
  402. };
  403. #nop 如果设置了 HideCool,那么内容冷却之后则不予显示;
  404. #if { "$field[visibility]" == "HideCool" && "$cool" == "true" } {
  405. #continue;
  406. };
  407. #nop 如果设置了 HideLabel,那么不显示标签;
  408. #if { "$field[visibility]" == "HideLabel" } {
  409. #local label {};
  410. };
  411. #if { "$label" != "" } {
  412. #nop 如果全局开关已经禁用,则忽略所有配色,全部显示为禁用色;
  413. #if { "${prompt-dict[disable][value]}" != "" } {
  414. #replace label {^<{[a-zA-Z0-9]+}>} {};
  415. #local label {${prompt-theme[Disable]}$label};
  416. };
  417. #else {
  418. #nop 否则根据内容的新鲜程度自动改变颜色;
  419. #if { "$cool" == "true" } {
  420. #replace label {^<{[a-zA-Z0-9]+}>} {};
  421. #local label {${prompt-theme[CoolLabel]}$label};
  422. };
  423. #else {
  424. #local label {${prompt-theme[HotLabel]}$label};
  425. };
  426. };
  427. #local label {$label<299> };
  428. };
  429. #if { "$field[visibility]" == "HideLabel" } {
  430. #local label {};
  431. };
  432. #if { "$color" == "" } {
  433. #local color {${prompt-theme[Value]}};
  434. };
  435. #format value {$color%-${width}s<299>} {$value[value]};
  436. #math lineWidth {$lineWidth + @str.Width{$label} + @str.Width{$value}};
  437. #if { "$text" == "" } {
  438. #local text {$label$value};
  439. };
  440. #elseif { "$label$value" != "" } {
  441. #local text {$text $label$value};
  442. #math lineWidth {$lineWidth + 1};
  443. };
  444. };
  445. #return {{width}{$lineWidth}{text}{$text}};
  446. };
  447. #func {__prompt_countdown__} {
  448. #local value {%1};
  449. #local count {%2};
  450. #math value {$value - $count};
  451. #if { $value < 0 } {
  452. #local value {0};
  453. };
  454. #return {$value};
  455. };
  456. #func {__prompt_show_countdown__} {
  457. #local type {%1};
  458. #local secs {%2};
  459. #local ret {};
  460. #if { "$type" == "Auto" } {
  461. #if { $secs < 600 } {
  462. #local type {Seconds};
  463. };
  464. #else {
  465. #local type {Clock};
  466. };
  467. };
  468. #if { "$type" == "Seconds" } {
  469. #local ret {${secs}s};
  470. };
  471. #elseif { "$type" == "Clock" } {
  472. #if { $secs > 86400 } {
  473. #math ret {$secs / 86400};
  474. #local ret {$ret天};
  475. #math secs {$secs % 86400};
  476. };
  477. #local hour {};
  478. #local mins {};
  479. #math hour {$secs / 3600};
  480. #math secs {$secs % 3600};
  481. #math mins {$secs / 60};
  482. #math secs {$secs % 60};
  483. #format ret {%s%%02d:%%02d:%%02d} {$ret} {$hour} {$mins} {$secs};
  484. };
  485. #return {$ret};
  486. };
  487. #func {__prompt_fill_line__} {
  488. #local text {%1};
  489. #local width {%2};
  490. #local color {%3};
  491. #local newText {@str.Trim{$text}};
  492. #math width {$width + @str.Width{$newText} - @str.Width{$text}};
  493. #local screenWidth {$prompt-screen-width};
  494. #local leftLen {0};
  495. #local rightLen {0};
  496. #math leftLen {($screenWidth - $width) / 2 - 1};
  497. #math rightLen {$screenWidth - $leftLen - $width - 2};
  498. #local left {};
  499. #format {left} {%${leftLen}s} {};
  500. #replace {left} { } {─};
  501. #local right {};
  502. #format {right} {%${rightLen}s} {};
  503. #replace {right} { } {─};
  504. #if { $leftLen < 0 } {
  505. #format {newText} {%$screenWidth.${screenWidth}s} {$newText};
  506. #return {$newText};
  507. };
  508. #elseif { "$newText" == "" } {
  509. #return {$color$left──$right<099>};
  510. };
  511. #else {
  512. #return {$color$left<299> $newText $color$right<099>};
  513. };
  514. };
  515. #event {SCREEN RESIZE} {
  516. #var prompt-top-max-line {0};
  517. #var prompt-bot-max-line {0};
  518. #var prompt-screen-width {0};
  519. #local _ @prompt.ScreenWidth{};
  520. prompt.refresh;
  521. #buffer end;
  522. };
  523. #event {CATCH IAC SB NAWS} {#0};
  524. #alias {prompt.Disable} {
  525. prompt.Set {{disable}{${prompt-icon[DisableRefresh]}}};
  526. prompt.refresh;
  527. #untick prompt.refresh;
  528. };
  529. #alias {prompt.Enable} {
  530. prompt.Set {{disable}{}};
  531. Tick prompt.refresh {prompt.refresh} 1;
  532. };
  533. #alias {prompt.ToggleSwitch} {
  534. #if { "${prompt-dict[disable][value]}" == "" } {
  535. prompt.Disable;
  536. };
  537. #else {
  538. prompt.Enable;
  539. };
  540. };
  541. #alias {prompt.bindKey} {
  542. #local idx {};
  543. #foreach {*{global-key-bindings[]}} {idx} {
  544. #local key {${global-key-bindings[$idx][key]}};
  545. #local code {${global-key-bindings[$idx][action]}};
  546. #line sub var #macro {$key} {$code};
  547. };
  548. };
  549. #alias {NOTE} {prompt.Note};
  550. #alias {prompt.Note} {
  551. prompt.Set {{note}{%0}};
  552. #if { @isEmpty{%0} } {
  553. okLog 你轻轻地从笔记本上撕下一页,捏成一个纸团丢到了垃圾桶里。;
  554. };
  555. #else {
  556. okLog 你抬头看着远方,若有所思,接着又奋笔疾书,在笔记本上记下一些东西。;
  557. };
  558. };
  559. #func {prompt.ScreenWidth} {
  560. #if { $prompt-screen-width == 0 } {
  561. #screen get COLS prompt-screen-width;
  562. };
  563. #return {$prompt-screen-width};
  564. };
  565. #alias {prompt.test} {
  566. #local fullme {<219>很久没有进行机器人检查(fullme)了,任务奖励将受到影响。<299>};
  567. #local fullme {http://pkuxkx.com/antirobot/robot.php?filename=1576762922984895};
  568. prompt.Set { {URL}{$fullme} };
  569. prompt.Set {
  570. {pot}{357.75万}
  571. {exp}{7510.56万}
  572. {expSpd}{11.88万/小时}
  573. {profit}{308金币/小时}
  574. };
  575. prompt.Set {
  576. {job}{<171>乔峰}
  577. {stage}{寻找NPC}
  578. {area}{建康}
  579. {room}{中城}
  580. {npc}{庞九公}
  581. {type}{杀死}
  582. };
  583. };