tmux.tin 6.4 KB

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