#nop vim: set filetype=tt:; /* 本文件属于 PaoTin++ 的一部分。 PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp ) 享有并保留一切法律权利 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。 */ #var lib_ui_tmux[META] { {NAME} {TMUX UI} {DESC} {支持丰富的自定义选项,用户可定制自己的 tmux 边框样式。} {AUTHOR} {担子炮} }; #nop tmux pane 边框的样式; #var tmux-pane-border-format {}; #nop 绑定事件,发生何种事件时,需要更新 UI; #var tmux-update-events {}; #nop 当前展示的边框样式的 theme。; #var tmux-theme {}; #func {lib_ui_tmux.Init} { #if { !@mkdir{{tmux/$user[id]}} } { errLog 创建 tmux UI 通信管道(tmux/$user[id])失败; }; #return {true}; }; #nop 切换 tmux 当前主题,比如可以为发呆、任务、战斗、练功设置不同的主题。; #alias {tmux.SetTheme} { #local theme {@default{%1;GAME}}; #if { "$tmux-theme" == "$theme" } { #return; }; #local event {}; #if { "$tmux-theme" != "" } { #foreach {$tmux-update-events[DEFAULT];$tmux-update-events[$tmux-theme]} {event} { event.UnHandle {$event} {tmux}; }; }; #var tmux-theme {$theme}; #local events {@default{{$tmux-update-events[$tmux-theme]};{$tmux-update-events[DEFAULT]}}}; #foreach {$events} {event} { event.Handle {$event} {tmux} {ui/tmux} {tmux.Update}; }; }; #alias {tmux.Update} { #if { "$char[档案][账号]" == "" } { #return; }; #local theme {$tmux-theme}; #local left {@default{ {$tmux-pane-border-format[$theme][left]}; {$tmux-pane-border-format[DEFAULT][left]}}}; #local centre {@default{ {$tmux-pane-border-format[$theme][centre]}; {$tmux-pane-border-format[DEFAULT][centre]}}}; #local right {@default{ {$tmux-pane-border-format[$theme][right]}; {$tmux-pane-border-format[DEFAULT][right]}}}; #line sub {functions;var;escapes;colors} { #format left {%s} {$left}; #format centre {%s} {$centre}; #format right {%s} {$right}; }; #local left {@tmux.ConvertFromANSI{{$left}}}; #local centre {@tmux.ConvertFromANSI{{$centre}}}; #local right {@tmux.ConvertFromANSI{{$right}}}; #local line {}; #if { @tmux.Width{{$left}} > 0 } { #cat line {#[align=left] $left }; }; #if { @tmux.Width{{$centre}} > 0 } { #cat {line} {#[align=centre] $centre }; }; #if { @tmux.Width{{$right}} > 0 } { #cat {line} {#[align=right] $right }; }; #local file {tmux/$char[档案][账号]/game-border}; #line quiet #script {tmp} {echo '$line' > $file}; #line quiet #script {tmp} {tmux refresh 2>/dev/null}; }; #func {TMUX} { #return {@tmux.ConvertFromANSI{{%1}}}; }; #func {tmux.ConvertFromANSI} { #local text {%1}; #if { {$text} == {%*{\e\[22(|;[0-9;]+)m}%*} } { #local esc {\e}; #line sub {var;escapes} #format esc {%s} {$esc}; #replace {text} {{\e\[22(|;([0-9;]+))m}} {#[none]@if{@str.Len{&2} > 0;{${esc}[&3m}}}; }; #replace {text} {{\e\[(3|4)8;5;(\d+)m}} {@tmux.ansi2tmux{&2;5;&3}}; #replace {text} {{\e\[(3|4)8;2;(\d+);(\d+);(\d+)m}} {@tmux.ansi2tmux{&2;2;&3;&4;&5}}; #local {mode} {TEXT}; #local output {}; #local pending {}; #local ch {}; #parse {$text} {ch} { #switch {"$mode"} { #case {"TEXT"} { #switch {"$ch"} { #case {"\e"} {#local mode {ESC}}; #case {";"} {#cat output { }}; #default {#cat output {$ch}}; }; }; #case {"ESC"} { #switch {"$ch"} { #case {"["} {#cat output {#[}; #local mode {SGR}}; #default {#cat output {$ch}; #local mode {TEXT}}; }; }; #case {"SGR"} { #switch {"$ch"} { #case {"0"} {#cat output {default}}; #case {"1"} {#cat output {bold}}; #case {"2"} {#cat output {dim}}; #case {"3"} {#local mode {PENDING3}}; #case {"4"} {#local mode {PENDING4}}; #case {"5"} {#cat output {blink}}; #case {";"} {#cat output { }}; #default { #if { "$pending" == "[" } {#cat output {default}}; #cat output {]}; #local mode {TEXT}; }; }; }; #case {"PENDING3"} { #switch {"$ch"} { #case {"{[0-7]}"} {#cat output {fg=colour$ch}; #local mode {SGR}}; #case {"9"} {#cat output {fg=default}; #local mode {SGR}}; #case {";"} {#cat output {italics }; #local mode {SGR}}; #case {"m"} {#cat output {italics]}; #local mode {TEXT}}; #default {#cat output {$ch]}; #local mode {TEXT}}; }; }; #case {"PENDING4"} { #switch {"$ch"} { #case {"{[0-7]}"} {#cat output {bg=colour$ch}; #local mode {SGR}}; #case {"9"} {#cat output {bg=default}; #local mode {SGR}}; #case {";"} {#cat output {underscore }; #local mode {SGR}}; #case {"m"} {#cat output {underscore]}; #local mode {TEXT}}; #default {#cat output {$ch]}; #local mode {TEXT}}; }; }; }; #local {pending} {$ch}; }; #return {$output#[default]}; }; #func {tmux.ansi2tmux} { #local {type} {%1}; #local {mode} {%2}; #local {arg1} {%3}; #local {arg2} {%4}; #local {arg3} {%5}; #local output {}; #nop 3 == 前景色, 4 == 背景色; #if { $type == 3 } { #cat output {#[fg=}; }; #elseif { $type == 4 } { #cat output {#[bg=}; }; #else { #return {}; }; #nop 5 == indexed colors, 2 == RGB colors; #if { $mode == 5 } { #cat output {colour$arg1]}; }; #elseif { $mode == 2 } { #local code {}; #format code {#%+02X%+02X%+02X} {$arg1} {$arg2} {$arg3}; #cat output {$code]}; }; #else { #return {}; }; #return {$output}; }; #func {tmux.Width} { #local arg {%1}; #replace {arg} {{#\[[^\]]*\]}} {}; #return {@str.Len{$arg}}; }; #nop 默认每分钟更新一次。; #tick tmux.Update {tmux.Update} 60;