@kecan0406/ttheme 1.0.38 → 1.0.40

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.38",
2
+ "version": "1.0.40",
3
3
  "gate": [
4
4
  {
5
5
  "rule": "foreground",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kecan0406/ttheme",
3
- "version": "1.0.38",
3
+ "version": "1.0.40",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "ttheme": "bin/ttheme.js"
@@ -255,7 +255,7 @@ __tt_pv_bg_open() {
255
255
  bgcw=0 bgch=0 bginc="" bgrel=0 bgmx=0 bgmy=0 bganchor=0
256
256
  local REPLY
257
257
  __tt_bg_shown && bginc=$REPLY
258
- (( TTHEME_TMUX )) || __tt_bg_cells
258
+ (( TTHEME_TMUX )) || { __tt_bg_cells; TTHEME_TYPED= }
259
259
  }
260
260
 
261
261
  __tt_pv_bg_show() {
@@ -75,32 +75,55 @@ __tt_pv_bg_close() { : }
75
75
 
76
76
  __tt_pv_bg_save() { : }
77
77
 
78
- __tt_query_bg() {
79
- local saved resp="" c fd
80
- REPLY=""
81
- if (( TTHEME_TMUX )); then
82
- REPLY=$(tmux show -qv @ttheme_bg 2>/dev/null)
83
- [[ $REPLY == \#* ]] && return 0
84
- REPLY=""
85
- fi
86
- exec {fd}<>/dev/tty 2>/dev/null || return 1
78
+ zmodload zsh/system
79
+
80
+ typeset -g TTHEME_TYPED=""
87
81
 
88
- saved=$(stty -g <&$fd 2>/dev/null)
82
+ __tt_ask() {
83
+ setopt localoptions extendedglob
84
+ local fd saved buf="" chunk seqs=$'\e[]_P][^\a\e]#(\a|\e\\\\)|\e\\[[0-?]#[ -/]#[@-~]|\e[^][_P]'
85
+ local -a match mbegin mend
86
+ REPLY=""
87
+ { exec {fd}<>/dev/tty } 2>/dev/null || return 1
88
+ saved=$(stty -g <&$fd 2>/dev/null && stty raw -echo min 0 time 3 <&$fd 2>/dev/null)
89
89
  if [[ -z $saved ]]; then
90
90
  exec {fd}>&-
91
91
  return 1
92
92
  fi
93
-
94
- stty raw -echo min 0 time 3 <&$fd 2>/dev/null
95
- printf '\033]11;?\033\\' >&$fd
96
- while IFS= read -r -k 1 -u $fd c 2>/dev/null; do
97
- resp+=$c
98
- [[ $resp == *$'\e\\' || $resp == *$'\a' ]] && break
99
- (( ${#resp} < 64 )) || break
93
+ printf '%s\e[5n' "$1" >&$fd
94
+ while sysread -i $fd -s 4096 chunk 2>/dev/null; do
95
+ buf+=$chunk
96
+ [[ $buf == *$'\e[0n'* ]] && break
97
+ (( ${#buf} < 16384 )) || break
100
98
  done
101
99
  stty "$saved" <&$fd 2>/dev/null
102
100
  exec {fd}>&-
101
+ while [[ $buf == (#b)([^$'\e']#)(${~seqs})(*) ]]; do
102
+ TTHEME_TYPED+=$match[1] REPLY+=$match[2] buf=$match[-1]
103
+ done
104
+ [[ $buf == $'\e'* ]] || TTHEME_TYPED+=$buf
105
+ REPLY=${REPLY%$'\e[0n'}
106
+ }
103
107
 
108
+ __tt_typed() {
109
+ [[ -n $TTHEME_TYPED ]] || return 0
110
+ zle -U -- "$TTHEME_TYPED"
111
+ TTHEME_TYPED=
112
+ }
113
+
114
+ __tt_start_bg() { __tt_query_bg }
115
+
116
+ __tt_query_bg() {
117
+ local resp
118
+ REPLY=""
119
+ if (( TTHEME_TMUX )); then
120
+ REPLY=$(tmux show -qv @ttheme_bg 2>/dev/null)
121
+ [[ $REPLY == \#* ]] && return 0
122
+ REPLY=""
123
+ fi
124
+ __tt_ask $'\e]11;?\e\\' || return 1
125
+ resp=$REPLY
126
+ REPLY=""
104
127
  [[ $resp == *rgb:* ]] || return 1
105
128
  local -a parts=(${(s:/:)${${resp#*rgb:}%%[^0-9A-Fa-f/]*}})
106
129
  (( ${#parts} >= 3 )) || return 1
@@ -28,7 +28,7 @@ __tt_shown() {
28
28
  }
29
29
 
30
30
  __tt_bg_cells() {
31
- local fd saved resp="" line c v f
31
+ local REPLY resp line v f
32
32
  local -i px=2 py=2 fs=0 sc=2
33
33
  for f in ${XDG_CONFIG_HOME:-$HOME/.config}/ghostty/config; do
34
34
  [[ -r $f ]] || continue
@@ -41,16 +41,8 @@ __tt_bg_cells() {
41
41
  esac
42
42
  done
43
43
  done
44
- exec {fd}<>/dev/tty 2>/dev/null || return 0
45
- saved=$(stty -g <&$fd 2>/dev/null)
46
- stty raw -echo min 0 time 3 <&$fd 2>/dev/null
47
- printf '\e_Ga=t,f=24,s=1,v=1,i=1,q=2;AAAA\e\\\e_Ga=p,i=1,p=9,P=999998,Q=1,C=1,q=1\e\\\e_Ga=d,d=i,i=1,p=9,q=2\e\\\e[16t' >&$fd
48
- while IFS= read -r -s -k 1 -t 1 -u $fd c 2>/dev/null; do
49
- resp+=$c
50
- [[ $resp == *'[6;'<1->';'<1->t ]] && break
51
- done
52
- stty "$saved" <&$fd 2>/dev/null
53
- exec {fd}>&-
44
+ __tt_ask $'\e_Ga=t,f=24,s=1,v=1,i=1,q=2;AAAA\e\\\e_Ga=p,i=1,p=9,P=999998,Q=1,C=1,q=1\e\\\e_Ga=d,d=i,i=1,p=9,q=2\e\\\e[16t' || return 0
45
+ resp=$REPLY
54
46
  [[ $resp == *'[6;'<1->';'<1->t ]] || return 0
55
47
  [[ $resp == *$'\e_G'*';E'* ]] && bgrel=1
56
48
  resp=${${resp##*\[6;}%t}
@@ -39,18 +39,10 @@ __tt_unshown() {
39
39
  }
40
40
 
41
41
  __tt_bg_cells() {
42
- local fd saved resp="" c
42
+ local REPLY resp
43
43
  local -a p
44
- exec {fd}<>/dev/tty 2>/dev/null || return 0
45
- saved=$(stty -g <&$fd 2>/dev/null)
46
- stty raw -echo min 0 time 3 <&$fd 2>/dev/null
47
- printf '\e]1337;ReportCellSize\a' >&$fd
48
- while IFS= read -r -s -k 1 -t 1 -u $fd c 2>/dev/null; do
49
- resp+=$c
50
- [[ $resp == *ReportCellSize=*($'\a'|$'\e\\') ]] && break
51
- done
52
- stty "$saved" <&$fd 2>/dev/null
53
- exec {fd}>&-
44
+ __tt_ask $'\e]1337;ReportCellSize\a' || return 0
45
+ resp=$REPLY
54
46
  [[ $resp == *ReportCellSize=*($'\a'|$'\e\\') ]] || return 0
55
47
  p=(${(s:;:)${${resp##*ReportCellSize=}%%($'\a'|$'\e\\')*}})
56
48
  (( ${#p} == 3 )) || return 0
@@ -32,17 +32,9 @@ __tt_bg_shown() { REPLY=$TTHEME_KITTY_SHOWN }
32
32
  __tt_bg_refresh() { (( ${@[(Ie)$TTHEME_KITTY_SHOWN]} )) && __tt_kitty_var ttheme_shown $TTHEME_KITTY_SHOWN }
33
33
 
34
34
  __tt_bg_cells() {
35
- local fd saved resp="" c
36
- exec {fd}<>/dev/tty 2>/dev/null || return 0
37
- saved=$(stty -g <&$fd 2>/dev/null)
38
- stty raw -echo min 0 time 3 <&$fd 2>/dev/null
39
- printf '\e[16t' >&$fd
40
- while IFS= read -r -s -k 1 -t 1 -u $fd c 2>/dev/null; do
41
- resp+=$c
42
- [[ $resp == *'[6;'<1->';'<1->t ]] && break
43
- done
44
- stty "$saved" <&$fd 2>/dev/null
45
- exec {fd}>&-
35
+ local REPLY resp
36
+ __tt_ask $'\e[16t' || return 0
37
+ resp=$REPLY
46
38
  [[ $resp == *'[6;'<1->';'<1->t ]] || return 0
47
39
  resp=${${resp##*\[6;}%t}
48
40
  bgch=${resp%;*} bgcw=${resp#*;}
@@ -1,22 +1,12 @@
1
1
  typeset -g TTHEME_TERMINAL_BASE=""
2
2
 
3
3
  __tt_terminal_base() {
4
- local fd saved resp="" c q=$'\e]11;?\e\\\e]10;?\e\\\e]12;?\e\\\e]17;?\e\\' e v i
4
+ local REPLY 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
- exec {fd}<>/dev/tty 2>/dev/null || return 1
9
- saved=$(stty -g <&$fd 2>/dev/null)
10
- [[ -n $saved ]] || { exec {fd}>&-; return 1 }
11
- stty raw -echo min 0 time 3 <&$fd 2>/dev/null
12
- printf '%s\e[5n' $q >&$fd
13
- while IFS= read -r -k 1 -u $fd c 2>/dev/null; do
14
- resp+=$c
15
- [[ $resp == *$'\e[0n' ]] && break
16
- (( ${#resp} < 2048 )) || break
17
- done
18
- stty "$saved" <&$fd 2>/dev/null
19
- exec {fd}>&-
8
+ __tt_ask $q || return 1
9
+ resp=$REPLY
20
10
  for e in ${(ps:\e]:)resp}; do
21
11
  [[ $e == *';rgb:'* ]] || continue
22
12
  p=(${(s:/:)${${e#*rgb:}%%[^0-9A-Fa-f/]*}})
@@ -27,6 +17,11 @@ __tt_terminal_base() {
27
17
  (( ${#${=v}} == 20 )) && TTHEME_TERMINAL_BASE=$v
28
18
  }
29
19
 
20
+ __tt_start_bg() {
21
+ REPLY=${TTHEME_TERMINAL_BASE%% *}
22
+ [[ -n $REPLY ]]
23
+ }
24
+
30
25
  __tt_osc_reset() {
31
26
  [[ -n $TTHEME_TERMINAL_BASE ]] && __tt_osc_apply "$TTHEME_TERMINAL_BASE"
32
27
  return 0
package/shell/ttheme.zsh CHANGED
@@ -31,7 +31,10 @@ __tt_gone() {
31
31
  for hook in precmd:__tt_fresh precmd:__tt_precmd precmd:__tt_unmux preexec:__tt_preexec preexec:__tt_mux chpwd:__tt_chpwd; do
32
32
  add-zsh-hook -d ${hook%%:*} ${hook#*:}
33
33
  done
34
- (( $+functions[add-zle-hook-widget] )) && add-zle-hook-widget -d line-init __tt_focus_on
34
+ if (( $+functions[add-zle-hook-widget] )); then
35
+ add-zle-hook-widget -d line-init __tt_focus_on
36
+ add-zle-hook-widget -d line-init __tt_typed
37
+ fi
35
38
  unfunction ttheme
36
39
  }
37
40
 
@@ -1691,7 +1694,7 @@ if __tt_active; then
1691
1694
  if [[ -n $TTHEME_SPEC ]]; then
1692
1695
  :
1693
1696
  elif [[ $TTHEME_TAB_PALETTE == off ]]; then
1694
- if __tt_query_bg; then
1697
+ if __tt_start_bg; then
1695
1698
  for k in ${(k)TTHEME_PALETTE}; do
1696
1699
  [[ ${TTHEME_PALETTE[$k]%% *} == "$REPLY" ]] && { TTHEME_SPEC=$TTHEME_PALETTE[$k]; break }
1697
1700
  done
@@ -1703,7 +1706,9 @@ if __tt_active; then
1703
1706
  fi
1704
1707
  __tt_dir_sync
1705
1708
  }
1706
- autoload -Uz add-zsh-hook
1709
+ autoload -Uz add-zsh-hook add-zle-hook-widget
1710
+ zle -N __tt_typed
1711
+ add-zle-hook-widget line-init __tt_typed
1707
1712
  add-zsh-hook chpwd __tt_chpwd
1708
1713
  add-zsh-hook precmd __tt_fresh
1709
1714
  if (( ! TTHEME_TMUX )); then