@kecan0406/ttheme 1.2.6 → 1.2.7

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.2.6",
2
+ "version": "1.2.7",
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.2.6",
3
+ "version": "1.2.7",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "ttheme": "bin/ttheme.js"
@@ -74,6 +74,8 @@ __tt_paints() { return 0 }
74
74
 
75
75
  __tt_unpainted() { : }
76
76
 
77
+ __tt_reverts() { return 0 }
78
+
77
79
  __tt_follows_focus() { return 1 }
78
80
 
79
81
  __tt_takes_default() { return 0 }
@@ -188,8 +190,18 @@ __tt_start_bg() {
188
190
  [[ -n $REPLY ]]
189
191
  }
190
192
 
193
+ __tt_colors() {
194
+ local e
195
+ local -a p
196
+ for e in ${(ps:\e]:)1}; do
197
+ [[ $e == *';rgb:'* ]] || continue
198
+ p=(${(s:/:)${${e#*rgb:}%%[^0-9A-Fa-f/]*}})
199
+ (( ${#p} >= 3 )) && got[${e%%;rgb:*}]="#${(L)p[1][1,2]}${(L)p[2][1,2]}${(L)p[3][1,2]}"
200
+ done
201
+ }
202
+
191
203
  __tt_query_bg() {
192
- local resp
204
+ local -A got
193
205
  REPLY=""
194
206
  if (( TTHEME_TMUX )); then
195
207
  REPLY=$(tmux show -qv @ttheme_bg 2>/dev/null)
@@ -197,10 +209,7 @@ __tt_query_bg() {
197
209
  REPLY=""
198
210
  fi
199
211
  __tt_ask $'\e]11;?\e\\' || return 1
200
- resp=$REPLY
201
- REPLY=""
202
- [[ $resp == *rgb:* ]] || return 1
203
- local -a parts=(${(s:/:)${${resp#*rgb:}%%[^0-9A-Fa-f/]*}})
204
- (( ${#parts} >= 3 )) || return 1
205
- REPLY="#${(L)parts[1]:0:2}${(L)parts[2]:0:2}${(L)parts[3]:0:2}"
212
+ __tt_colors "$REPLY"
213
+ REPLY=$got[11]
214
+ [[ -n $REPLY ]]
206
215
  }
@@ -0,0 +1,5 @@
1
+ __tt_paints() { return 1 }
2
+
3
+ __tt_unpainted() {
4
+ print -u2 "ttheme: this shell runs in an editor's built-in terminal, whose colors come from the editor's theme — use ttheme in a terminal tab outside the editor"
5
+ }
@@ -7,6 +7,8 @@ fi
7
7
 
8
8
  __tt_keepable() { return 0 }
9
9
 
10
+ __tt_reverts() { return 1 }
11
+
10
12
  __tt_follows_focus() { return 0 }
11
13
 
12
14
  __tt_takes_default() {
@@ -8,6 +8,8 @@ __tt_keepable() { __tt_paints }
8
8
 
9
9
  __tt_takes_default() { __tt_osc_reset }
10
10
 
11
+ __tt_reverts() { return 1 }
12
+
11
13
  __tt_follows_focus() { return 0 }
12
14
 
13
15
  __tt_scheme() {
@@ -1,18 +1,12 @@
1
1
  typeset -g TTHEME_TERMINAL_BASE=""
2
2
 
3
3
  __tt_hear() {
4
- local resp q=$'\e]11;?\e\\\e]10;?\e\\\e]12;?\e\\\e]17;?\e\\' e v i
5
- local -a p
4
+ local q=$'\e]11;?\e\\\e]10;?\e\\\e]12;?\e\\\e]17;?\e\\' v i
6
5
  local -A got
7
6
  for i in {0..15}; do q+=$'\e]4;'$i$';?\e\\'; done
8
7
  __tt_ask $q || return 1
9
- resp=$REPLY
8
+ __tt_colors "$REPLY"
10
9
  REPLY=""
11
- for e in ${(ps:\e]:)resp}; do
12
- [[ $e == *';rgb:'* ]] || continue
13
- p=(${(s:/:)${${e#*rgb:}%%[^0-9A-Fa-f/]*}})
14
- (( ${#p} >= 3 )) && got[${e%%;rgb:*}]="#${(L)p[1][1,2]}${(L)p[2][1,2]}${(L)p[3][1,2]}"
15
- done
16
10
  v="$got[11] $got[10] $got[12] ${got[17]:-$got[11]}"
17
11
  for i in {0..15}; do v+=" ${got[4;$i]}"; done
18
12
  (( ${#${=v}} == 20 )) || return 1
@@ -23,6 +17,8 @@ __tt_heard() { TTHEME_TERMINAL_BASE=$1 }
23
17
 
24
18
  __tt_takes_default() { return 1 }
25
19
 
20
+ __tt_reverts() { return 1 }
21
+
26
22
  __tt_osc_reset() {
27
23
  [[ -n $TTHEME_TERMINAL_BASE ]] && __tt_osc_apply "$TTHEME_TERMINAL_BASE"
28
24
  unset TTHEME_PAINTED
@@ -26,6 +26,8 @@ __tt_unpainted() {
26
26
 
27
27
  __tt_keepable() { return 0 }
28
28
 
29
+ __tt_reverts() { return 1 }
30
+
29
31
  __tt_follows_prompt() { return 0 }
30
32
 
31
33
  __tt_prompted() {
package/shell/ttheme.zsh CHANGED
@@ -48,7 +48,7 @@ __tt_gone() {
48
48
  __tt_reload
49
49
  __tt_reset_reloaded $bg
50
50
  print -n $'\e[?1004l'
51
- for hook in precmd:__tt_prompt precmd:__tt_precmd precmd:__tt_prompted precmd:__tt_unmux preexec:__tt_preexec preexec:__tt_mux chpwd:__tt_chpwd; do
51
+ for hook in precmd:__tt_prompt precmd:__tt_precmd precmd:__tt_prompted precmd:__tt_unmux preexec:__tt_preexec preexec:__tt_ran chpwd:__tt_chpwd; do
52
52
  add-zsh-hook -d ${hook%%:*} ${hook#*:}
53
53
  done
54
54
  (( $+functions[add-zle-hook-widget] )) && add-zle-hook-widget -d line-init __tt_line_init
@@ -124,7 +124,9 @@ typeset -g TTHEME_STATE_DIR=${XDG_STATE_HOME:-$HOME/.local/state}/ttheme
124
124
 
125
125
  () {
126
126
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
127
- if [[ $TERM_PROGRAM == WarpTerminal ]]; then
127
+ if [[ -n $NVIM || -n $VIM_TERMINAL || -n $INSIDE_EMACS || $TERM_PROGRAM == vscode ]]; then
128
+ typeset -g TTHEME_ADAPTER=editor
129
+ elif [[ $TERM_PROGRAM == WarpTerminal ]]; then
128
130
  typeset -g TTHEME_ADAPTER=warp
129
131
  elif [[ -n $GHOSTTY_RESOURCES_DIR || $TERM_PROGRAM == ghostty ]]; then
130
132
  typeset -g TTHEME_ADAPTER=ghostty
@@ -163,7 +165,7 @@ __tt_active() {
163
165
  }
164
166
 
165
167
  typeset -g TTHEME_HEARD=""
166
- typeset -gi TTHEME_RECHECK=0 TTHEME_FOCUS=0 TTHEME_FRONT=-1
168
+ typeset -gi TTHEME_RECHECK=0 TTHEME_FOCUS=0 TTHEME_FRONT=-1 TTHEME_RAN=0
167
169
 
168
170
  __tt_put() {
169
171
  local f=${1:A}
@@ -237,6 +239,18 @@ __tt_recheck() {
237
239
  fi
238
240
  }
239
241
 
242
+ __tt_mend() {
243
+ local REPLY
244
+ local -a p=(${(L)=TTHEME_SPEC})
245
+ local -A got
246
+ TTHEME_RAN=0
247
+ [[ -n $TTHEME_PAINTED ]] && (( ${#p} >= 20 )) && __tt_reverts || return 0
248
+ __tt_ask $'\e]11;?\e\\\e]12;?\e\\' || return 0
249
+ __tt_colors "$REPLY"
250
+ [[ $p[1] == - || ${got[11]:-$p[1]} == $p[1] ]] && [[ ${got[12]:-$p[3]} == $p[3] ]] && return 0
251
+ __tt_apply "$TTHEME_SPEC"
252
+ }
253
+
240
254
  source $TTHEME_HOME/adapters/_osc.zsh
241
255
  source $TTHEME_HOME/adapters/_wired.zsh
242
256
  [[ -r $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh ]] &&
@@ -381,8 +395,9 @@ __tt_focus() {
381
395
  fi
382
396
  }
383
397
 
384
- __tt_mux() {
398
+ __tt_ran() {
385
399
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
400
+ TTHEME_RAN=1
386
401
  [[ ${${(z)3}[1]:t} == tmux ]] && TTHEME_MUXED=1
387
402
  }
388
403
 
@@ -402,6 +417,7 @@ __tt_blur() {
402
417
  __tt_line_init() {
403
418
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
404
419
  (( TTHEME_RECHECK )) && __tt_recheck
420
+ (( TTHEME_RAN )) && __tt_mend
405
421
  __tt_typed
406
422
  (( TTHEME_FOCUS )) && __tt_focus_on
407
423
  }
@@ -2859,7 +2875,7 @@ fi
2859
2875
  add-zsh-hook chpwd __tt_chpwd
2860
2876
  add-zsh-hook precmd __tt_prompt
2861
2877
  if (( ! TTHEME_TMUX )); then
2862
- add-zsh-hook preexec __tt_mux
2878
+ add-zsh-hook preexec __tt_ran
2863
2879
  add-zsh-hook precmd __tt_unmux
2864
2880
  fi
2865
2881
  if __tt_follows_focus || (( TTHEME_TMUX )); then