@kecan0406/ttheme 1.0.45 → 1.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ttheme.js +154 -154
- package/bin/ttheme.js.map +1 -1
- package/dist/manifest.json +1 -1
- package/package.json +1 -1
- package/shell/adapters/_bg.zsh +17 -16
- package/shell/adapters/_osc.zsh +48 -8
- package/shell/adapters/iterm2.zsh +13 -2
- package/shell/adapters/kitty.zsh +5 -1
- package/shell/adapters/terminal-app.zsh +8 -8
- package/shell/adapters/wezterm.zsh +5 -1
- package/shell/ttheme.zsh +206 -116
package/dist/manifest.json
CHANGED
package/package.json
CHANGED
package/shell/adapters/_bg.zsh
CHANGED
|
@@ -29,18 +29,6 @@ __tt_bg_refresh() { : }
|
|
|
29
29
|
|
|
30
30
|
__tt_bg_aligns() { (( ! ${TTHEME_TERMINALS[(Ie)iterm2]} )) }
|
|
31
31
|
|
|
32
|
-
__tt_b64() {
|
|
33
|
-
local t=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ out="" i n
|
|
34
|
-
local -a b=("$@")
|
|
35
|
-
for (( i = 1; i <= ${#b}; i += 3 )); do
|
|
36
|
-
n=$(( (b[i] << 16) | (${b[i+1]:-0} << 8) | ${b[i+2]:-0} ))
|
|
37
|
-
out+=${t:$(( (n >> 18) & 63 )):1}${t:$(( (n >> 12) & 63 )):1}
|
|
38
|
-
if (( i + 1 <= ${#b} )); then out+=${t:$(( (n >> 6) & 63 )):1}; else out+='='; fi
|
|
39
|
-
if (( i + 2 <= ${#b} )); then out+=${t:$(( n & 63 )):1}; else out+='='; fi
|
|
40
|
-
done
|
|
41
|
-
REPLY=$out
|
|
42
|
-
}
|
|
43
|
-
|
|
44
32
|
__tt_bg_frame() {
|
|
45
33
|
local -i iw=$1 ih=$2 W=$3 H=$4 s=$5 ax=$(( ($6 - 1) % 3 )) ay=$(( ($6 - 1) / 3 )) f=${8:--1} wide dw dh ox oy
|
|
46
34
|
wide=$(( W * ih >= H * iw ))
|
|
@@ -155,11 +143,22 @@ __tt_bg_label() {
|
|
|
155
143
|
}
|
|
156
144
|
|
|
157
145
|
__tt_bg_dim() {
|
|
158
|
-
|
|
159
|
-
local
|
|
146
|
+
setopt localoptions nomultibyte
|
|
147
|
+
local img=$1 fd hdr="" c
|
|
148
|
+
local -a d=()
|
|
149
|
+
local -i i n
|
|
160
150
|
[[ -n $img && -r $img ]] || return 1
|
|
161
151
|
if [[ -z ${bgdim[$img]} ]]; then
|
|
162
|
-
|
|
152
|
+
if { exec {fd}<$img } 2>/dev/null; then
|
|
153
|
+
sysread -s 24 -i $fd hdr
|
|
154
|
+
exec {fd}<&-
|
|
155
|
+
fi
|
|
156
|
+
for (( i = 1; i <= ${#hdr}; i++ )); do
|
|
157
|
+
c=${hdr[i]}
|
|
158
|
+
n=$(( #c ))
|
|
159
|
+
(( n < 0 )) && (( n += 256 ))
|
|
160
|
+
d+=($n)
|
|
161
|
+
done
|
|
163
162
|
if (( ${#d} == 24 && d[1] == 137 && d[2] == 80 && d[3] == 78 && d[4] == 71 )); then
|
|
164
163
|
bgdim[$img]="$(( (d[17] << 24) | (d[18] << 16) | (d[19] << 8) | d[20] )) $(( (d[21] << 24) | (d[22] << 16) | (d[23] << 8) | d[24] ))"
|
|
165
164
|
else
|
|
@@ -314,7 +313,8 @@ __tt_pv_bg_show() {
|
|
|
314
313
|
__tt_bg_send() {
|
|
315
314
|
if [[ -z ${bgsent[$1]} ]]; then
|
|
316
315
|
bgsent[$1]=$(( ${#bgsent} + 3 ))
|
|
317
|
-
|
|
316
|
+
__tt_b64s "$1"
|
|
317
|
+
printf '\e_Ga=t,t=f,f=100,i=%d,q=2;%s\e\\' ${bgsent[$1]} "$REPLY"
|
|
318
318
|
fi
|
|
319
319
|
REPLY=${bgsent[$1]}
|
|
320
320
|
}
|
|
@@ -406,6 +406,7 @@ __tt_pv_bg_findable() {
|
|
|
406
406
|
__tt_pv_bg_find() {
|
|
407
407
|
local name=$1 err var
|
|
408
408
|
local -i rc
|
|
409
|
+
[[ $applied == "$painted" ]] || { __tt_apply "$applied" && painted=$applied }
|
|
409
410
|
__tt_pv_bg_close
|
|
410
411
|
err=$(__tt_cli find $name 2>&1 >/dev/tty)
|
|
411
412
|
rc=$?
|
package/shell/adapters/_osc.zsh
CHANGED
|
@@ -19,6 +19,7 @@ __tt_osc_apply() {
|
|
|
19
19
|
out+=$'\e]10;'$p[2]$'\e\\\e]12;'$p[3]$'\e\\\e]17;'$p[4]$'\e\\'
|
|
20
20
|
for i in {0..15}; do out+=$'\e]4;'$i';'$p[i+5]$'\e\\'; done
|
|
21
21
|
__tt_out "$out"
|
|
22
|
+
export TTHEME_PAINTED=1
|
|
22
23
|
(( TTHEME_TMUX )) && tmux set -q @ttheme_bg "$p[1]" 2>/dev/null
|
|
23
24
|
__tt_worn "$1"
|
|
24
25
|
return 0
|
|
@@ -26,6 +27,7 @@ __tt_osc_apply() {
|
|
|
26
27
|
|
|
27
28
|
__tt_osc_reset() {
|
|
28
29
|
__tt_out $'\e]104\e\\\e]110\e\\\e]111\e\\\e]112\e\\\e]117\e\\'
|
|
30
|
+
unset TTHEME_PAINTED
|
|
29
31
|
(( TTHEME_TMUX )) && tmux set -qu @ttheme_bg 2>/dev/null
|
|
30
32
|
__tt_worn ""
|
|
31
33
|
return 0
|
|
@@ -43,6 +45,8 @@ __tt_repaint() {
|
|
|
43
45
|
|
|
44
46
|
__tt_apply() { __tt_osc_apply "$@" }
|
|
45
47
|
|
|
48
|
+
__tt_pv_paint() { __tt_apply "$1" && painted=$1 }
|
|
49
|
+
|
|
46
50
|
__tt_shown() { return 1 }
|
|
47
51
|
|
|
48
52
|
__tt_unshown() { : }
|
|
@@ -78,25 +82,54 @@ __tt_pv_bg_save() { : }
|
|
|
78
82
|
zmodload zsh/system
|
|
79
83
|
|
|
80
84
|
typeset -g TTHEME_TYPED=""
|
|
85
|
+
typeset -gi TTHEME_RAW=0
|
|
86
|
+
|
|
87
|
+
__tt_b64() {
|
|
88
|
+
local t=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ out="" i n
|
|
89
|
+
local -a b=("$@")
|
|
90
|
+
for (( i = 1; i <= ${#b}; i += 3 )); do
|
|
91
|
+
n=$(( (b[i] << 16) | (${b[i+1]:-0} << 8) | ${b[i+2]:-0} ))
|
|
92
|
+
out+=${t:$(( (n >> 18) & 63 )):1}${t:$(( (n >> 12) & 63 )):1}
|
|
93
|
+
if (( i + 1 <= ${#b} )); then out+=${t:$(( (n >> 6) & 63 )):1}; else out+='='; fi
|
|
94
|
+
if (( i + 2 <= ${#b} )); then out+=${t:$(( n & 63 )):1}; else out+='='; fi
|
|
95
|
+
done
|
|
96
|
+
REPLY=$out
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
__tt_b64s() {
|
|
100
|
+
setopt localoptions nomultibyte
|
|
101
|
+
local s=$1 c
|
|
102
|
+
local -a b=()
|
|
103
|
+
local -i i n
|
|
104
|
+
for (( i = 1; i <= ${#s}; i++ )); do
|
|
105
|
+
c=${s[i]}
|
|
106
|
+
n=$(( #c ))
|
|
107
|
+
(( n < 0 )) && (( n += 256 ))
|
|
108
|
+
b+=($n)
|
|
109
|
+
done
|
|
110
|
+
__tt_b64 $b
|
|
111
|
+
}
|
|
81
112
|
|
|
82
113
|
__tt_ask() {
|
|
83
114
|
setopt localoptions extendedglob
|
|
84
|
-
local fd saved buf="" chunk seqs=$'\e[]_P][^\a\e]#(\a|\e\\\\)|\e\\[[0-?]#[ -/]#[@-~]|\e[^][_P]'
|
|
115
|
+
local fd saved="" buf="" chunk seqs=$'\e[]_P][^\a\e]#(\a|\e\\\\)|\e\\[[0-?]#[ -/]#[@-~]|\e[^][_P]'
|
|
85
116
|
local -a match mbegin mend
|
|
86
117
|
REPLY=""
|
|
87
118
|
{ exec {fd}<>/dev/tty } 2>/dev/null || return 1
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
119
|
+
if (( ! TTHEME_RAW )) && ! zle; then
|
|
120
|
+
saved=$(stty -g <&$fd 2>/dev/null && stty raw -echo <&$fd 2>/dev/null)
|
|
121
|
+
if [[ -z $saved ]]; then
|
|
122
|
+
exec {fd}>&-
|
|
123
|
+
return 1
|
|
124
|
+
fi
|
|
92
125
|
fi
|
|
93
126
|
printf '%s\e[5n' "$1" >&$fd
|
|
94
|
-
while sysread -i $fd -s 4096 chunk 2>/dev/null; do
|
|
127
|
+
while sysread -t 0.3 -i $fd -s 4096 chunk 2>/dev/null; do
|
|
95
128
|
buf+=$chunk
|
|
96
129
|
[[ $buf == *$'\e[0n'* ]] && break
|
|
97
130
|
(( ${#buf} < 16384 )) || break
|
|
98
131
|
done
|
|
99
|
-
stty "$saved" <&$fd 2>/dev/null
|
|
132
|
+
[[ -n $saved ]] && stty "$saved" <&$fd 2>/dev/null
|
|
100
133
|
exec {fd}>&-
|
|
101
134
|
while [[ $buf == (#b)([^$'\e']#)(${~seqs})(*) ]]; do
|
|
102
135
|
TTHEME_TYPED+=$match[1] REPLY+=$match[2] buf=$match[-1]
|
|
@@ -111,7 +144,14 @@ __tt_typed() {
|
|
|
111
144
|
TTHEME_TYPED=
|
|
112
145
|
}
|
|
113
146
|
|
|
114
|
-
|
|
147
|
+
__tt_hear() { __tt_query_bg }
|
|
148
|
+
|
|
149
|
+
__tt_heard() { : }
|
|
150
|
+
|
|
151
|
+
__tt_start_bg() {
|
|
152
|
+
REPLY=${TTHEME_HEARD%% *}
|
|
153
|
+
[[ -n $REPLY ]]
|
|
154
|
+
}
|
|
115
155
|
|
|
116
156
|
__tt_query_bg() {
|
|
117
157
|
local resp
|
|
@@ -7,6 +7,17 @@ fi
|
|
|
7
7
|
|
|
8
8
|
__tt_keepable() { return 0 }
|
|
9
9
|
|
|
10
|
+
__tt_pv_paint() {
|
|
11
|
+
local -a p=(${=1})
|
|
12
|
+
if (( ${#p} < 20 )); then
|
|
13
|
+
__tt_out $'\e]110\e\\\e]111\e\\'
|
|
14
|
+
elif [[ $p[1] == - ]]; then
|
|
15
|
+
__tt_out $'\e]111\e\\\e]10;'$p[2]$'\e\\'
|
|
16
|
+
else
|
|
17
|
+
__tt_out $'\e]11;'$p[1]$'\e\\\e]10;'$p[2]$'\e\\'
|
|
18
|
+
fi
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
__tt_bg_shown() {
|
|
11
22
|
REPLY=""
|
|
12
23
|
(( TTHEME_TMUX )) && REPLY=$(tmux show -qv @ttheme_shown 2>/dev/null)
|
|
@@ -67,6 +78,6 @@ __tt_bg_crop() {
|
|
|
67
78
|
sips -c $h $iw --cropOffset 1 1 $bgcut/pad.png --out $band >/dev/null 2>&1 || return 1
|
|
68
79
|
fi
|
|
69
80
|
fi
|
|
70
|
-
|
|
71
|
-
REPLY="
|
|
81
|
+
__tt_bg_send $band
|
|
82
|
+
REPLY="$REPLY 0"
|
|
72
83
|
}
|
package/shell/adapters/kitty.zsh
CHANGED
|
@@ -4,7 +4,11 @@ typeset -g TTHEME_KITTY_SHOWN=""
|
|
|
4
4
|
|
|
5
5
|
__tt_keepable() { (( ${TTHEME_TERMINALS[(Ie)kitty]} )) }
|
|
6
6
|
|
|
7
|
-
__tt_kitty_var() {
|
|
7
|
+
__tt_kitty_var() {
|
|
8
|
+
local REPLY
|
|
9
|
+
__tt_b64s "$2"
|
|
10
|
+
__tt_out $'\e]1337;SetUserVar='$1'='$REPLY$'\a'
|
|
11
|
+
}
|
|
8
12
|
|
|
9
13
|
__tt_shown() {
|
|
10
14
|
[[ $2 != force && $TTHEME_KITTY_SHOWN == $1 ]] && return 1
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
typeset -g TTHEME_TERMINAL_BASE=""
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
local
|
|
3
|
+
__tt_hear() {
|
|
4
|
+
local resp q=$'\e]11;?\e\\\e]10;?\e\\\e]12;?\e\\\e]17;?\e\\' e v i
|
|
5
5
|
local -a p
|
|
6
6
|
local -A got
|
|
7
7
|
for i in {0..15}; do q+=$'\e]4;'$i$';?\e\\'; done
|
|
8
8
|
__tt_ask $q || return 1
|
|
9
9
|
resp=$REPLY
|
|
10
|
+
REPLY=""
|
|
10
11
|
for e in ${(ps:\e]:)resp}; do
|
|
11
12
|
[[ $e == *';rgb:'* ]] || continue
|
|
12
13
|
p=(${(s:/:)${${e#*rgb:}%%[^0-9A-Fa-f/]*}})
|
|
@@ -14,17 +15,16 @@ __tt_terminal_base() {
|
|
|
14
15
|
done
|
|
15
16
|
v="$got[11] $got[10] $got[12] ${got[17]:-$got[11]}"
|
|
16
17
|
for i in {0..15}; do v+=" ${got[4;$i]}"; done
|
|
17
|
-
(( ${#${=v}} == 20 ))
|
|
18
|
+
(( ${#${=v}} == 20 )) || return 1
|
|
19
|
+
REPLY=$v
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
REPLY=${TTHEME_TERMINAL_BASE%% *}
|
|
22
|
-
[[ -n $REPLY ]]
|
|
23
|
-
}
|
|
22
|
+
__tt_heard() { TTHEME_TERMINAL_BASE=$1 }
|
|
24
23
|
|
|
25
24
|
__tt_osc_reset() {
|
|
26
25
|
[[ -n $TTHEME_TERMINAL_BASE ]] && __tt_osc_apply "$TTHEME_TERMINAL_BASE"
|
|
26
|
+
unset TTHEME_PAINTED
|
|
27
27
|
return 0
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
[[ -o interactive && -t 1 ]] &&
|
|
30
|
+
[[ -o interactive && -t 1 ]] && __tt_listen
|
|
@@ -2,7 +2,11 @@ typeset -g TTHEME_WEZTERM_SHOWN=""
|
|
|
2
2
|
|
|
3
3
|
__tt_keepable() { (( ${TTHEME_TERMINALS[(Ie)wezterm]} )) }
|
|
4
4
|
|
|
5
|
-
__tt_wezterm_show() {
|
|
5
|
+
__tt_wezterm_show() {
|
|
6
|
+
local REPLY
|
|
7
|
+
__tt_b64s "$1"
|
|
8
|
+
printf '\e]1337;SetUserVar=ttheme_shown=%s\a' "$REPLY"
|
|
9
|
+
}
|
|
6
10
|
|
|
7
11
|
__tt_shown() {
|
|
8
12
|
[[ $2 != force && $TTHEME_WEZTERM_SHOWN == $1 ]] && return 1
|