tmux.tin 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 本文件属于 PaoTin++ 的一部分。
  4. PaoTin++ © 2020~2024 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  5. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  6. */
  7. #var lib_ui_tmux[META] {
  8. {NAME} {TMUX UI}
  9. {DESC} {支持丰富的自定义选项,用户可定制自己的 tmux 边框样式。}
  10. {AUTHOR} {担子炮}
  11. };
  12. #nop tmux pane 边框的样式;
  13. #var tmux-pane-border-format {};
  14. #nop 绑定事件,发生何种事件时,需要更新 UI;
  15. #var tmux-update-events {};
  16. #nop 当前展示的边框样式的 theme。;
  17. #var tmux-theme {};
  18. #func {lib_ui_tmux.Init} {
  19. #if { !@mkdir{{tmux/$user[id]}} } {
  20. errLog 创建 tmux UI 通信管道(tmux/$user[id])失败;
  21. };
  22. tmux.SetTheme GAME;
  23. #return {true};
  24. };
  25. #nop 切换 tmux 当前主题,比如可以为发呆、任务、战斗、练功设置不同的主题。;
  26. #alias {tmux.SetTheme} {
  27. #local theme {@default{%1;GAME}};
  28. #if { "$tmux-theme" == "$theme" } {
  29. #return;
  30. };
  31. #local event {};
  32. #if { "$tmux-theme" != "" } {
  33. #foreach {$tmux-update-events[DEFAULT];$tmux-update-events[$tmux-theme]} {event} {
  34. event.UnHandle {$event} {tmux};
  35. };
  36. };
  37. #var tmux-theme {$theme};
  38. #local events {@default{{$tmux-update-events[$tmux-theme]};{$tmux-update-events[DEFAULT]}}};
  39. #foreach {$events} {event} {
  40. event.Handle {$event} {tmux} {ui/tmux} {tmux.Update};
  41. };
  42. };
  43. #alias {tmux.Update} {
  44. #if { "$char[档案][账号]" == "" } {
  45. #return;
  46. };
  47. #local theme {$tmux-theme};
  48. #local left {@default{
  49. {$tmux-pane-border-format[$theme][left]};
  50. {$tmux-pane-border-format[DEFAULT][left]}}};
  51. #local centre {@default{
  52. {$tmux-pane-border-format[$theme][centre]};
  53. {$tmux-pane-border-format[DEFAULT][centre]}}};
  54. #local right {@default{
  55. {$tmux-pane-border-format[$theme][right]};
  56. {$tmux-pane-border-format[DEFAULT][right]}}};
  57. #line sub {functions;var;escapes;colors} {
  58. #format left {%s} {$left};
  59. #format centre {%s} {$centre};
  60. #format right {%s} {$right};
  61. };
  62. #local left {@tmux.ConvertFromANSI{{$left}}};
  63. #local centre {@tmux.ConvertFromANSI{{$centre}}};
  64. #local right {@tmux.ConvertFromANSI{{$right}}};
  65. #local line {};
  66. #if { @tmux.Width{{$left}} > 0 } {
  67. #cat line {#[align=left] $left };
  68. };
  69. #if { @tmux.Width{{$centre}} > 0 } {
  70. #cat {line} {#[align=centre] $centre };
  71. };
  72. #if { @tmux.Width{{$right}} > 0 } {
  73. #cat {line} {#[align=right] $right };
  74. };
  75. #local file {tmux/$char[档案][账号]/game-border};
  76. #line quiet #script {tmp} {echo '$line' > $file};
  77. #line quiet #script {tmp} {tmux refresh 2>/dev/null};
  78. };
  79. #func {TMUX} {
  80. #return {@tmux.ConvertFromANSI{{%1}}};
  81. };
  82. #func {tmux.ConvertFromANSI} {
  83. #local text {%1};
  84. #if { {$text} == {%*{\e\[22(|;[0-9;]+)m}%*} } {
  85. #local esc {\e};
  86. #line sub {var;escapes} #format esc {%s} {$esc};
  87. #replace {text} {{\e\[22(|;([0-9;]+))m}} {#[none]@if{@str.Len{&2} > 0;{${esc}[&3m}}};
  88. };
  89. #replace {text} {{\e\[(3|4)8;5;(\d+)m}} {@tmux.ansi2tmux{&2;5;&3}};
  90. #replace {text} {{\e\[(3|4)8;2;(\d+);(\d+);(\d+)m}} {@tmux.ansi2tmux{&2;2;&3;&4;&5}};
  91. #local {mode} {TEXT};
  92. #local output {};
  93. #local pending {};
  94. #local ch {};
  95. #parse {$text} {ch} {
  96. #switch {"$mode"} {
  97. #case {"TEXT"} {
  98. #switch {"$ch"} {
  99. #case {"\e"} {#local mode {ESC}};
  100. #case {";"} {#cat output { }};
  101. #default {#cat output {$ch}};
  102. };
  103. };
  104. #case {"ESC"} {
  105. #switch {"$ch"} {
  106. #case {"["} {#cat output {#[}; #local mode {SGR}};
  107. #default {#cat output {$ch}; #local mode {TEXT}};
  108. };
  109. };
  110. #case {"SGR"} {
  111. #switch {"$ch"} {
  112. #case {"0"} {#cat output {default}};
  113. #case {"1"} {#cat output {bold}};
  114. #case {"2"} {#cat output {dim}};
  115. #case {"3"} {#local mode {PENDING3}};
  116. #case {"4"} {#local mode {PENDING4}};
  117. #case {"5"} {#cat output {blink}};
  118. #case {";"} {#cat output { }};
  119. #default {
  120. #if { "$pending" == "[" } {#cat output {default}};
  121. #cat output {]};
  122. #local mode {TEXT};
  123. };
  124. };
  125. };
  126. #case {"PENDING3"} {
  127. #switch {"$ch"} {
  128. #case {"{[0-7]}"} {#cat output {fg=colour$ch}; #local mode {SGR}};
  129. #case {"9"} {#cat output {fg=default}; #local mode {SGR}};
  130. #case {";"} {#cat output {italics }; #local mode {SGR}};
  131. #case {"m"} {#cat output {italics]}; #local mode {TEXT}};
  132. #default {#cat output {$ch]}; #local mode {TEXT}};
  133. };
  134. };
  135. #case {"PENDING4"} {
  136. #switch {"$ch"} {
  137. #case {"{[0-7]}"} {#cat output {bg=colour$ch}; #local mode {SGR}};
  138. #case {"9"} {#cat output {bg=default}; #local mode {SGR}};
  139. #case {";"} {#cat output {underscore }; #local mode {SGR}};
  140. #case {"m"} {#cat output {underscore]}; #local mode {TEXT}};
  141. #default {#cat output {$ch]}; #local mode {TEXT}};
  142. };
  143. };
  144. };
  145. #local {pending} {$ch};
  146. };
  147. #return {$output#[default]};
  148. };
  149. #func {tmux.ansi2tmux} {
  150. #local {type} {%1};
  151. #local {mode} {%2};
  152. #local {arg1} {%3};
  153. #local {arg2} {%4};
  154. #local {arg3} {%5};
  155. #local output {};
  156. #nop 3 == 前景色, 4 == 背景色;
  157. #if { $type == 3 } {
  158. #cat output {#[fg=};
  159. };
  160. #elseif { $type == 4 } {
  161. #cat output {#[bg=};
  162. };
  163. #else {
  164. #return {};
  165. };
  166. #nop 5 == indexed colors, 2 == RGB colors;
  167. #if { $mode == 5 } {
  168. #cat output {colour$arg1]};
  169. };
  170. #elseif { $mode == 2 } {
  171. #local code {};
  172. #format code {#%+02X%+02X%+02X} {$arg1} {$arg2} {$arg3};
  173. #cat output {$code]};
  174. };
  175. #else {
  176. #return {};
  177. };
  178. #return {$output};
  179. };
  180. #func {tmux.Width} {
  181. #local arg {%1};
  182. #replace {arg} {{#\[[^\]]*\]}} {};
  183. #return {@str.Len{$arg}};
  184. };
  185. #nop 默认每分钟更新一次。;
  186. #tick tmux.Update {tmux.Update} 60;