@kecan0406/ttheme 1.2.1 → 1.2.3

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,14 @@
1
1
  __tt_keepable() { (( ${TTHEME_TERMINALS[(Ie)windows-terminal]} )) }
2
2
 
3
- __tt_reloaded() { __tt_repaint }
3
+ __tt_reloaded() {
4
+ local REPLY
5
+ integer i
6
+ [[ -n $TTHEME_PAINTED ]] || return 0
7
+ for (( i = 0; i < 20; i++ )); do
8
+ __tt_query_bg && [[ ${(L)REPLY} == ${(L)${TTHEME_SPEC%% *}} ]] || break
9
+ sleep 0.05
10
+ done
11
+ __tt_repaint
12
+ }
4
13
 
5
14
  __tt_follows_focus() { return 0 }
package/shell/ttheme.zsh CHANGED
@@ -14,23 +14,29 @@ __tt_palettes_load() {
14
14
  __tt_fresh() {
15
15
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
16
16
  local -a at
17
- local was=$TTHEME_STARTUP
17
+ local was=$TTHEME_STARTUP start="$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}"
18
18
  if ! zstat -F %s.%N -A at +mtime -- $TTHEME_HOME/palettes.zsh 2>/dev/null; then
19
19
  [[ -e $TTHEME_HOME ]] || __tt_gone
20
20
  return 0
21
21
  fi
22
22
  [[ $at[1] == "$TTHEME_PALETTES_AT" ]] && return 0
23
- __tt_palettes_load && __tt_reloaded
23
+ __tt_palettes_load && { __tt_follow "$start" && __tt_sync; __tt_reloaded }
24
24
  [[ -n $was && -z $TTHEME_STARTUP && -n $TTHEME_SPEC ]] && __tt_active && __tt_off_here
25
25
  }
26
26
 
27
+ __tt_follow() {
28
+ [[ -n $TTHEME_STARTUP && "$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}" != "$1" && -z $TTHEME_PAINTED ]] || return 1
29
+ __tt_active && __tt_takes_default || return 1
30
+ TTHEME_SPEC=${TTHEME_PALETTE[$TTHEME_STARTUP]}
31
+ }
32
+
27
33
  __tt_gone() {
28
34
  local bg=${TTHEME_SPEC%% *} hook
29
35
  TTHEME_SPEC=
30
36
  __tt_reload
31
37
  __tt_reset_reloaded $bg
32
38
  print -n $'\e[?1004l'
33
- for hook in precmd:__tt_fresh precmd:__tt_precmd precmd:__tt_unmux preexec:__tt_preexec preexec:__tt_mux chpwd:__tt_chpwd; do
39
+ for hook in precmd:__tt_fresh precmd:__tt_precmd precmd:__tt_prompted precmd:__tt_unmux preexec:__tt_preexec preexec:__tt_mux chpwd:__tt_chpwd; do
34
40
  add-zsh-hook -d ${hook%%:*} ${hook#*:}
35
41
  done
36
42
  (( $+functions[add-zle-hook-widget] )) && add-zle-hook-widget -d line-init __tt_line_init
@@ -304,8 +310,7 @@ __tt_dir_sync() {
304
310
  [[ -n $spec && $spec != "$TTHEME_SPEC" ]] || return 0
305
311
  __tt_apply "$spec"
306
312
  TTHEME_SPEC=$spec
307
- __tt_name_of "$spec"
308
- __tt_shown "$REPLY" && __tt_reload
313
+ __tt_sync
309
314
  }
310
315
 
311
316
  __tt_chpwd() {
@@ -314,14 +319,16 @@ __tt_chpwd() {
314
319
  __tt_dir_sync
315
320
  }
316
321
 
317
- __tt_sync() {
322
+ __tt_worn_shown() {
318
323
  local REPLY
319
- [[ -n $TTHEME_SPEC ]] || return 0
324
+ [[ -n $TTHEME_SPEC ]] || return 1
320
325
  __tt_name_of "$TTHEME_SPEC"
321
- [[ -n ${TTHEME_PALETTE[$REPLY]} ]] || return 0
322
- __tt_shown "$REPLY" && __tt_reload
326
+ [[ -n ${TTHEME_PALETTE[$REPLY]} ]] || return 1
327
+ __tt_shown "$REPLY" $1
323
328
  }
324
329
 
330
+ __tt_sync() { ! __tt_worn_shown || __tt_reload }
331
+
325
332
  __tt_precmd() {
326
333
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
327
334
  __tt_sync
@@ -335,12 +342,13 @@ __tt_preexec() {
335
342
  }
336
343
 
337
344
  __tt_rewear() {
338
- local REPLY
339
345
  __tt_repaint
340
- [[ -n $TTHEME_SPEC ]] || { __tt_unshown $1; return 0 }
341
- __tt_name_of "$TTHEME_SPEC"
342
- [[ -n ${TTHEME_PALETTE[$REPLY]} ]] || return 0
343
- __tt_shown "$REPLY" $1 && __tt_reload
346
+ if [[ -n $TTHEME_SPEC ]]; then
347
+ __tt_worn_shown $1 && __tt_reload
348
+ else
349
+ __tt_unshown $1
350
+ fi
351
+ return 0
344
352
  }
345
353
 
346
354
  __tt_focus() {
@@ -1074,10 +1082,11 @@ __tt_pins_map() {
1074
1082
  }
1075
1083
 
1076
1084
  __tt_keep() {
1077
- local note
1085
+ local note was="$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}"
1078
1086
  note=$(__tt_cli default "$1") || return 1
1079
- TTHEME_STARTUP=$1
1080
- __tt_shown "$1" force
1087
+ [[ -r $TTHEME_HOME/palettes.zsh ]] && __tt_palettes_load && __tt_reloaded
1088
+ __tt_follow "$was"
1089
+ __tt_worn_shown $2
1081
1090
  __tt_reload
1082
1091
  if __tt_color; then
1083
1092
  printf '\033[2m%s\033[0m\n' "${(@f)note}"
@@ -1189,7 +1198,10 @@ __tt_catalog() {
1189
1198
  [[ -r $TTHEME_HOME/palettes.zsh ]] || return 0
1190
1199
  was="$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}"
1191
1200
  __tt_palettes_load && __tt_reloaded
1192
- [[ "$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}" == "$was" ]] || __tt_reload
1201
+ [[ "$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}" == "$was" ]] && return 0
1202
+ __tt_follow "$was"
1203
+ __tt_worn_shown
1204
+ __tt_reload
1193
1205
  }
1194
1206
 
1195
1207
  __tt_switch() {
@@ -1307,13 +1319,11 @@ __tt_next() {
1307
1319
  }
1308
1320
 
1309
1321
  __tt_rotate() {
1310
- local REPLY spec
1322
+ local REPLY
1311
1323
  __tt_next
1312
- spec=$REPLY
1313
- __tt_apply "$spec"
1314
- TTHEME_SPEC=$spec
1315
- __tt_name_of "$spec"
1316
- __tt_shown "$REPLY" force && __tt_reload
1324
+ __tt_apply "$REPLY"
1325
+ TTHEME_SPEC=$REPLY
1326
+ __tt_worn_shown force && __tt_reload
1317
1327
  __tt_announce
1318
1328
  }
1319
1329
 
@@ -2653,7 +2663,7 @@ __tt_preview() {
2653
2663
  local tty=""
2654
2664
  local -i TTHEME_RAW=0
2655
2665
  {
2656
- tty=$(stty -g 2>/dev/null && stty -echo -icanon min 1 time 0 2>/dev/null)
2666
+ tty=$(stty -g 2>/dev/null) && stty -echo -icanon min 1 time 0 2>/dev/null || tty=""
2657
2667
  TTHEME_RAW=$(( ${#tty} > 0 ))
2658
2668
  __tt_pv_bg_open
2659
2669
  printf '\e[?2026h\e[?1049h\e[?7l\e[?25l'
@@ -2705,7 +2715,7 @@ __tt_preview() {
2705
2715
  __tt_sync
2706
2716
  elif (( picked == 2 )); then
2707
2717
  __tt_announce
2708
- __tt_keep "$sel"
2718
+ __tt_keep "$sel" force
2709
2719
  else
2710
2720
  __tt_announce
2711
2721
  __tt_shown "$sel" force && __tt_reload
@@ -2733,6 +2743,8 @@ ttheme() {
2733
2743
  print -u2 "ttheme: unknown command '$1' — see \`ttheme help\`"
2734
2744
  return 1
2735
2745
  fi
2746
+ __tt_fresh
2747
+ (( $+functions[ttheme] )) || { print -u2 "ttheme: uninstalled — \`npx @kecan0406/ttheme@latest init\` sets it up again"; return 1 }
2736
2748
  if ! __tt_paints && (( ! $# || ${TTHEME_TAB_VERBS[(Ie)$1]} )); then
2737
2749
  __tt_unpainted
2738
2750
  return 1
@@ -2841,6 +2853,7 @@ fi
2841
2853
  else
2842
2854
  __tt_sync
2843
2855
  fi
2856
+ __tt_follows_prompt && add-zsh-hook precmd __tt_prompted
2844
2857
  __tt_announce
2845
2858
  }
2846
2859