tmux.tin 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 本文件属于 PaoTin++ 的一部分。
  4. PaoTin++ © 2020~2023 的所有版权均由担子炮(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. #return {true};
  23. };
  24. #nop 切换 tmux 当前主题,比如可以为发呆、任务、战斗、练功设置不同的主题。;
  25. #alias {tmux.SetTheme} {
  26. #local theme {@default{%1;GAME}};
  27. #if { "$tmux-theme" == "$theme" } {
  28. #return;
  29. };
  30. #local event {};
  31. #if { "$tmux-theme" != "" } {
  32. #foreach {$tmux-update-events[DEFAULT];$tmux-update-events[$tmux-theme]} {event} {
  33. event.UnHandle {$event} {tmux};
  34. };
  35. };
  36. #var tmux-theme {$theme};
  37. #local events {@default{{$tmux-update-events[$tmux-theme]};{$tmux-update-events[DEFAULT]}}};
  38. #foreach {$events} {event} {
  39. event.Handle {$event} {tmux} {ui/tmux} {tmux.Update};
  40. };
  41. };
  42. #alias {tmux.Update} {
  43. #if { "$char[档案][账号]" == "" } {
  44. #return;
  45. };
  46. #local theme {$tmux-theme};
  47. #local left {@default{
  48. {$tmux-pane-border-format[$theme][left]};
  49. {$tmux-pane-border-format[DEFAULT][left]}}};
  50. #local centre {@default{
  51. {$tmux-pane-border-format[$theme][centre]};
  52. {$tmux-pane-border-format[DEFAULT][centre]}}};
  53. #local right {@default{
  54. {$tmux-pane-border-format[$theme][right]};
  55. {$tmux-pane-border-format[DEFAULT][right]}}};
  56. #line sub {functions;var;escapes;colors} {
  57. #format left {%s} {$left};
  58. #format centre {%s} {$centre};
  59. #format right {%s} {$right};
  60. };
  61. #local left {@tmux.ConvertFromANSI{{$left}}};
  62. #local centre {@tmux.ConvertFromANSI{{$centre}}};
  63. #local right {@tmux.ConvertFromANSI{{$right}}};
  64. #local line {};
  65. #if { @tmux.Width{{$left}} > 0 } {
  66. #cat line {#[align=left] $left };
  67. };
  68. #if { @tmux.Width{{$centre}} > 0 } {
  69. #cat {line} {#[align=centre] $centre };
  70. };
  71. #if { @tmux.Width{{$right}} > 0 } {
  72. #cat {line} {#[align=right] $right };
  73. };
  74. #local file {tmux/$char[档案][账号]/game-border};
  75. #line quiet #script {tmp} {echo '$line' > $file};
  76. #line quiet #script {tmp} {tmux refresh 2>/dev/null};
  77. };
  78. #func {TMUX} {
  79. #return {@tmux.ConvertFromANSI{{%1}}};
  80. };
  81. #func {tmux.ConvertFromANSI} {
  82. #local text {%1};
  83. #if { {$text} == {%*{\e\[22(|;[0-9;]+)m}%*} } {
  84. #local esc {\e};
  85. #line sub {var;escapes} #format esc {%s} {$esc};
  86. #replace {text} {{\e\[22(|;([0-9;]+))m}} {#[none]@if{@str.Len{&2} > 0;{${esc}[&3m}}};
  87. };
  88. #replace {text} {{\e\[(3|4)8;5;(\d+)m}} {@tmux.ansi2tmux{&2;5;&3}};
  89. #replace {text} {{\e\[(3|4)8;2;(\d+);(\d+);(\d+)m}} {@tmux.ansi2tmux{&2;2;&3;&4;&5}};
  90. #local {mode} {TEXT};
  91. #local output {};
  92. #local pending {};
  93. #local ch {};
  94. #parse {$text} {ch} {
  95. #switch {"$mode"} {
  96. #case {"TEXT"} {
  97. #switch {"$ch"} {
  98. #case {"\e"} {#local mode {ESC}};
  99. #case {";"} {#cat output { }};
  100. #default {#cat output {$ch}};
  101. };
  102. };
  103. #case {"ESC"} {
  104. #switch {"$ch"} {
  105. #case {"["} {#cat output {#[}; #local mode {SGR}};
  106. #default {#cat output {$ch}; #local mode {TEXT}};
  107. };
  108. };
  109. #case {"SGR"} {
  110. #switch {"$ch"} {
  111. #case {"0"} {#cat output {default}};
  112. #case {"1"} {#cat output {bold}};
  113. #case {"2"} {#cat output {dim}};
  114. #case {"3"} {#local mode {PENDING3}};
  115. #case {"4"} {#local mode {PENDING4}};
  116. #case {"5"} {#cat output {blink}};
  117. #case {";"} {#cat output { }};
  118. #default {
  119. #if { "$pending" == "[" } {#cat output {default}};
  120. #cat output {]};
  121. #local mode {TEXT};
  122. };
  123. };
  124. };
  125. #case {"PENDING3"} {
  126. #switch {"$ch"} {
  127. #case {"{[0-7]}"} {#cat output {fg=colour$ch}; #local mode {SGR}};
  128. #case {"9"} {#cat output {fg=default}; #local mode {SGR}};
  129. #case {";"} {#cat output {italics }; #local mode {SGR}};
  130. #case {"m"} {#cat output {italics]}; #local mode {TEXT}};
  131. #default {#cat output {$ch]}; #local mode {TEXT}};
  132. };
  133. };
  134. #case {"PENDING4"} {
  135. #switch {"$ch"} {
  136. #case {"{[0-7]}"} {#cat output {bg=colour$ch}; #local mode {SGR}};
  137. #case {"9"} {#cat output {bg=default}; #local mode {SGR}};
  138. #case {";"} {#cat output {underscore }; #local mode {SGR}};
  139. #case {"m"} {#cat output {underscore]}; #local mode {TEXT}};
  140. #default {#cat output {$ch]}; #local mode {TEXT}};
  141. };
  142. };
  143. };
  144. #local {pending} {$ch};
  145. };
  146. #return {$output#[default]};
  147. };
  148. #func {tmux.ansi2tmux} {
  149. #local {type} {%1};
  150. #local {mode} {%2};
  151. #local {arg1} {%3};
  152. #local {arg2} {%4};
  153. #local {arg3} {%5};
  154. #local output {};
  155. #nop 3 == 前景色, 4 == 背景色;
  156. #if { $type == 3 } {
  157. #cat output {#[fg=};
  158. };
  159. #elseif { $type == 4 } {
  160. #cat output {#[bg=};
  161. };
  162. #else {
  163. #return {};
  164. };
  165. #nop 5 == indexed colors, 2 == RGB colors;
  166. #if { $mode == 5 } {
  167. #cat output {colour$arg1]};
  168. };
  169. #elseif { $mode == 2 } {
  170. #local code {};
  171. #format code {#%+02X%+02X%+02X} {$arg1} {$arg2} {$arg3};
  172. #cat output {$code]};
  173. };
  174. #else {
  175. #return {};
  176. };
  177. #return {$output};
  178. };
  179. #func {tmux.Width} {
  180. #local arg {%1};
  181. #replace {arg} {{#\[[^\]]*\]}} {};
  182. #return {@str.Len{$arg}};
  183. };
  184. #nop 默认每分钟更新一次。;
  185. #tick tmux.Update {tmux.Update} 60;