@kecan0406/ttheme 1.2.5 → 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.5",
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.5",
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 }
@@ -82,6 +84,8 @@ __tt_follows_prompt() { return 1 }
82
84
 
83
85
  __tt_prompted() { : }
84
86
 
87
+ __tt_pv_conf_rows() { : }
88
+
85
89
  __tt_pv_bg_open() { : }
86
90
 
87
91
  __tt_pv_bg_show() { : }
@@ -186,8 +190,18 @@ __tt_start_bg() {
186
190
  [[ -n $REPLY ]]
187
191
  }
188
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
+
189
203
  __tt_query_bg() {
190
- local resp
204
+ local -A got
191
205
  REPLY=""
192
206
  if (( TTHEME_TMUX )); then
193
207
  REPLY=$(tmux show -qv @ttheme_bg 2>/dev/null)
@@ -195,10 +209,7 @@ __tt_query_bg() {
195
209
  REPLY=""
196
210
  fi
197
211
  __tt_ask $'\e]11;?\e\\' || return 1
198
- resp=$REPLY
199
- REPLY=""
200
- [[ $resp == *rgb:* ]] || return 1
201
- local -a parts=(${(s:/:)${${resp#*rgb:}%%[^0-9A-Fa-f/]*}})
202
- (( ${#parts} >= 3 )) || return 1
203
- 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 ]]
204
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
@@ -2,8 +2,9 @@ source $TTHEME_HOME/adapters/_bg.zsh
2
2
 
3
3
  typeset -g TTHEME_WARP_SETTINGS=$HOME/.warp/settings.toml TTHEME_WARP_THEMES=$HOME/.warp/themes TTHEME_WARP_WORN=""
4
4
  typeset -g TTHEME_WARP_TABS=$TTHEME_STATE_DIR/warp TTHEME_WARP_DB="" TTHEME_WARP_ID="" TTHEME_WARP_LAST="" TTHEME_WARP_SEEN=""
5
- typeset -g TTHEME_WARP_SHOWING="" TTHEME_WARP_VIEW=""
6
- typeset -gi TTHEME_WARP_VIEWS=0 TTHEME_WARP_BUSY=0 TTHEME_WARP_FOLLOWS=-1 TTHEME_WARP_TICK=0
5
+ typeset -g TTHEME_WARP_SHOWING="" TTHEME_WARP_VIEW="" TTHEME_WARP_CODE="" TTHEME_WARP_RECORDS=""
6
+ typeset -gi TTHEME_WARP_VIEWS=0 TTHEME_WARP_BUSY=0 TTHEME_WARP_FOLLOWS=-1 TTHEME_WARP_UP=0 TTHEME_WARP_SQLPID=0 TTHEME_WARP_MIXED=0
7
+ typeset -gF TTHEME_WARP_WARM=0 TTHEME_WARP_PRIMED=0 TTHEME_WARP_LIVED=0
7
8
  typeset -ga TTHEME_WARP_LAID=()
8
9
  typeset -g TTHEME_WARP_SQL='with t as (select id, window_id, row_number() over (partition by window_id order by id) - 1 as ix from tabs) select lower(hex(p.uuid)) from app a join windows w on w.id = a.active_window_id join t on t.window_id = w.id and t.ix = w.active_tab_index join pane_nodes n on n.tab_id = t.id and n.is_leaf join pane_leaves l on l.pane_node_id = n.id and l.is_focused join terminal_panes p on p.id = n.id'
9
10
  if [[ $OSTYPE != darwin* ]]; then
@@ -25,6 +26,8 @@ __tt_unpainted() {
25
26
 
26
27
  __tt_keepable() { return 0 }
27
28
 
29
+ __tt_reverts() { return 1 }
30
+
28
31
  __tt_follows_prompt() { return 0 }
29
32
 
30
33
  __tt_prompted() {
@@ -194,8 +197,48 @@ __tt_warp_follow() {
194
197
 
195
198
  __tt_warp_active() {
196
199
  setopt localoptions extendedglob
197
- REPLY=$(sqlite3 -readonly -cmd '.timeout 300' $TTHEME_WARP_DB $TTHEME_WARP_SQL 2>/dev/null)
198
- [[ $REPLY == [0-9a-f](#c32) ]]
200
+ local line
201
+ REPLY=""
202
+ if (( ! TTHEME_WARP_SQLPID )) || ! kill -0 $TTHEME_WARP_SQLPID 2>/dev/null; then
203
+ coproc sqlite3 -readonly -batch -cmd '.timeout 300' $TTHEME_WARP_DB 2>/dev/null
204
+ TTHEME_WARP_SQLPID=$!
205
+ fi
206
+ if print -rp -- "$TTHEME_WARP_SQL; select 'end';" 2>/dev/null; then
207
+ while read -rp -t 1 line; do
208
+ [[ $line == end ]] && { [[ $REPLY == [0-9a-f](#c32) ]]; return }
209
+ REPLY=$line
210
+ done
211
+ fi
212
+ TTHEME_WARP_SQLPID=0 REPLY=""
213
+ return 1
214
+ }
215
+
216
+ __tt_warp_stamp() {
217
+ local -a at
218
+ zstat -F %s.%N -A at +mtime -- $TTHEME_WARP_DB-wal 2>/dev/null || zstat -F %s.%N -A at +mtime -- $TTHEME_WARP_DB 2>/dev/null || return 1
219
+ REPLY=$at[1]
220
+ }
221
+
222
+ __tt_warp_mixed() {
223
+ setopt localoptions extendedglob
224
+ local f pal view
225
+ local -a rec
226
+ local -A looks
227
+ for f in $TTHEME_WARP_TABS/[0-9a-f](#c32)(N); do
228
+ rec=(${=${"$(<$f)"}})
229
+ pal=${rec[3]#-} view=${rec[4]#-}
230
+ [[ $rec[2] != - && -z $TTHEME_STARTUP ]] && pal="" view=""
231
+ pal="${pal:-$TTHEME_STARTUP} $view"
232
+ looks[$pal]=1
233
+ done
234
+ (( ${#looks} > 1 ))
235
+ }
236
+
237
+ __tt_warp_prime() {
238
+ local fd byte
239
+ sysopen -rw -u fd $TTHEME_WARP_SETTINGS 2>/dev/null || return 0
240
+ sysread -s 1 -i $fd byte && sysseek -u $fd 0 && syswrite -o $fd -- $byte
241
+ exec {fd}>&-
199
242
  }
200
243
 
201
244
  __tt_warp_line() {
@@ -207,18 +250,28 @@ __tt_warp_line() {
207
250
  __tt_warp_tick() {
208
251
  local line="" REPLY
209
252
  local -a at
210
- if zstat -F %s.%N -A at +mtime -- $TTHEME_WARP_DB-wal 2>/dev/null || zstat -F %s.%N -A at +mtime -- $TTHEME_WARP_DB 2>/dev/null; then
211
- if [[ $at[1] != "$TTHEME_WARP_SEEN" ]]; then
212
- TTHEME_WARP_SEEN=$at[1]
213
- if __tt_warp_active && [[ $REPLY != "$TTHEME_WARP_ID" ]]; then
214
- TTHEME_WARP_ID=$REPLY
253
+ integer recount=0
254
+ if __tt_warp_stamp && [[ $REPLY != "$TTHEME_WARP_SEEN" ]]; then
255
+ TTHEME_WARP_SEEN=$REPLY
256
+ if __tt_warp_active; then
257
+ TTHEME_WARP_UP=1
258
+ if [[ $REPLY != "$TTHEME_WARP_ID" ]]; then
259
+ TTHEME_WARP_ID=$REPLY recount=1
215
260
  __tt_put $TTHEME_WARP_TABS/.active $REPLY 2>/dev/null
216
261
  fi
262
+ else
263
+ TTHEME_WARP_UP=0
217
264
  fi
218
265
  fi
219
- zstat -F %s.%N -A at +mtime -- $TTHEME_HOME/palettes.zsh 2>/dev/null && [[ $at[1] != "$TTHEME_PALETTES_AT" ]] && __tt_palettes_load
266
+ zstat -F %s.%N -A at +mtime -- $TTHEME_HOME/palettes.zsh 2>/dev/null && [[ $at[1] != "$TTHEME_PALETTES_AT" ]] && __tt_palettes_load && recount=1
267
+ zstat -F %s.%N -A at +mtime -- $TTHEME_WARP_TABS 2>/dev/null && [[ $at[1] != "$TTHEME_WARP_RECORDS" ]] && TTHEME_WARP_RECORDS=$at[1] recount=1
268
+ if (( recount )); then
269
+ __tt_warp_mixed
270
+ TTHEME_WARP_MIXED=$(( ! $? ))
271
+ fi
220
272
  [[ -n $TTHEME_WARP_ID && -r $TTHEME_WARP_TABS/$TTHEME_WARP_ID ]] && line=$(<$TTHEME_WARP_TABS/$TTHEME_WARP_ID)
221
273
  [[ "$TTHEME_WARP_ID $line $TTHEME_PALETTES_AT" == "$TTHEME_WARP_LAST" ]] && return 0
274
+ [[ ${TTHEME_WARP_LAST%% *} == "$TTHEME_WARP_ID" ]] && TTHEME_WARP_WARM=$(( EPOCHREALTIME + 3 ))
222
275
  TTHEME_WARP_LAST="$TTHEME_WARP_ID $line $TTHEME_PALETTES_AT"
223
276
  [[ -n $line ]] && __tt_warp_line ${=line} && __tt_warp_wear "$REPLY"
224
277
  return 0
@@ -239,15 +292,64 @@ __tt_warp_live() {
239
292
  (( live ))
240
293
  }
241
294
 
295
+ __tt_pv_conf_rows() {
296
+ cvars+=(TTHEME_WARP_FAST) clabel+=("Warp tabs") cchoice+=("on off") cshow+=("on off")
297
+ cnote+=(
298
+ TTHEME_WARP_FAST:on "About 0.2 s per switch, for about 8% CPU"
299
+ TTHEME_WARP_FAST:off "About 0.6 s per switch"
300
+ )
301
+ }
302
+
303
+ __tt_warp_warming() {
304
+ [[ $TTHEME_WARP_FAST == on ]] && (( TTHEME_WARP_UP && ( TTHEME_WARP_MIXED || EPOCHREALTIME < TTHEME_WARP_WARM ) ))
305
+ }
306
+
307
+ __tt_warp_wait() {
308
+ local REPLY
309
+ local -F now=$EPOCHREALTIME end=$(( EPOCHREALTIME + 0.1 ))
310
+ if ! __tt_warp_warming; then
311
+ zselect -t 10
312
+ return 0
313
+ fi
314
+ while (( now < end )); do
315
+ if (( now - TTHEME_WARP_PRIMED >= 0.25 )); then
316
+ __tt_warp_prime
317
+ TTHEME_WARP_PRIMED=$now
318
+ fi
319
+ zselect -t 2
320
+ __tt_warp_stamp && [[ $REPLY != "$TTHEME_WARP_SEEN" ]] && return 0
321
+ now=$EPOCHREALTIME
322
+ done
323
+ return 0
324
+ }
325
+
326
+ __tt_warp_code() {
327
+ local -a at conf
328
+ zstat -F %s.%N -A at +mtime -- $TTHEME_HOME/adapters/warp.zsh 2>/dev/null
329
+ zstat -F %s.%N -A conf +mtime -- $TTHEME_CONFIG 2>/dev/null
330
+ REPLY="$at[1] $conf[1]"
331
+ }
332
+
242
333
  __tt_warp_follower() {
243
334
  emulate -L zsh
244
- local fd
335
+ local fd REPLY
245
336
  __tt_warp_db && zsystem flock -t 0 -f fd $TTHEME_WARP_TABS/.follow 2>/dev/null || return 0
246
- trap '' HUP
337
+ trap '' HUP PIPE
338
+ __tt_warp_code
339
+ TTHEME_WARP_CODE=$REPLY TTHEME_WARP_LIVED=$EPOCHREALTIME
247
340
  while [[ -e $TTHEME_HOME/palettes.zsh && -e $TTHEME_WARP_DB ]]; do
248
341
  __tt_warp_tick
249
- (( ++TTHEME_WARP_TICK % 50 )) || __tt_warp_live || break
250
- zselect -t 10
342
+ if (( EPOCHREALTIME - TTHEME_WARP_LIVED >= 5 )); then
343
+ TTHEME_WARP_LIVED=$EPOCHREALTIME
344
+ __tt_warp_live || break
345
+ __tt_warp_code
346
+ if [[ $REPLY != "$TTHEME_WARP_CODE" ]]; then
347
+ coproc :
348
+ zsystem flock -u $fd
349
+ exec zsh -fc 'source $1; __tt_warp_follower' zsh $TTHEME_HOME/ttheme.zsh
350
+ fi
351
+ fi
352
+ __tt_warp_wait
251
353
  done
252
354
  zf_rm -f -- $TTHEME_WARP_TABS/.active 2>/dev/null
253
355
  }
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
@@ -118,11 +118,15 @@ __tt_pins_load
118
118
 
119
119
  : ${TTHEME_BG_COLORS:=tone}
120
120
 
121
+ : ${TTHEME_WARP_FAST:=on}
122
+
121
123
  typeset -g TTHEME_STATE_DIR=${XDG_STATE_HOME:-$HOME/.local/state}/ttheme
122
124
 
123
125
  () {
124
126
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
125
- 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
126
130
  typeset -g TTHEME_ADAPTER=warp
127
131
  elif [[ -n $GHOSTTY_RESOURCES_DIR || $TERM_PROGRAM == ghostty ]]; then
128
132
  typeset -g TTHEME_ADAPTER=ghostty
@@ -161,7 +165,7 @@ __tt_active() {
161
165
  }
162
166
 
163
167
  typeset -g TTHEME_HEARD=""
164
- 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
165
169
 
166
170
  __tt_put() {
167
171
  local f=${1:A}
@@ -235,6 +239,18 @@ __tt_recheck() {
235
239
  fi
236
240
  }
237
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
+
238
254
  source $TTHEME_HOME/adapters/_osc.zsh
239
255
  source $TTHEME_HOME/adapters/_wired.zsh
240
256
  [[ -r $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh ]] &&
@@ -379,8 +395,9 @@ __tt_focus() {
379
395
  fi
380
396
  }
381
397
 
382
- __tt_mux() {
398
+ __tt_ran() {
383
399
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
400
+ TTHEME_RAN=1
384
401
  [[ ${${(z)3}[1]:t} == tmux ]] && TTHEME_MUXED=1
385
402
  }
386
403
 
@@ -400,6 +417,7 @@ __tt_blur() {
400
417
  __tt_line_init() {
401
418
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
402
419
  (( TTHEME_RECHECK )) && __tt_recheck
420
+ (( TTHEME_RAN )) && __tt_mend
403
421
  __tt_typed
404
422
  (( TTHEME_FOCUS )) && __tt_focus_on
405
423
  }
@@ -2202,7 +2220,7 @@ __tt_pv_draw() {
2202
2220
  split=$(( sw > 0 )) sc=$(( pw - 1 - sw ))
2203
2221
  h=$(( ph - 5 ))
2204
2222
  [[ -n $tune ]] && (( ! split )) && h=$(( ph - 14 ))
2205
- (( conf && ! split )) && h=$(( ph - 12 ))
2223
+ (( conf && ! split )) && h=$(( ph - 6 - ${#cvars} ))
2206
2224
  reach=()
2207
2225
  if [[ -n $pick && $mode == pin ]]; then
2208
2226
  if (( split )); then
@@ -2351,8 +2369,8 @@ __tt_pv_draw() {
2351
2369
  __tt_pv_head $(( ph - 10 )) 1 $lw $tune "$REPLY" $state
2352
2370
  __tt_pv_bg_panel $tpick $(( ph - 9 )) 1 $lw
2353
2371
  elif (( conf )); then
2354
- __tt_pv_head $(( ph - 8 )) 1 $lw Config
2355
- __tt_pv_conf_panel $(( ph - 7 )) 1 $lw
2372
+ __tt_pv_head $(( ph - 2 - ${#cvars} )) 1 $lw Config
2373
+ __tt_pv_conf_panel $(( ph - 1 - ${#cvars} )) 1 $lw
2356
2374
  fi
2357
2375
  (( help )) && __tt_pv_help
2358
2376
  fi
@@ -2663,6 +2681,7 @@ __tt_preview() {
2663
2681
  TTHEME_BG_COLORS:tone "New pictures are tinted in one color of the palette"
2664
2682
  TTHEME_BG_COLORS:original "New pictures keep their own colors"
2665
2683
  )
2684
+ __tt_pv_conf_rows
2666
2685
  [[ $mode == pin ]] && __tt_pin_scopes "$pdir"
2667
2686
  [[ $mode == init ]] && pkdef=2
2668
2687
  __tt_pv_canpick
@@ -2856,7 +2875,7 @@ fi
2856
2875
  add-zsh-hook chpwd __tt_chpwd
2857
2876
  add-zsh-hook precmd __tt_prompt
2858
2877
  if (( ! TTHEME_TMUX )); then
2859
- add-zsh-hook preexec __tt_mux
2878
+ add-zsh-hook preexec __tt_ran
2860
2879
  add-zsh-hook precmd __tt_unmux
2861
2880
  fi
2862
2881
  if __tt_follows_focus || (( TTHEME_TMUX )); then