@kecan0406/ttheme 1.0.0 → 1.0.2

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/shell/ttheme.zsh CHANGED
@@ -1,7 +1,23 @@
1
- typeset -g TTHEME_HOME=${${(%):-%x}:A:h}
1
+ typeset -g TTHEME_HOME=${${(%):-%x}:A:h} TTHEME_PALETTES_AT=""
2
+
3
+ zmodload -F zsh/stat b:zstat 2>/dev/null
4
+
5
+ __tt_palettes_load() {
6
+ local -a at
7
+ unset TTHEME_PALETTE TTHEME_GROUP TTHEME_NATIVE TTHEME_SRC
8
+ source $TTHEME_HOME/palettes.zsh || return 1
9
+ zstat -F %s.%N -A at +mtime -- $TTHEME_HOME/palettes.zsh 2>/dev/null
10
+ TTHEME_PALETTES_AT=$at[1]
11
+ }
12
+
13
+ __tt_fresh() {
14
+ local -a at
15
+ zstat -F %s.%N -A at +mtime -- $TTHEME_HOME/palettes.zsh 2>/dev/null || return 0
16
+ [[ $at[1] == "$TTHEME_PALETTES_AT" ]] || __tt_palettes_load
17
+ }
2
18
 
3
19
  if [[ -r $TTHEME_HOME/palettes.zsh ]]; then
4
- source $TTHEME_HOME/palettes.zsh
20
+ __tt_palettes_load
5
21
  else
6
22
  print -u2 "ttheme: palettes.zsh not found — run \`npx @kecan0406/ttheme@latest init\`"
7
23
  return 1
@@ -62,6 +78,26 @@ else
62
78
  typeset -g TTHEME_ADAPTER=unknown
63
79
  fi
64
80
 
81
+ typeset -g TTHEME_GHOSTTY_PID=""
82
+
83
+ __tt_reload() {
84
+ (( ${TTHEME_TERMINALS[(Ie)ghostty]} )) || return 0
85
+ local pid=$PPID ppid comm
86
+ if [[ -z $TTHEME_GHOSTTY_PID ]]; then
87
+ TTHEME_GHOSTTY_PID=0
88
+ while (( pid > 1 )); do
89
+ read -r ppid comm <<< "$(ps -o ppid=,comm= -p $pid)"
90
+ if [[ ${comm:t} == ghostty ]]; then
91
+ TTHEME_GHOSTTY_PID=$pid
92
+ break
93
+ fi
94
+ pid=$ppid
95
+ done
96
+ fi
97
+ (( TTHEME_GHOSTTY_PID )) && kill -USR2 $TTHEME_GHOSTTY_PID 2>/dev/null && return
98
+ pkill -USR2 -x ghostty 2>/dev/null
99
+ }
100
+
65
101
  source $TTHEME_HOME/adapters/_osc.zsh
66
102
  [[ -r $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh ]] &&
67
103
  source $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh
@@ -173,7 +209,10 @@ __tt_precmd() {
173
209
 
174
210
  __tt_preexec() { printf '\e[?1004l' }
175
211
 
176
- __tt_focus() { __tt_sync }
212
+ __tt_focus() {
213
+ __tt_fresh
214
+ __tt_sync
215
+ }
177
216
 
178
217
  __tt_blur() { : }
179
218
 
@@ -258,8 +297,9 @@ __tt_unpin() {
258
297
  __tt_keep() {
259
298
  local note
260
299
  note=$(__tt_cli default "$1") || return 1
261
- __tt_shown "$1"
262
- (( $+functions[__tt_reload] )) && __tt_reload
300
+ TTHEME_STARTUP=$1
301
+ __tt_shown "$1" force
302
+ __tt_reload
263
303
  if __tt_color; then
264
304
  printf '\033[2m%s\033[0m\n' "${(@f)note}"
265
305
  else
@@ -335,11 +375,13 @@ __tt_cli() {
335
375
  }
336
376
 
337
377
  __tt_catalog() {
378
+ local was
338
379
  __tt_cli "$@" || return
339
380
  [[ $1 == list ]] && return 0
340
381
  [[ -r $TTHEME_HOME/palettes.zsh ]] || return 0
341
- unset TTHEME_PALETTE TTHEME_GROUP TTHEME_NATIVE TTHEME_SRC
342
- source $TTHEME_HOME/palettes.zsh
382
+ was="$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}"
383
+ __tt_palettes_load
384
+ [[ "$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}" == "$was" ]] || __tt_reload
343
385
  }
344
386
 
345
387
  __tt_config() {
@@ -424,7 +466,7 @@ __tt_rotate() {
424
466
  __tt_apply "$spec"
425
467
  TTHEME_SPEC=$spec
426
468
  __tt_name_of "$spec"
427
- __tt_shown "$REPLY" && __tt_reload
469
+ __tt_shown "$REPLY" force && __tt_reload
428
470
  __tt_announce
429
471
  }
430
472
 
@@ -638,7 +680,7 @@ __tt_pv_foot() {
638
680
  elif (( pk == 1 )); then
639
681
  note="until this tab closes"
640
682
  else
641
- note="new tabs · ghostty config"
683
+ note="new tabs · the default palette"
642
684
  fi
643
685
  kk=(enter) kl=(confirm)
644
686
  right=$b"esc"$z$d" back"$z
@@ -1019,7 +1061,8 @@ __tt_pv_draw() {
1019
1061
  cnt="$mt/${#TTHEME_ORDER}"
1020
1062
  out=$'\e[H'
1021
1063
  if (( resized )); then
1022
- out+=$'\e[2J'
1064
+ out+=$'\e[K\e[2H\e[J\e[H'
1065
+ (( bgcw )) && out+=$'\e_Ga=d,d=A,q=2\e\\'
1023
1066
  resized=0 wiped=1
1024
1067
  fi
1025
1068
  if (( pw < 40 || ph < 12 )); then
@@ -1147,7 +1190,7 @@ __tt_pv_canpick() {
1147
1190
  canpick=0
1148
1191
  if [[ $mode == pin ]]; then
1149
1192
  canpick=1
1150
- elif (( $+functions[__tt_reload] )) && [[ $TTHEME_TAB_PALETTE == off ]]; then
1193
+ elif __tt_keepable && [[ $TTHEME_TAB_PALETTE == off ]]; then
1151
1194
  canpick=1
1152
1195
  fi
1153
1196
  }
@@ -1384,7 +1427,7 @@ __tt_preview() {
1384
1427
  fi
1385
1428
  local orig=$TTHEME_SPEC applied=$TTHEME_SPEC flt="" sel="" cn="" cdot="" key="" REPLY="" cur=1 top=1 color=0 pw=80 ph=24 resized=1 expal="" exgrp="" exnext=0 gstep=0 gseed=0
1386
1429
  local pick="" pk=1 pkdef=1 picked=0 canpick=0 bgcw=0 bgch=0 bgname="" bgshown="" bginc="" osd="" osdt=0
1387
- local tune="" tsnap="" tf=1 help=0 msg="" msgt=0 an="" bgrel=0 bgmx=0 bgmy=0 bganchor=0
1430
+ local tune="" tsnap="" tf=1 help=0 msg="" msgt=0 an="" bgrel=0 bgmx=0 bgmy=0 bganchor=0 bgcut=""
1388
1431
  local -A bgfrom=() bgsent=() bgdim=() bgsrc=() bgfill=() bgfocus=() bgsize=() bgpos=() bgop=() bgdef=() bgoff=() bgbase=() bgload=() bgshot=() bgshotkey=() bgedit=()
1389
1432
  local conf=0 cf=1
1390
1433
  local -a plabel=(" this tab " " default ") csnap=()
@@ -1441,7 +1484,7 @@ __tt_preview() {
1441
1484
  elif (( picked == 2 )); then
1442
1485
  __tt_keep "$sel"
1443
1486
  else
1444
- __tt_shown "$sel" && __tt_reload
1487
+ __tt_shown "$sel" force && __tt_reload
1445
1488
  fi
1446
1489
  else
1447
1490
  if [[ -z $orig && -n $applied ]]; then
@@ -1489,7 +1532,7 @@ ttheme() {
1489
1532
  local spec=${TTHEME_PALETTE[$REPLY]}
1490
1533
  __tt_apply "$spec"
1491
1534
  TTHEME_SPEC=$spec
1492
- __tt_shown "$REPLY" && __tt_reload
1535
+ __tt_shown "$REPLY" force && __tt_reload
1493
1536
  __tt_announce
1494
1537
  }
1495
1538
 
@@ -1521,17 +1564,20 @@ if __tt_active; then
1521
1564
  }
1522
1565
  autoload -Uz add-zsh-hook
1523
1566
  add-zsh-hook chpwd __tt_chpwd
1524
- if (( $+functions[__tt_reload] )); then
1567
+ add-zsh-hook precmd __tt_fresh
1568
+ if [[ $TTHEME_ADAPTER == ghostty ]]; then
1525
1569
  add-zsh-hook precmd __tt_precmd
1526
1570
  add-zsh-hook preexec __tt_preexec
1527
1571
  __tt_bind_focus
1572
+ else
1573
+ __tt_sync
1528
1574
  fi
1529
1575
  __tt_announce
1530
1576
  fi
1531
1577
 
1532
1578
  () {
1533
1579
  local f
1534
- for f in $TTHEME_HOME/ttheme.zsh $TTHEME_HOME/palettes.zsh $TTHEME_HOME/adapters/_osc.zsh $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh; do
1580
+ for f in $TTHEME_HOME/ttheme.zsh $TTHEME_HOME/palettes.zsh $TTHEME_HOME/adapters/_osc.zsh $TTHEME_HOME/adapters/_bg.zsh $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh; do
1535
1581
  [[ -r $f && ! $f.zwc -nt $f ]] || continue
1536
1582
  zcompile -UR -- $f.$$.zwc $f 2>/dev/null && command mv -f -- $f.$$.zwc $f.zwc 2>/dev/null
1537
1583
  [[ ! -e $f.$$.zwc ]] || command rm -f -- $f.$$.zwc