@kecan0406/ttheme 1.0.45 → 1.0.47

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
@@ -31,10 +31,7 @@ __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
- 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
34
+ (( $+functions[add-zle-hook-widget] )) && add-zle-hook-widget -d line-init __tt_line_init
38
35
  unfunction ttheme
39
36
  }
40
37
 
@@ -143,16 +140,79 @@ __tt_tmux() {
143
140
  TTHEME_TMUX=1 TTHEME_SPEC=
144
141
  }
145
142
 
146
- source $TTHEME_HOME/adapters/_osc.zsh
147
- [[ -r $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh ]] &&
148
- source $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh
149
-
150
143
  __tt_active() {
151
144
  [[ -o interactive ]] || return 1
152
145
  (( ${#TTHEME_PALETTE} )) || return 1
153
146
  [[ $TTHEME_ADAPTER != (unknown|warp) || -n $TTHEME_FORCE ]]
154
147
  }
155
148
 
149
+ typeset -g TTHEME_HEARD=""
150
+ typeset -gi TTHEME_RECHECK=0 TTHEME_FOCUS=0
151
+
152
+ __tt_recall() {
153
+ local f=$TTHEME_STATE_DIR/colors.$TTHEME_ADAPTER line
154
+ REPLY=""
155
+ [[ -o zle && -r $f && -z $TTHEME_PAINTED && $TTHEME_TAB_PALETTE == off ]] && (( ! TTHEME_TMUX )) && __tt_active || return 1
156
+ line=$(<$f)
157
+ [[ $line == "${TTHEME_STARTUP:--} "?* ]] || return 1
158
+ REPLY=${line#* }
159
+ }
160
+
161
+ __tt_remember() {
162
+ local f=$TTHEME_STATE_DIR/colors.$TTHEME_ADAPTER line="${TTHEME_STARTUP:--} $1"
163
+ [[ -n $1 && -z $TTHEME_PAINTED ]] && (( ! TTHEME_TMUX )) || return 0
164
+ [[ -r $f && "$(<$f)" == "$line" ]] && return 0
165
+ [[ -d $TTHEME_STATE_DIR ]] || mkdir -p $TTHEME_STATE_DIR 2>/dev/null
166
+ print -r -- "$line" 2>/dev/null > $f
167
+ }
168
+
169
+ __tt_listen() {
170
+ local REPLY
171
+ if __tt_recall; then
172
+ TTHEME_RECHECK=1
173
+ else
174
+ __tt_hear || return 1
175
+ __tt_remember "$REPLY"
176
+ fi
177
+ TTHEME_HEARD=$REPLY
178
+ __tt_heard "$REPLY"
179
+ }
180
+
181
+ __tt_wearing() {
182
+ local k
183
+ [[ -n $1 ]] || return 1
184
+ [[ -n $TTHEME_STARTUP && ${TTHEME_PALETTE[$TTHEME_STARTUP]%% *} == "$1" ]] && { REPLY=$TTHEME_PALETTE[$TTHEME_STARTUP]; return 0 }
185
+ for k in ${(k)TTHEME_PALETTE}; do
186
+ [[ ${TTHEME_PALETTE[$k]%% *} == "$1" ]] && { REPLY=$TTHEME_PALETTE[$k]; return 0 }
187
+ done
188
+ return 1
189
+ }
190
+
191
+ __tt_recheck() {
192
+ local REPLY heard=$TTHEME_HEARD was="" now
193
+ TTHEME_RECHECK=0
194
+ [[ -z $TTHEME_PAINTED ]] && __tt_hear || return 0
195
+ [[ $REPLY == "$heard" ]] && return 0
196
+ now=$REPLY
197
+ __tt_remember "$now"
198
+ TTHEME_HEARD=$now
199
+ __tt_heard "$now"
200
+ [[ $TTHEME_TAB_PALETTE == off ]] || return 0
201
+ __tt_wearing "${heard%% *}" && was=$REPLY
202
+ REPLY=""
203
+ __tt_wearing "${now%% *}"
204
+ if [[ -n $TTHEME_PIN ]]; then
205
+ [[ $TTHEME_BASE_SPEC == "$was" ]] && TTHEME_BASE_SPEC=$REPLY
206
+ elif [[ $TTHEME_SPEC == "$was" ]]; then
207
+ TTHEME_SPEC=$REPLY
208
+ __tt_sync
209
+ fi
210
+ }
211
+
212
+ source $TTHEME_HOME/adapters/_osc.zsh
213
+ [[ -r $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh ]] &&
214
+ source $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh
215
+
156
216
  __tt_empty() {
157
217
  print -u2 'ttheme: no palettes installed yet — run `ttheme browse` to pick some'
158
218
  return 1
@@ -169,15 +229,22 @@ __tt_name_of() { REPLY=${${(k)TTHEME_PALETTE[(re)$1]}:-custom} }
169
229
  __tt_color() { [[ -t 1 && -z $NO_COLOR && $TERM != dumb ]] }
170
230
 
171
231
  __tt_palette_line() {
172
- local name=$1 marker=$2
173
- local -a p=(${=TTHEME_PALETTE[$name]})
232
+ local name=$1 width=$2 on=$3 hex cell="" bar=""
233
+ local -a p=(${=TTHEME_PALETTE[$name]}) sw=(${=TTHEME_SWATCH[$name]})
174
234
  (( ${#p} >= 20 )) || return 1
175
- local bg=${p[1]#\#} cur=${p[3]#\#}
176
- printf '%s\033[48;2;%d;%d;%d;38;2;%d;%d;%dm ● \033[0m %-8s \033[2m· ANSI %s\033[0m\n' \
177
- "$marker" \
178
- $((16#${bg:0:2})) $((16#${bg:2:2})) $((16#${bg:4:2})) \
179
- $((16#${cur:0:2})) $((16#${cur:2:2})) $((16#${cur:4:2})) \
180
- "$name" "${TTHEME_SRC[$name]:-unknown}"
235
+ for hex in $sw; do
236
+ hex=${hex#\#}
237
+ cell+=$'\e[38;2;'$((16#${hex:0:2}))';'$((16#${hex:2:2}))';'$((16#${hex:4:2}))'m■ '
238
+ done
239
+ if [[ -n $on ]]; then
240
+ local cur=${p[3]#\#} sel=${p[4]#\#} fg=${p[2]#\#} ac
241
+ printf -v ac '\e[38;2;%d;%d;%dm' $((16#${cur:0:2})) $((16#${cur:2:2})) $((16#${cur:4:2}))
242
+ printf -v bar '\e[48;2;%d;%d;%d;38;2;%d;%d;%dm' \
243
+ $((16#${sel:0:2})) $((16#${sel:2:2})) $((16#${sel:4:2})) $((16#${fg:0:2})) $((16#${fg:2:2})) $((16#${fg:4:2}))
244
+ printf '%s▌\e[39m %s %s■\e[39m \e[1m%-*s\e[22m %s\e[0m\n' "$ac" "$bar" "$ac" "$width" "$name" "$cell"
245
+ else
246
+ printf ' %-*s %s\e[0m\n' "$width" "$name" "$cell"
247
+ fi
181
248
  }
182
249
 
183
250
  __tt_announce() {
@@ -281,13 +348,17 @@ __tt_unmux() {
281
348
 
282
349
  __tt_blur() { : }
283
350
 
351
+ __tt_line_init() {
352
+ (( TTHEME_RECHECK )) && __tt_recheck
353
+ __tt_typed
354
+ (( TTHEME_FOCUS )) && __tt_focus_on
355
+ }
356
+
284
357
  __tt_bind_focus() {
285
358
  local k
286
359
  zle -N __tt_focus
287
360
  zle -N __tt_blur
288
- zle -N __tt_focus_on
289
- autoload -Uz add-zle-hook-widget
290
- add-zle-hook-widget line-init __tt_focus_on
361
+ TTHEME_FOCUS=1
291
362
  for k in emacs viins vicmd; do
292
363
  bindkey -M $k '^[[I' __tt_focus
293
364
  bindkey -M $k '^[[O' __tt_blur
@@ -384,8 +455,9 @@ __tt_order() {
384
455
  }
385
456
 
386
457
  __tt_menu() {
387
- local k cur="" mark grp last_grp="" REPLY
458
+ local k cur="" grp last_grp="" REPLY
388
459
  local -a reply
460
+ local -i width=0
389
461
  __tt_order
390
462
  if ! __tt_color; then
391
463
  for k in $reply; do
@@ -394,27 +466,21 @@ __tt_menu() {
394
466
  return 0
395
467
  fi
396
468
  [[ -n $TTHEME_SPEC ]] && __tt_name_of "$TTHEME_SPEC" && cur=$REPLY
397
- local gutter=""
398
- if [[ -n ${TTHEME_PALETTE[$cur]} ]]; then
399
- local -a cp=(${=TTHEME_PALETTE[$cur]})
400
- local ch=${cp[3]#\#}
401
- printf -v gutter '\033[38;2;%d;%d;%dm◆\033[0m ' \
402
- $((16#${ch:0:2})) $((16#${ch:2:2})) $((16#${ch:4:2}))
403
- fi
469
+ for k in $reply; do
470
+ (( ${#k} > width )) && width=${#k}
471
+ done
404
472
  for k in $reply; do
405
473
  grp=${TTHEME_GROUP[$k]:-Other}
406
474
  if [[ $grp != $last_grp ]]; then
407
- [[ $grp == *@* && $last_grp != *@* && -n $last_grp ]] && printf '\033[2m── markets ──────────\033[0m\n'
408
- printf '\033[1m%s\033[0m' "$grp"
475
+ [[ $grp == *@* && $last_grp != *@* && -n $last_grp ]] && printf ' \033[2m── markets ──────────\033[0m\n'
476
+ printf ' \033[1m%s\033[0m' "$grp"
409
477
  [[ -n ${TTHEME_NATIVE[$k]} ]] && printf ' \033[2m%s\033[0m' "${TTHEME_NATIVE[$k]}"
410
478
  printf '\n'
411
479
  last_grp=$grp
412
480
  fi
413
- mark=" "
414
- [[ $k == $cur ]] && mark=$gutter
415
- __tt_palette_line "$k" "$mark"
481
+ __tt_palette_line "$k" $width ${${(M)k:#$cur}:+1}
416
482
  done
417
- printf '\n\033[2mttheme use <palette> paints this tab · ttheme preview · ttheme help\033[0m\n'
483
+ printf '\n \033[2mttheme use <palette> paints this tab · ttheme preview · ttheme help\033[0m\n'
418
484
  }
419
485
 
420
486
  __tt_help() {
@@ -459,7 +525,7 @@ __tt_arity() {
459
525
 
460
526
  __tt_cli() {
461
527
  local k
462
- local -a pass=()
528
+ local -a pass=(NODE_COMPILE_CACHE=${XDG_CACHE_HOME:-$HOME/.cache}/ttheme/node)
463
529
  for k in $TTHEME_SETTINGS; do
464
530
  (( $+parameters[$k] )) && pass+=("$k=${(P)k}")
465
531
  done
@@ -640,7 +706,7 @@ __tt_pv_focus() {
640
706
  (( resized )) || [[ ${rval[cur]} == "$bgname" ]] || __tt_pv_bg_show "${rval[cur]}"
641
707
  local spec=${TTHEME_PALETTE[${rval[cur]}]}
642
708
  [[ $spec == "$applied" ]] && return 0
643
- __tt_apply "$spec"
709
+ __tt_pv_paint "$spec"
644
710
  applied=$spec
645
711
  }
646
712
 
@@ -734,19 +800,22 @@ __tt_pv_hl() {
734
800
  }
735
801
 
736
802
  __tt_pv_row() {
737
- local t=${rval[$1]} b=$'\e[1m' d=$'\e[2m' r=$'\e[22;24;39m' z=$'\e[0m' on="" base="" lead=$'\e[2m' mark=" " name arrow=▸
803
+ local t=${rval[$1]} b=$'\e[1m' d=$'\e[2m' r=$'\e[22;24;39m' z=$'\e[0m' on="" gut=" " base="" lead=$'\e[2m' mark=" " name arrow=▸
738
804
  local -i w
739
805
  (( color )) || b= d= r= z= lead=
740
- (( $1 == cur && color )) && on=$sb
806
+ if (( $1 == cur )); then
807
+ gut=$ac"▌"$r" "
808
+ (( color )) && on=$sb
809
+ fi
741
810
  if [[ ${rtype[$1]} == rule ]]; then
742
811
  name='── markets '
743
- REPLY=$d$name${(l:lw - 2 - ${#name}::─:)}$z
812
+ REPLY=" "$d$name${(l:lw - 4 - ${#name}::─:)}$z
744
813
  return 0
745
814
  fi
746
815
  if [[ ${rtype[$1]} == hdr ]]; then
747
816
  [[ -n $flt || -n ${exp[$t]} ]] && arrow=▾
748
817
  name=$t
749
- (( ${(m)#name} > lw - 8 )) && name="${name[1,lw-9]}…"
818
+ (( ${(m)#name} > lw - 10 )) && name="${name[1,lw-11]}…"
750
819
  base=$b
751
820
  if (( color )) && [[ $t == "$ag" ]]; then
752
821
  base+=$ac lead=$ac
@@ -754,24 +823,24 @@ __tt_pv_row() {
754
823
  lead=""
755
824
  fi
756
825
  __tt_pv_hl "$name" "$base"
757
- w=$(( lw - 2 - ${(m)#name} - ${#rcnt[$1]} ))
826
+ w=$(( lw - 6 - ${(m)#name} - ${#rcnt[$1]} ))
758
827
  (( w < 1 )) && w=1
759
- REPLY=$on$lead$arrow$r" "$base$REPLY$r${(l:w:: :)}$d${rcnt[$1]}$z
828
+ REPLY=$gut$on" "$lead$arrow$r" "$base$REPLY$r${(l:w:: :)}$d${rcnt[$1]}$r" "$z
760
829
  return 0
761
830
  fi
762
831
  if (( $1 == cur )); then
763
- mark=$cmark base=$b
832
+ mark=$ac"■"$r base=$b
764
833
  elif [[ -n $cdot && $t == "$cn" ]]; then
765
834
  mark=$cdot
766
835
  fi
767
836
  __tt_pv_hl "$t" "$base"
768
837
  if (( color )); then
769
838
  [[ -n ${tstrip[$t]} ]] || __tt_pv_strip $t
770
- w=$(( lw - 20 - ${#t} ))
839
+ w=$(( lw - 19 - ${#t} ))
771
840
  (( w < 1 )) && w=1
772
- REPLY="$on $mark $base$REPLY$r${(l:w:: :)}${tstrip[$t]}"
841
+ REPLY=$gut$on" $mark $base$REPLY$r${(l:w:: :)}${tstrip[$t]} "$z
773
842
  else
774
- REPLY=" $mark $REPLY"
843
+ REPLY="$gut $mark $REPLY"
775
844
  fi
776
845
  }
777
846
 
@@ -786,10 +855,14 @@ __tt_pv_head() {
786
855
 
787
856
  __tt_pv_foot() {
788
857
  setopt localoptions extendedglob
789
- local b=$'\e[1m' d=$'\e[2m' z=$'\e[0m' y=$'\e[33m' on=$'\e[7;1m'$ac badge="" lead="" note="" right="" text line plain
858
+ local b=$'\e[1m' d=$'\e[2m' z=$'\e[0m' y=$'\e[33m' on=$'\e[7;1m'$ac badge="" lead="" note="" right="" text line plain hex
790
859
  local -a kk=() kl=() seg=()
791
860
  local -i end=$1 i lwid rwid room
792
861
  (( color )) || b= d= z= y= on=
862
+ if (( color )) && [[ -n $applied && $applied != "$painted" ]]; then
863
+ hex=${${=applied}[8]#\#}
864
+ printf -v y '\e[38;2;%d;%d;%dm' $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2}))
865
+ fi
793
866
  if (( help )); then
794
867
  badge=KEYS right=$b"? esc"$z$d" close"$z
795
868
  elif [[ -n $pick ]]; then
@@ -944,10 +1017,21 @@ __tt_pv_help() {
944
1017
  }
945
1018
 
946
1019
  __tt_pv_specimen() {
947
- local -a sp=(${=applied}) ln=()
1020
+ local -a sp=(${=applied}) ln=() fg=()
948
1021
  (( ${#sp} >= 20 )) || return 0
949
- local z=$'\e[0m' d=$'\e[2m' pr=$'\e[32m❯\e[0m ' sel cu cell line="" lo hi
1022
+ local z=$'\e[0m' d=$'\e[2m' sel cu cell line="" lo hi pr bd
950
1023
  local -i i r cw=4
1024
+ if [[ $applied == "$painted" ]]; then
1025
+ fg=($'\e[31m' $'\e[32m' $'\e[33m' $'\e[34m' $'\e[35m') bd=$'\e[1;34m'
1026
+ else
1027
+ for i in 6 7 8 9 10 17; do
1028
+ lo=${sp[i]#\#}
1029
+ printf -v cell '\e[38;2;%d;%d;%dm' $((16#${lo:0:2})) $((16#${lo:2:2})) $((16#${lo:4:2}))
1030
+ fg+=($cell)
1031
+ done
1032
+ bd=$'\e[1m'$fg[6]
1033
+ fi
1034
+ pr=$fg[2]'❯'$z' '
951
1035
  (( sw < 44 )) && cw=3
952
1036
  (( sw >= 56 )) && cw=$(( (sw + 1) / 8 - 1 ))
953
1037
  (( cw > 7 )) && cw=7
@@ -961,12 +1045,12 @@ __tt_pv_specimen() {
961
1045
  line+=$cell
962
1046
  done
963
1047
  out+=$'\e[4;'$sc'H'$line
964
- ln=($'\e[1;34m~/code/demo\e[0m'$d' on '$z$'\e[35mmain\e[32m +2\e[33m ~1\e[0m' "${pr}git status -sb")
965
- (( sw >= 44 )) && ln+=($'## \e[32mmain\e[0m...\e[31morigin/main\e[33m [ahead 1]\e[0m')
966
- ln+=($'\e[31m M\e[0m src/main.rs' $'\e[31m??\e[0m notes.md' "")
967
- (( sw >= 44 )) && ln+=("${pr}ls" $'\e[1;34mdocs\e[0m \e[1;34msrc\e[0m \e[1;34mtests\e[0m Cargo.toml README.md' "")
968
- ln+=("${pr}cargo test" $'\e[32m ✓\e[0m parses config' $'\e[31m ✗\e[0m renders frame')
969
- (( sw >= 44 )) && ln[-1]+=$d' expected '$z$'\e[32m3\e[0m'$d', received '$z$'\e[31m2\e[0m'
1048
+ ln=($bd'~/code/demo'$z$d' on '$z$fg[5]'main'$fg[2]' +2'$fg[3]' ~1'$z "${pr}git status -sb")
1049
+ (( sw >= 44 )) && ln+=('## '$fg[2]'main'$z'...'$fg[1]'origin/main'$fg[3]' [ahead 1]'$z)
1050
+ ln+=($fg[1]' M'$z' src/main.rs' $fg[1]'??'$z' notes.md' "")
1051
+ (( sw >= 44 )) && ln+=("${pr}ls" $bd'docs'$z' '$bd'src'$z' '$bd'tests'$z' Cargo.toml README.md' "")
1052
+ ln+=("${pr}cargo test" $fg[2]' ✓'$z' parses config' $fg[1]' ✗'$z' renders frame')
1053
+ (( sw >= 44 )) && ln[-1]+=$d' expected '$z$fg[2]'3'$z$d', received '$z$fg[1]'2'$z
970
1054
  ln+=("" "${pr}echo ${sel}selected text${z} ${cu} ${z}")
971
1055
  for (( r = 1; r <= ${#ln}; r++ )); do
972
1056
  (( r + 5 < ph )) || break
@@ -1151,8 +1235,8 @@ __tt_pv_flush() {
1151
1235
  }
1152
1236
 
1153
1237
  __tt_pv_draw() {
1154
- local out line cnt ex ag="" ac="" sb="" cmark="▶" rthumb="#" rtrack="." dd="" zz="" state=on src="" REPLY
1155
- local -i lw sw split sc se=$(( pw - 2 )) h k i N=${#rval} rail=0 rl=0 rs=0 mt=${#TTHEME_ORDER} wiped=0
1238
+ local out line cnt ex ag="" ac="" sb="" dd="" zz="" state=on src="" REPLY
1239
+ local -i lw sw split sc se=$(( pw - 2 )) h k i N=${#rval} mt=${#TTHEME_ORDER} wiped=0
1156
1240
  __tt_pv_lw
1157
1241
  lw=$reply[1] sw=$reply[2]
1158
1242
  split=$(( sw > 0 )) sc=$(( pw - 1 - sw ))
@@ -1164,21 +1248,14 @@ __tt_pv_draw() {
1164
1248
  (( cur >= top + h )) && top=$(( cur - h + 1 ))
1165
1249
  (( top < 1 )) && top=1
1166
1250
  (( N > h && top > N - h + 1 )) && top=$(( N - h + 1 ))
1167
- if (( N > h )); then
1168
- rail=1
1169
- rl=$(( h * h / N ))
1170
- (( rl < 1 )) && rl=1
1171
- rs=$(( 1 + (top - 1) * (h - rl) / (N - h) ))
1172
- fi
1173
1251
  if (( color )); then
1174
- dd=$'\e[2m' zz=$'\e[0m' rtrack=$'\e[2m░\e[0m'
1252
+ dd=$'\e[2m' zz=$'\e[0m'
1175
1253
  if [[ -n $applied ]]; then
1176
1254
  local -a ap=(${=applied})
1177
1255
  local acx=${ap[3]#\#} sbx=${ap[4]#\#}
1178
1256
  printf -v ac '\e[38;2;%d;%d;%dm' $((16#${acx:0:2})) $((16#${acx:2:2})) $((16#${acx:4:2}))
1179
1257
  printf -v sb '\e[48;2;%d;%d;%dm' $((16#${sbx:0:2})) $((16#${sbx:2:2})) $((16#${sbx:4:2}))
1180
1258
  fi
1181
- rthumb=$ac"█"$zz cmark=$ac"▶"$'\e[39m'
1182
1259
  [[ ${rtype[cur]} == thm ]] && ag=${TTHEME_GROUP[${rval[cur]}]:-Other}
1183
1260
  fi
1184
1261
  if [[ -n $flt ]]; then
@@ -1204,13 +1281,13 @@ __tt_pv_draw() {
1204
1281
  fi
1205
1282
  if [[ -n $flt ]]; then
1206
1283
  if (( color )); then
1207
- line="⌕ "$'\e[1m'$flt$zz$ac$'\e[7m \e[0m'
1284
+ line=" "$'\e[1m'$flt$zz$ac$'\e[7m \e[0m'
1208
1285
  else
1209
- line="⌕ ${flt}_"
1286
+ line=" ${flt}_"
1210
1287
  fi
1211
1288
  else
1212
1289
  ex="$expal | $exgrp"
1213
- (( ${#ex} > lw - 17 - ${#cnt} )) && ex="${ex[1,lw-18-${#cnt}]}…"
1290
+ (( ${#ex} > lw - 19 - ${#cnt} )) && ex="${ex[1,lw-20-${#cnt}]}…"
1214
1291
  if (( gstep > 0 )); then
1215
1292
  local gkeep=$(( ${#ex} * (8 - gstep) / 8 ))
1216
1293
  if [[ $TTHEME_FX == (decode|glitch) ]]; then
@@ -1228,39 +1305,35 @@ __tt_pv_draw() {
1228
1305
  ex="${ex[1,gkeep]}▏"
1229
1306
  fi
1230
1307
  fi
1231
- line="⌕ "$dd"search… e.g. $ex"$zz
1308
+ line=" "$dd"search… e.g. $ex"$zz
1232
1309
  fi
1233
- out+=$line$'\e[K\e['$(( lw - ${#cnt} + 1 ))'G'
1234
- if [[ -n $flt ]]; then
1235
- out+=$cnt$'\n'$ac
1236
- else
1237
- out+=$dd$cnt$zz$'\n'$dd
1310
+ local tail=$'\e['$(( lw - ${#cnt} ))'G'$dd$cnt$zz
1311
+ [[ -n $flt ]] && tail=$'\e['$(( lw - ${#cnt} ))'G'$cnt
1312
+ if [[ $1 == hint ]] && (( ! wiped )); then
1313
+ print -rn -- $'\e[H\e[0m\e['$lw'X'$line$tail
1314
+ printf '\e[?2026l'
1315
+ return 0
1238
1316
  fi
1239
- out+=${(l:lw::─:)}$zz$'\e[K\n\e[K\n'
1317
+ out+=$line$'\e[K'$tail$'\n\e[K\n'
1318
+ (( N > h && top > 1 )) && out+=" "$dd"…"$zz
1319
+ out+=$'\e[K\n'
1240
1320
  for (( k = 0; k < ph - 4; k++ )); do
1241
1321
  i=$(( top + k ))
1242
1322
  line=""
1243
1323
  if (( k < h )); then
1244
1324
  if (( ! N )); then
1245
- (( k == 0 )) && line=" ${dd}no palettes match '$flt'$zz"
1325
+ (( k == 0 )) && line=" ${dd}no palettes match '$flt'$zz"
1246
1326
  elif (( i <= N )); then
1247
1327
  __tt_pv_row $i
1248
1328
  line=$REPLY
1249
1329
  fi
1330
+ elif (( k == h && N > h && top + h <= N )); then
1331
+ line=" "$dd"…"$zz
1250
1332
  fi
1251
- out+=$line$'\e[K'
1252
- if (( rail && k < h )); then
1253
- if (( k + 1 >= rs && k + 1 < rs + rl )); then
1254
- out+=$'\e['$(( lw + 2 ))'G'$rthumb
1255
- else
1256
- out+=$'\e['$(( lw + 2 ))'G'$rtrack
1257
- fi
1258
- fi
1259
- out+=$'\n'
1333
+ out+=$line$'\e[K\n'
1260
1334
  done
1261
1335
  __tt_pv_foot $(( split ? se : pw ))
1262
1336
  if (( split )); then
1263
- out+=$'\e[2;'$sc'H'$dd${(l:$(( se - sc + 1 ))::─:)}$zz
1264
1337
  if (( help && sw >= 48 )); then
1265
1338
  __tt_pv_head 1 $sc $se keys
1266
1339
  __tt_pv_help
@@ -1323,15 +1396,19 @@ __tt_pv_canpick() {
1323
1396
  }
1324
1397
 
1325
1398
  __tt_pv_strip() {
1326
- local lo hi cell
1327
- local -a tp=(${=TTHEME_PALETTE[$1]}) v=()
1399
+ local hex cell=""
1400
+ local -a sw=(${=TTHEME_SWATCH[$1]})
1328
1401
  local -i j
1329
- for (( j = 5; j <= 12; j++ )); do
1330
- lo=${tp[j]#\#} hi=${tp[j+8]#\#}
1331
- v+=($((16#${lo:0:2})) $((16#${lo:2:2})) $((16#${lo:4:2})) $((16#${hi:0:2})) $((16#${hi:2:2})) $((16#${hi:4:2})))
1402
+ for (( j = 1; j <= 6; j++ )); do
1403
+ hex=${sw[j]#\#}
1404
+ (( j > 1 )) && cell+=" "
1405
+ if [[ -n $hex ]]; then
1406
+ cell+=$'\e[38;2;'$((16#${hex:0:2}))';'$((16#${hex:2:2}))';'$((16#${hex:4:2}))'m■'
1407
+ else
1408
+ cell+=" "
1409
+ fi
1332
1410
  done
1333
- printf -v cell '\e[38;2;%d;%d;%d;48;2;%d;%d;%dm▀▀' $v
1334
- tstrip[$1]=$cell$'\e[0m'
1411
+ tstrip[$1]=$cell$'\e[39m'
1335
1412
  }
1336
1413
 
1337
1414
  __tt_pv_init() {
@@ -1380,8 +1457,8 @@ __tt_pv_getch() {
1380
1457
  (( msgt -= gstep ? 6 : 20 ))
1381
1458
  (( msgt > 0 )) || return 1
1382
1459
  fi
1383
- (( gstep )) && { gstep=$(( gstep - 1 )); return 1 }
1384
- (( SECONDS >= exnext )) && { __tt_pv_roll; gstep=8; return 1 }
1460
+ (( gstep )) && { gstep=$(( gstep - 1 )); tick=1; return 1 }
1461
+ (( SECONDS >= exnext )) && { __tt_pv_roll; gstep=8; tick=1; return 1 }
1385
1462
  done
1386
1463
  return 0
1387
1464
  }
@@ -1554,7 +1631,7 @@ __tt_preview() {
1554
1631
  print -u2 "ttheme ${mode:-preview}: needs a terminal"
1555
1632
  return 1
1556
1633
  fi
1557
- 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
1634
+ local orig=$TTHEME_SPEC applied=$TTHEME_SPEC painted=$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 tick=0
1558
1635
  local pick="" pk=1 pkdef=1 picked=0 canpick=0 bgcw=0 bgch=0 bgname="" bgshown="" bginc="" osd="" osdt=0
1559
1636
  local tune="" tsnap="" tf=1 help=0 msg="" msgt=0 an="" bgrel=0 bgmx=0 bgmy=0 bganchor=0 bgcut=""
1560
1637
  local -A bgfrom=() bgsent=() bgdim=() bgsrc=() bgfill=() bgfocus=() bgsize=() bgpos=() bgop=() bgdef=() bgoff=() bgbase=() bgload=() bgshot=() bgshotkey=() bgedit=() bgtunef=() bgofff=() bgimages=()
@@ -1579,14 +1656,23 @@ __tt_preview() {
1579
1656
  __tt_pv_roll
1580
1657
  __tt_pv_rows
1581
1658
  [[ -n ${TTHEME_PALETTE[$cn]} ]] && __tt_pv_goto "$cn"
1582
- printf '\e[?2026h\e[?1049h\e[?7l\e[?25l'
1583
- __tt_pv_bg_open
1659
+ local tty=""
1660
+ local -i TTHEME_RAW=0
1584
1661
  {
1662
+ tty=$(stty -g 2>/dev/null && stty -echo -icanon min 1 time 0 2>/dev/null)
1663
+ TTHEME_RAW=$(( ${#tty} > 0 ))
1664
+ printf '\e[?2026h\e[?1049h\e[?7l\e[?25l'
1665
+ __tt_pv_bg_open
1585
1666
  while :; do
1586
1667
  printf '\e[?2026h'
1587
- __tt_pv_focus
1588
- [[ ${rtype[cur]} == thm ]] && an=${rval[cur]}
1589
- __tt_pv_draw
1668
+ if (( tick )); then
1669
+ __tt_pv_draw hint
1670
+ else
1671
+ __tt_pv_focus
1672
+ [[ ${rtype[cur]} == thm ]] && an=${rval[cur]}
1673
+ __tt_pv_draw
1674
+ fi
1675
+ tick=0
1590
1676
  if ! __tt_pv_read; then
1591
1677
  [[ -t 0 ]] && continue
1592
1678
  break
@@ -1597,15 +1683,27 @@ __tt_preview() {
1597
1683
  done
1598
1684
  done
1599
1685
  } always {
1686
+ local spec=${sel:+${TTHEME_PALETTE[$sel]}}
1600
1687
  printf '\e[?2026h'
1601
1688
  __tt_pv_bg_close
1689
+ if [[ -n $spec ]]; then
1690
+ [[ $spec == "$painted" ]] || __tt_apply "$spec"
1691
+ elif [[ $painted != "$orig" ]]; then
1692
+ if [[ -z $orig ]]; then
1693
+ __tt_osc_reset
1694
+ else
1695
+ __tt_apply "$orig"
1696
+ fi
1697
+ elif [[ $applied != "$orig" ]]; then
1698
+ __tt_pv_paint "${TTHEME_PAINTED:+$orig}"
1699
+ fi
1602
1700
  printf '\e[?7h\e[?1049l\e[?25h\e[?2026l'
1701
+ [[ -n $tty ]] && stty "$tty" 2>/dev/null
1702
+ TTHEME_RAW=0
1603
1703
  [[ -n $tune ]] && __tt_pv_untune
1604
1704
  (( conf )) && __tt_pv_unconf
1605
1705
  __tt_pv_bg_save
1606
- if [[ -n $sel ]]; then
1607
- local spec=${TTHEME_PALETTE[$sel]}
1608
- [[ $spec == "$applied" ]] || __tt_apply "$spec"
1706
+ if [[ -n $spec ]]; then
1609
1707
  TTHEME_SPEC=$spec
1610
1708
  __tt_announce
1611
1709
  if [[ $mode == pin ]]; then
@@ -1617,11 +1715,6 @@ __tt_preview() {
1617
1715
  __tt_shown "$sel" force && __tt_reload
1618
1716
  fi
1619
1717
  else
1620
- if [[ -z $orig && -n $applied ]]; then
1621
- __tt_osc_reset
1622
- elif [[ $orig != "$applied" ]]; then
1623
- __tt_apply "$orig"
1624
- fi
1625
1718
  (( ${#bgedit} )) && [[ -n ${TTHEME_PALETTE[$cn]} ]] && { __tt_shown "$cn" && __tt_reload }
1626
1719
  fi
1627
1720
  }
@@ -1708,15 +1801,12 @@ fi
1708
1801
  if __tt_active; then
1709
1802
  [[ -n $TMUX ]] && __tt_tmux
1710
1803
  () {
1711
- local REPLY k
1804
+ local REPLY
1712
1805
  if [[ -n $TTHEME_SPEC ]]; then
1713
1806
  :
1714
1807
  elif [[ $TTHEME_TAB_PALETTE == off ]]; then
1715
- if __tt_start_bg; then
1716
- for k in ${(k)TTHEME_PALETTE}; do
1717
- [[ ${TTHEME_PALETTE[$k]%% *} == "$REPLY" ]] && { TTHEME_SPEC=$TTHEME_PALETTE[$k]; break }
1718
- done
1719
- fi
1808
+ [[ -n $TTHEME_HEARD ]] || __tt_listen
1809
+ __tt_start_bg && __tt_wearing $REPLY && TTHEME_SPEC=$REPLY
1720
1810
  else
1721
1811
  __tt_next
1722
1812
  TTHEME_SPEC=$REPLY
@@ -1725,8 +1815,8 @@ if __tt_active; then
1725
1815
  __tt_dir_sync
1726
1816
  }
1727
1817
  autoload -Uz add-zsh-hook add-zle-hook-widget
1728
- zle -N __tt_typed
1729
- add-zle-hook-widget line-init __tt_typed
1818
+ zle -N __tt_line_init
1819
+ add-zle-hook-widget line-init __tt_line_init
1730
1820
  add-zsh-hook chpwd __tt_chpwd
1731
1821
  add-zsh-hook precmd __tt_fresh
1732
1822
  if (( ! TTHEME_TMUX )); then