@kecan0406/ttheme 1.2.17 → 1.2.18

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/preview.zsh CHANGED
@@ -157,7 +157,7 @@ typeset -gA TTHEME_GLYPHS=(
157
157
  )
158
158
 
159
159
  __tt_pv_osd() {
160
- local text=${(U)osd} bits line oc=$'\e[1m' blank
160
+ local text=${(U)osd} bits line oc=$TTHEME_SGR[bold] blank
161
161
  local -i s=2 n=${#text} w r c k i top left
162
162
  (( n * 16 + 4 <= pw && ph >= 14 )) || s=1
163
163
  w=$(( n * 8 * s - 2 * s + 4 ))
@@ -186,7 +186,7 @@ __tt_pv_osd() {
186
186
  done
187
187
  line+=" "
188
188
  for (( i = 0; i < s; i++ )); do
189
- out+=$'\e['$(( top + r * s + i ))';'${left}H$oc$line$'\e[0m'
189
+ out+=$'\e['$(( top + r * s + i ))';'${left}H$oc$line$TTHEME_SGR[reset]
190
190
  done
191
191
  done
192
192
  out+=$'\e['$(( top + 5 * s ))';'${left}H$blank
@@ -217,7 +217,7 @@ __tt_pv_hl() {
217
217
  REPLY=$t
218
218
  (( color )) && [[ -n $flt && $lt == *$flt* ]] || return 0
219
219
  pre=${lt%%$flt*}
220
- REPLY=${t[1,${#pre}]}$'\e[1;4m'$ac${t[${#pre}+1,${#pre}+${#flt}]}$'\e[22;24;39m'$2${t[${#pre}+${#flt}+1,-1]}
220
+ REPLY=${t[1,${#pre}]}$hm${t[${#pre}+1,${#pre}+${#flt}]}$TTHEME_SGR[/match]$2${t[${#pre}+${#flt}+1,-1]}
221
221
  }
222
222
 
223
223
  __tt_pv_fit() {
@@ -233,11 +233,11 @@ __tt_pv_fit() {
233
233
  }
234
234
 
235
235
  __tt_pv_row() {
236
- 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=▸ ind=" " hl extra part
236
+ local t=${rval[$1]} b=$TTHEME_SGR[bold] d=$TTHEME_SGR[dim] r=$TTHEME_SGR[/match] z=$TTHEME_SGR[reset] on="" gut=" " base="" lead=$TTHEME_SGR[dim] mark=" " name arrow=▸ ind=" " hl extra part
237
237
  local -i w
238
238
  (( color )) || b= d= r= z= lead=
239
239
  if (( $1 == cur )); then
240
- gut=$ac"▌"$r" "
240
+ gut=$gc"▌"$r" "
241
241
  (( color )) && on=$sb
242
242
  fi
243
243
  if [[ ${rtype[$1]} == rule ]]; then
@@ -282,14 +282,18 @@ __tt_pv_row() {
282
282
  return 0
283
283
  fi
284
284
  if (( $1 == cur )); then
285
- mark=$ac"■"$r base=$b
285
+ mark=$gc"■"$r base=$b
286
286
  elif [[ -n $cdot && $t == "$cn" ]]; then
287
- mark=$cdot
287
+ mark=$ac$cdot$r
288
288
  fi
289
289
  name=${t##*/}
290
290
  [[ -n ${TTHEME_CATALOG[$t]} && ${TTHEME_GROUP[$t]} == *@* ]] && ind=" "
291
291
  __tt_pv_hl "$name" "$base"
292
292
  hl=$REPLY
293
+ if (( ${TTHEME_TUNED[(Ie)$t]} )); then
294
+ (( color )) && hl+=" "$TTHEME_SGR[warn]"●"$TTHEME_SGR[/warn] || hl+=" ●"
295
+ w=-2
296
+ fi
293
297
  extra=""
294
298
  for part in "${(@s:|:)TTHEME_NATIVE_NAMES[$t]}" "${TTHEME_CHARACTER[$t]}" "${(@s:|:)TTHEME_ALIASES[$t]}"; do
295
299
  __tt_pv_alias "$name" "$part"
@@ -297,7 +301,7 @@ __tt_pv_row() {
297
301
  done
298
302
  if (( color )); then
299
303
  [[ -n ${tstrip[$t]} ]] || __tt_pv_strip $t
300
- w=$(( lw - 16 - ${#ind} - ${#name} ))
304
+ w=$(( w + lw - 16 - ${#ind} - ${#name} ))
301
305
  __tt_pv_fit "$extra"
302
306
  (( w < 1 )) && w=1
303
307
  REPLY=$gut$on"$ind$mark $base$hl$r$REPLY${(l:w:: :)}${tstrip[$t]} "$z
@@ -314,13 +318,13 @@ __tt_pv_bg_credit() {
314
318
  (( ${#REPLY} > room )) && REPLY=${by:+by $by}
315
319
  (( ${#REPLY} > room )) && REPLY=""
316
320
  [[ -n $mark && $REPLY == *"$mark$ref"* ]] || return 0
317
- (( color )) && [[ -n ${TTHEME_SITE_ANSI[${ref%% *}]} ]] && sgr=$'\e[3'${TTHEME_SITE_ANSI[${ref%% *}]}m
318
- REPLY=${REPLY/"$mark$ref"/$sgr⧉${sgr:+$'\e[39m'} $'\e]8;;'$url$'\e\\'$ref$'\e]8;;\e\\'}
321
+ (( color )) && [[ -n ${TTHEME_SITE_ANSI[${ref%% *}]} ]] && sgr=$TTHEME_SGR[fg${TTHEME_SITE_ANSI[${ref%% *}]}]
322
+ REPLY=${REPLY/"$mark$ref"/$sgr⧉${sgr:+$TTHEME_SGR[/fg]} $'\e]8;;'$url$'\e\\'$ref$'\e]8;;\e\\'}
319
323
  return 0
320
324
  }
321
325
 
322
326
  __tt_pv_bar() {
323
- local z=$'\e[0m' d=$'\e[2m' on=$'\e[7;1m'$ac line=" " title hint="tab next"
327
+ local z=$TTHEME_SGR[reset] d=$TTHEME_SGR[dim] on=$pl line=" " title hint="tab next"
324
328
  local -i i at=${TTHEME_HUB_TABS[(Ie)preview]} len=${#TTHEME_HUB_TITLES}
325
329
  (( color )) || z= d= on=
326
330
  [[ ${rtype[cur]} == thm ]] && hint="⇧tab switch"
@@ -346,9 +350,9 @@ __tt_pv_bar() {
346
350
  }
347
351
 
348
352
  __tt_pv_head() {
349
- local b=$'\e[1m' d=$'\e[2m' z=$'\e[0m' right=$6
353
+ local b=$TTHEME_SGR[bold] d=$TTHEME_SGR[dim] z=$TTHEME_SGR[reset] right=$6
350
354
  (( color )) || b= d= z=
351
- out+=$'\e['$1';'$2'H'$b$ac$4$z
355
+ out+=$'\e['$1';'$2'H'$b$gc$4$z
352
356
  [[ -n $5 ]] && out+=" "$d$5$z
353
357
  [[ -n $right ]] && out+=$'\e['$(( $3 - ${(m)#right} + 1 ))'G'$d$right$z
354
358
  return 0
@@ -356,7 +360,7 @@ __tt_pv_head() {
356
360
 
357
361
  __tt_pv_foot() {
358
362
  setopt localoptions extendedglob
359
- 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 tb=EDIT
363
+ local b=$TTHEME_SGR[bold] d=$TTHEME_SGR[dim] z=$TTHEME_SGR[reset] y=$TTHEME_SGR[warn] on=$pl badge="" lead="" note="" right="" text line plain hex tb=EDIT
360
364
  local -a kk=() kl=() seg=()
361
365
  local -i end=$1 i lwid rwid room
362
366
  (( color )) || b= d= z= y= on=
@@ -394,6 +398,8 @@ __tt_pv_foot() {
394
398
  right=$b"esc"$z$d" back"$z
395
399
  elif (( te && tfocus == 0 )); then
396
400
  badge=$tb kk=(enter ↑↓ s ⇧enter) kl=("edit palette" move save apply)
401
+ (( tbtn )) && kl[1]="reset palette"
402
+ (( ${TTHEME_TUNED[(Ie)$tename]} )) && kk[2]=↑↓←→
397
403
  right=$b"esc"$z$d" cancel"$z
398
404
  elif (( te && tfocus == 2 )); then
399
405
  badge=$tb kk=(enter ↑↓ s) kl=(apply move save)
@@ -448,7 +454,7 @@ __tt_pv_foot() {
448
454
  right=$b"esc"$z$d" clear filter"$z
449
455
  else
450
456
  right=$b"esc"$z$d" restore"$z
451
- [[ -n $cdot ]] && right+=" $cdot$z $cn"
457
+ [[ -n $cdot ]] && right+=" $ac$cdot$z $cn"
452
458
  fi
453
459
  fi
454
460
  if (( msgt > 0 )) && [[ -z $pick ]]; then
@@ -470,7 +476,7 @@ __tt_pv_foot() {
470
476
  line=${(j: :)seg}
471
477
  if [[ -n $badge ]]; then
472
478
  if (( color )); then
473
- line=$'\e[7;1m'$ac" $badge "$z" "$line
479
+ line=$on" $badge "$z" "$line
474
480
  else
475
481
  line="[$badge] $line"
476
482
  fi
@@ -521,7 +527,7 @@ __tt_pv_foot() {
521
527
  }
522
528
 
523
529
  __tt_pv_help() {
524
- local back="the tab" z=$'\e[0m' b=$'\e[1m' blank
530
+ local back="the tab" z=$TTHEME_SGR[reset] b=$TTHEME_SGR[bold] blank
525
531
  [[ -n ${TTHEME_PALETTE[$cn]} ]] && back=$cn
526
532
  local -a hk=() hv=()
527
533
  if (( te )); then
@@ -560,7 +566,7 @@ __tt_pv_help() {
560
566
  hv+=("? esc")
561
567
  fi
562
568
  (( color )) || z= b=
563
- local -i i r x y w hh
569
+ local -i i r x y w hh floor
564
570
  if (( split && sw >= 48 )); then
565
571
  for (( i = 1; i <= ${#hk}; i++ )); do
566
572
  r=$(( i + 3 ))
@@ -572,7 +578,10 @@ __tt_pv_help() {
572
578
  w=$(( pw - 2 < 58 ? pw - 2 : 58 )) hh=$(( ${#hk} + 4 ))
573
579
  (( te )) && w=$(( pw - 2 < 76 ? pw - 2 : 76 ))
574
580
  x=$(( (pw - w) / 2 + 1 )) y=$(( (ph - hh) / 2 ))
575
- (( y < 4 )) && y=4
581
+ floor=$(( te && ! split ? 4 : pvhd + 2 ))
582
+ (( y < floor )) && y=$floor
583
+ (( y > ph - hh )) && y=$(( ph - hh ))
584
+ (( y < 1 )) && y=1
576
585
  blank=${(l:w:: :)}
577
586
  out+=$'\e['$y';'$x'H'"╭─ Help ${(l:$(( w - 9 ))::─:)}╮"
578
587
  for (( r = y + 1; r < y + hh - 1; r++ )); do
@@ -588,8 +597,8 @@ __tt_pv_help() {
588
597
  __tt_pv_specimen() {
589
598
  local -a sp=(${=applied}) lines parts
590
599
  (( ${#sp} >= 20 )) || return 0
591
- local z=$'\e[0m' d=$'\e[2m' cell hex fore line text piece role tabs="" built="" key="$applied|$painted|$scene|$sw|$sc|$ph"
592
- local -A rs=(p "" d $'\e[2m' b $'\e[1m')
600
+ local z=$TTHEME_SGR[reset] d=$TTHEME_SGR[dim] cell hex fore line text piece role tabs="" built="" key="$applied|$painted|$scene|$sw|$sc|$ph"
601
+ local -A rs=(p "" d $TTHEME_SGR[dim] b $TTHEME_SGR[bold])
593
602
  local -i i r=6 cw=4 k n=${#TTHEME_SCENES} at
594
603
  (( n )) || return 0
595
604
  if [[ $key == "$pvscene" ]]; then
@@ -624,13 +633,13 @@ __tt_pv_specimen() {
624
633
  for (( k = 1; k <= n; k++ )); do
625
634
  (( k > 1 )) && tabs+=" "
626
635
  if (( k == at )); then
627
- tabs+=$'\e[1m'$ac$TTHEME_SCENES[k]$z
636
+ tabs+=$TTHEME_SGR[bold]$ac$TTHEME_SCENES[k]$z
628
637
  else
629
638
  tabs+=$d$TTHEME_SCENES[k]$z
630
639
  fi
631
640
  done
632
641
  else
633
- tabs=$'\e[1m'$ac$TTHEME_SCENES[at]$z" "$d"$at/$n"$z
642
+ tabs=$TTHEME_SGR[bold]$ac$TTHEME_SCENES[at]$z" "$d"$at/$n"$z
634
643
  fi
635
644
  built+=$'\e[2;'$sc'H'$tabs
636
645
  (( sw < 44 )) && cw=3
@@ -639,7 +648,7 @@ __tt_pv_specimen() {
639
648
  line=""
640
649
  for (( i = 0; i < 8; i++ )); do
641
650
  fore=${sp[i+5]#\#} hex=${sp[i+13]#\#}
642
- printf -v cell '\e[38;2;%d;%d;%d;48;2;%d;%d;%dm%s\e[0m ' \
651
+ printf -v cell "\e[38;2;%d;%d;%d;48;2;%d;%d;%dm%s${TTHEME_SGR[/ink]} " \
643
652
  $((16#${fore:0:2})) $((16#${fore:2:2})) $((16#${fore:4:2})) \
644
653
  $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2})) "${(l:cw::▀:)}"
645
654
  line+=$cell
@@ -808,6 +817,7 @@ __tt_pv_conf_save() {
808
817
  __tt_tilde "$TTHEME_CONFIG"
809
818
  if __tt_config_write "${pairs[@]}"; then
810
819
  conf=0 msg="Saved · $REPLY" msgt=200
820
+ (( ${pairs[(Ie)TTHEME_TAB_PALETTE]} )) && __tt_cli sync > /dev/null 2>&1 && __tt_reload
811
821
  (( ${pairs[(Ie)TTHEME_BG_BLUR]} )) && __tt_pv_redraw
812
822
  else
813
823
  __tt_pv_unconf
@@ -834,7 +844,7 @@ __tt_pv_redraw() {
834
844
  }
835
845
 
836
846
  __tt_pv_conf_panel() {
837
- local z=$'\e[0m' b=$'\e[1m' d=$'\e[2m' c=$ac on=$'\e[7;1m'$ac var v note
847
+ local z=$TTHEME_SGR[reset] b=$TTHEME_SGR[bold] d=$TTHEME_SGR[dim] c=$ac on=$pl var v note
838
848
  local -a ch sh
839
849
  local -i r0=$1 col=$2 end=$3 k i j fit=1
840
850
  (( color )) || z= b= d= c= on=
@@ -904,11 +914,11 @@ __tt_pv_flush() {
904
914
  elif (( ${#bgthumb} )); then
905
915
  __tt_pv_bg_strip_off
906
916
  fi
907
- printf '\e[1;%dH\e[?2026l' $(( 4 + ${(m)#flt} ))
917
+ printf '\e[%d;%dH\e[?2026l' $pvsr $pvsc
908
918
  }
909
919
 
910
920
  __tt_pv_reach() {
911
- local key=${pkeys[pk]} base top k home=${HOME:a} here=${PWD:a} htip="" d=$'\e[2m' z=$'\e[0m' REPLY
921
+ local key=${pkeys[pk]} base top k home=${HOME:a} here=${PWD:a} htip="" d=$TTHEME_SGR[dim] z=$TTHEME_SGR[reset] REPLY
912
922
  local -A own=() below=() parent=() mark=() tstrip=()
913
923
  local -a roots=() lp=() lpw=() ll=() lat=() lpal=() lnote=() lflag=() reply was=()
914
924
  local -A TTHEME_PINS=("${(@kv)TTHEME_PINS}")
@@ -941,7 +951,7 @@ __tt_pv_reach() {
941
951
  __tt_map_build "$top"
942
952
  fi
943
953
  __tt_map_fit $1
944
- (( ${#reply} > room )) && reply=("${(@)reply[1,room-1]}" " …")
954
+ (( ${#reply} > room )) && reply=("${(@)reply[1,room-1]}" " …")
945
955
  reach=("${reply[@]}")
946
956
  [[ $key == /* || ${#was} -gt 0 ]] && reach+=("")
947
957
  __tt_pin_where "$key"
@@ -959,8 +969,8 @@ __tt_pv_reach() {
959
969
  }
960
970
 
961
971
  __tt_pv_draw() {
962
- local out line cnt ex ag="" acat="" ac="" sb="" dd="" zz="" state=on src="" nflt="" rsub="" REPLY
963
- local -i lw sw split sc se=$(( pw - 2 )) h k i N=${#rval} mt=${#TTHEME_ORDER} wiped=0
972
+ local out line cnt ex ag="" acat="" ac="" gc="" pl="" hm="" sb="" dd="" zz="" state=on src="" nflt="" rsub="" REPLY
973
+ local -i lw sw split sc se=$(( pw - 2 )) h k i N=${#rval} mt=${#TTHEME_ORDER} wiped=0 tall=$(( ph >= 22 )) hd
964
974
  local -a held
965
975
  bgstrip=""
966
976
  if [[ -n $flt ]]; then
@@ -970,15 +980,16 @@ __tt_pv_draw() {
970
980
  __tt_pv_lw
971
981
  lw=$reply[1] sw=$reply[2]
972
982
  split=$(( sw > 0 )) sc=$(( pw - 1 - sw ))
973
- h=$(( ph - 5 ))
974
- (( conf && ! split )) && h=$(( ph - 6 - ${#cvars} ))
983
+ hd=$(( tall ? hub + 4 : 2 )) pvhd=$hd
984
+ h=$(( ph - hd - 3 ))
985
+ (( conf && ! split )) && h=$(( ph - hd - 4 - ${#cvars} ))
975
986
  reach=()
976
987
  if [[ -n $pick && $mode == pin ]]; then
977
988
  if (( split )); then
978
989
  __tt_pv_reach $sw $(( ph - 6 ))
979
990
  else
980
- __tt_pv_reach $se $(( ph - 13 ))
981
- h=$(( ph - 6 - ${#reach} ))
991
+ __tt_pv_reach $se $(( ph - hd - 11 ))
992
+ h=$(( ph - hd - 4 - ${#reach} ))
982
993
  fi
983
994
  fi
984
995
  (( h < 1 )) && h=1
@@ -987,12 +998,16 @@ __tt_pv_draw() {
987
998
  (( top < 1 )) && top=1
988
999
  (( N > h && top > N - h + 1 )) && top=$(( N - h + 1 ))
989
1000
  if (( color )); then
990
- dd=$'\e[2m' zz=$'\e[0m'
1001
+ dd=$TTHEME_SGR[dim] zz=$TTHEME_SGR[reset] ac=$TTHEME_SGR[accent] pl=$TTHEME_SGR[pill] hm=$TTHEME_SGR[match]
991
1002
  if [[ -n $applied ]]; then
992
1003
  local -a ap=(${=applied})
993
- local acx=${ap[3]#\#} sbx=${ap[4]#\#}
994
- printf -v ac '\e[38;2;%d;%d;%dm' $((16#${acx:0:2})) $((16#${acx:2:2})) $((16#${acx:4:2}))
1004
+ local acx=${ap[3]#\#} sbx=${ap[4]#\#} six=${ap[11]#\#}
1005
+ printf -v gc '\e[38;2;%d;%d;%dm' $((16#${acx:0:2})) $((16#${acx:2:2})) $((16#${acx:4:2}))
995
1006
  printf -v sb '\e[48;2;%d;%d;%dm' $((16#${sbx:0:2})) $((16#${sbx:2:2})) $((16#${sbx:4:2}))
1007
+ if [[ $applied != "$painted" && -n $six ]]; then
1008
+ printf -v ac '\e[38;2;%d;%d;%dm' $((16#${six:0:2})) $((16#${six:2:2})) $((16#${six:4:2}))
1009
+ pl+=$ac hm+=$ac
1010
+ fi
996
1011
  fi
997
1012
  if [[ ${rtype[cur]} == thm ]]; then
998
1013
  ag=${TTHEME_GROUP[${rval[cur]}]:-Other}
@@ -1013,10 +1028,10 @@ __tt_pv_draw() {
1013
1028
  [[ $1 == hint ]] && (( ! wiped )) || pvz=()
1014
1029
  if (( pw < 40 || ph < 12 )); then
1015
1030
  line="ttheme"
1016
- (( color )) && line=$'\e[1m'$ac$line$'\e[0m'
1031
+ (( color )) && line=$TTHEME_SGR[bold]$ac$line$TTHEME_SGR[reset]
1017
1032
  out+=$line$'\e[K\n'"Needs 40×12 — now ${pw}×${ph}"$'\e[K\n'
1018
1033
  line="esc quits"
1019
- (( color )) && line=$'\e[2m'$line$'\e[0m'
1034
+ (( color )) && line=$TTHEME_SGR[dim]$line$TTHEME_SGR[reset]
1020
1035
  out+=$line$'\e[K\e[J'
1021
1036
  __tt_pv_flush
1022
1037
  return 0
@@ -1025,15 +1040,14 @@ __tt_pv_draw() {
1025
1040
  __tt_pv_te_draw
1026
1041
  return 0
1027
1042
  fi
1043
+ local find bd="" edge=${(l:$(( lw - 3 ))::─:)}
1044
+ (( color )) && bd=$TTHEME_SGR[bold]
1028
1045
  if [[ -n $flt ]]; then
1029
- if (( color )); then
1030
- line=" "$'\e[1m'$flt$zz$ac$'\e[7m \e[0m'
1031
- else
1032
- line=" ${flt}_"
1033
- fi
1046
+ find=$flt"_"
1034
1047
  else
1035
1048
  ex="$expal | $exgrp"
1036
- (( ${#ex} > lw - 19 - ${#cnt} )) && ex="${ex[1,lw-20-${#cnt}]}…"
1049
+ local -i room=$(( tall ? lw - 21 : lw - 19 - ${#cnt} ))
1050
+ (( ${#ex} > room )) && ex="${ex[1,room-1]}…"
1037
1051
  if (( gstep > 0 )); then
1038
1052
  local gkeep=$(( ${#ex} * (8 - gstep) / 8 ))
1039
1053
  if [[ $TTHEME_FX == (decode|glitch) ]]; then
@@ -1051,27 +1065,37 @@ __tt_pv_draw() {
1051
1065
  ex="${ex[1,gkeep]}▏"
1052
1066
  fi
1053
1067
  fi
1054
- line=" "$dd"Search… e.g. $ex"$zz
1068
+ find=$dd"Search… e.g. $ex"$zz
1069
+ fi
1070
+ if (( tall )); then
1071
+ pvsr=$(( hub + 3 )) pvsc=$(( 6 + ${(m)#flt} ))
1072
+ line=$'\e['$lw'X '$dd"│"$zz" "$dd"⌕"$zz" "$find$'\e['$lw'G'$dd"│"$zz
1073
+ else
1074
+ pvsr=$(( hub + 1 )) pvsc=$(( 4 + ${(m)#flt} ))
1075
+ line=$'\e['$lw'X '$dd"⌕"$zz" "$find$'\e['$(( lw - ${#cnt} ))'G'$dd$cnt$zz
1055
1076
  fi
1056
- local tail=$'\e['$(( lw - ${#cnt} ))'G'$dd$cnt$zz
1057
- [[ -n $flt ]] && tail=$'\e['$(( lw - ${#cnt} ))'G'$cnt
1058
1077
  if [[ $1 == hint ]] && (( ! wiped )); then
1059
- print -rn -- $'\e['$(( 1 + hub ))$'H\e[0m\e['$lw'X'$line$tail
1060
- printf '\e[%d;%dH\e[?2026l' $(( 1 + hub )) $(( 4 + ${(m)#flt} ))
1078
+ print -rn -- $'\e['$pvsr'H'$TTHEME_SGR[reset]$line
1079
+ printf '\e[%d;%dH\e[?2026l' $pvsr $pvsc
1061
1080
  return 0
1062
1081
  fi
1063
1082
  if (( hub )); then
1064
1083
  __tt_pv_bar $(( split ? sc - 2 : pw - 1 ))
1065
- out+=$REPLY$'\e[K\n'$line$'\e[K'$tail$'\n'
1084
+ out+=$REPLY$'\e[K\n'
1085
+ fi
1086
+ if (( tall )); then
1087
+ out+=" "$bd"Preview"$zz" "$dd"($cnt)"$zz$'\e[K\n'
1088
+ out+=" "$dd"╭"$edge"╮"$zz$'\e[K\n'$line$'\e[K\n'" "$dd"╰"$edge"╯"$zz$'\e[K\n'
1066
1089
  else
1067
- out+=$line$'\e[K'$tail$'\n\e[K\n'
1090
+ out+=$line$'\e[K\n'
1091
+ (( hub )) || out+=$'\e[K\n'
1068
1092
  fi
1069
1093
  if (( N > h && top > 1 )); then
1070
1094
  out+=" "$dd"…"$zz
1071
- pvz+=("3 1 $lw more -1")
1095
+ pvz+=("$(( hd + 1 )) 1 $lw more -1")
1072
1096
  fi
1073
1097
  out+=$'\e[K\n'
1074
- for (( k = 0; k < ph - 4; k++ )); do
1098
+ for (( k = 0; k < ph - hd - 2; k++ )); do
1075
1099
  i=$(( top + k ))
1076
1100
  line=""
1077
1101
  if (( k < h )); then
@@ -1080,15 +1104,15 @@ __tt_pv_draw() {
1080
1104
  elif (( i <= N )); then
1081
1105
  __tt_pv_row $i
1082
1106
  line=$REPLY
1083
- pvz+=("$(( 4 + k )) 1 $lw row $i")
1107
+ pvz+=("$(( hd + 2 + k )) 1 $lw row $i")
1084
1108
  case ${rtype[i]} in
1085
- hdr) pvz+=("$(( 4 + k )) 3 5 fold $i") ;;
1086
- cat) pvz+=("$(( 4 + k )) 5 7 fold $i") ;;
1109
+ hdr) pvz+=("$(( hd + 2 + k )) 3 5 fold $i") ;;
1110
+ cat) pvz+=("$(( hd + 2 + k )) 5 7 fold $i") ;;
1087
1111
  esac
1088
1112
  fi
1089
1113
  elif (( k == h && N > h && top + h <= N )); then
1090
1114
  line=" "$dd"…"$zz
1091
- pvz+=("$(( 4 + k )) 1 $lw more 1")
1115
+ pvz+=("$(( hd + 2 + k )) 1 $lw more 1")
1092
1116
  fi
1093
1117
  out+=$line$'\e[K\n'
1094
1118
  done
@@ -1167,20 +1191,14 @@ __tt_pv_strip() {
1167
1191
  cell+=" "
1168
1192
  fi
1169
1193
  done
1170
- tstrip[$1]=$cell$'\e[39m'
1194
+ tstrip[$1]=$cell$TTHEME_SGR[/fg]
1171
1195
  }
1172
1196
 
1173
1197
  __tt_pv_init() {
1174
- local lo
1175
- local -a tp
1176
1198
  __tt_pv_group
1177
1199
  [[ -n $orig ]] && __tt_name_of "$orig" && cn=$REPLY
1178
1200
  [[ -n ${TTHEME_PALETTE[$cn]} ]] || return 0
1179
1201
  cdot="◆"
1180
- (( color )) || return 0
1181
- tp=(${=TTHEME_PALETTE[$cn]})
1182
- lo=${tp[3]#\#}
1183
- printf -v cdot '\e[38;2;%d;%d;%dm◆\e[39m' $((16#${lo:0:2})) $((16#${lo:2:2})) $((16#${lo:4:2}))
1184
1202
  }
1185
1203
 
1186
1204
  __tt_pv_roll() {
@@ -1370,12 +1388,15 @@ __tt_pv_free() {
1370
1388
  }
1371
1389
 
1372
1390
  __tt_pv_press() {
1391
+ [[ $4 == tereset ]] || tearm=0
1373
1392
  case $4 in
1374
1393
  row|fold) __tt_pv_free && [[ ${rtype[$5]} != rule ]] && cur=$5 ;;
1375
1394
  pick) pk=$5 ;;
1376
1395
  conf) cf=$5 ;;
1377
1396
  teimg) (( tfocus == 1 )) || __tt_te_to_image ;;
1378
- tepal|teedit) tfocus=0 ;;
1397
+ tepal) tfocus=0 ;;
1398
+ teedit) tfocus=0 tbtn=0 ;;
1399
+ tereset) tfocus=0 tbtn=1 ;;
1379
1400
  tefield|track|place|colors)
1380
1401
  (( tfocus == 1 )) || __tt_te_to_image
1381
1402
  case $4 in
@@ -1432,6 +1453,7 @@ __tt_pv_release() {
1432
1453
  ;;
1433
1454
  tefind) __tt_te_find ;;
1434
1455
  teedit) __tt_te_edit ;;
1456
+ tereset) __tt_te_resetting ;;
1435
1457
  teapply) __tt_te_apply || return 1 ;;
1436
1458
  place) __tt_pv_bg_adjust at $5 ;;
1437
1459
  colors)
@@ -1558,7 +1580,7 @@ __tt_te_read() {
1558
1580
 
1559
1581
  __tt_te_open() {
1560
1582
  local name=$1
1561
- tename=$name tfocus=0 teframe=() tetop=0 msgt=0 te=1
1583
+ tename=$name tfocus=0 teframe=() tetop=0 msgt=0 te=1 tbtn=0 tearm=0
1562
1584
  if ! __tt_te_read; then
1563
1585
  msg="Could not read the colors of $name" msgt=300
1564
1586
  tename="" te=0
@@ -1572,7 +1594,7 @@ __tt_te_open() {
1572
1594
 
1573
1595
  __tt_te_close() {
1574
1596
  [[ -n $tune ]] && __tt_pv_untune
1575
- te=0 tfocus=0 tename="" teframe=() tetop=0 help=0 pick=""
1597
+ te=0 tfocus=0 tename="" teframe=() tetop=0 tbtn=0 tearm=0 help=0 pick=""
1576
1598
  resized=1 bgname=""
1577
1599
  return 0
1578
1600
  }
@@ -1644,8 +1666,14 @@ __tt_pv_unpaint() {
1644
1666
  fi
1645
1667
  }
1646
1668
 
1669
+ __tt_te_follow() {
1670
+ [[ $orig == "$1" && -n ${TTHEME_PALETTE[$tename]} ]] || return 0
1671
+ orig=${TTHEME_PALETTE[$tename]}
1672
+ TTHEME_SPEC=$orig
1673
+ }
1674
+
1647
1675
  __tt_te_edit() {
1648
- local name=$tename err back=$applied
1676
+ local name=$tename err back=$applied was=${TTHEME_PALETTE[$tename]}
1649
1677
  local -i rc
1650
1678
  __tt_te_save_image
1651
1679
  __tt_pv_untune
@@ -1660,6 +1688,7 @@ __tt_te_edit() {
1660
1688
  resized=1 bgname="" bgshown="" bgdim=()
1661
1689
  if (( rc == 0 )); then
1662
1690
  __tt_palettes_load && __tt_reloaded
1691
+ __tt_te_follow "$was"
1663
1692
  __tt_reload
1664
1693
  back=${TTHEME_PALETTE[$name]:-$back}
1665
1694
  fi
@@ -1677,11 +1706,56 @@ __tt_te_edit() {
1677
1706
  return 0
1678
1707
  }
1679
1708
 
1709
+ __tt_te_reset() {
1710
+ local name=$tename err was=${TTHEME_PALETTE[$tename]}
1711
+ local -i rc
1712
+ __tt_te_save_image
1713
+ __tt_pv_untune
1714
+ __tt_pv_bg_close
1715
+ err=$(__tt_cli tone $name reset 2>&1 >/dev/null)
1716
+ rc=$?
1717
+ err=${${err//$'\n'/ }## #}
1718
+ tbtn=0 tearm=0 resized=1 bgname="" bgshown="" bgdim=()
1719
+ if (( rc == 0 )); then
1720
+ __tt_palettes_load && __tt_reloaded
1721
+ __tt_te_follow "$was"
1722
+ __tt_reload
1723
+ [[ -n ${TTHEME_PALETTE[$name]} ]] && __tt_pv_paint "${TTHEME_PALETTE[$name]}" && applied=${TTHEME_PALETTE[$name]}
1724
+ __tt_pv_bg_reset $name
1725
+ bgload[$name]=""
1726
+ __tt_te_read
1727
+ msg=${err:-"Back to the original colors"} msgt=200
1728
+ elif (( rc == 1 )); then
1729
+ msg=${err:-"Could not reset the colors of $name"} msgt=300
1730
+ fi
1731
+ __tt_pv_bg_state $name && __tt_pv_tune_open $name
1732
+ return 0
1733
+ }
1734
+
1735
+ __tt_te_resetting() {
1736
+ if (( tearm )); then
1737
+ __tt_te_reset
1738
+ else
1739
+ tearm=1
1740
+ fi
1741
+ }
1742
+
1680
1743
  __tt_te_palette() {
1744
+ local -i armed=$tearm
1745
+ tearm=0
1746
+ (( ${TTHEME_TUNED[(Ie)$tename]} )) || tbtn=0
1681
1747
  case $key in
1682
- $'\r'|$'\n') __tt_te_edit ;;
1748
+ $'\r'|$'\n')
1749
+ if (( tbtn )); then
1750
+ tearm=$armed
1751
+ __tt_te_resetting
1752
+ else
1753
+ __tt_te_edit
1754
+ fi
1755
+ ;;
1756
+ left|right) (( ${TTHEME_TUNED[(Ie)$tename]} )) && tbtn=$(( ! tbtn )) ;;
1683
1757
  s) __tt_te_save ;;
1684
- esc) __tt_te_close ;;
1758
+ esc) (( armed )) || __tt_te_close ;;
1685
1759
  up|k)
1686
1760
  if __tt_te_image; then
1687
1761
  __tt_te_to_image last
@@ -1769,7 +1843,7 @@ __tt_pv_te() {
1769
1843
  }
1770
1844
 
1771
1845
  __tt_pv_te_head() {
1772
- local z=$'\e[0m' d=$'\e[2m' b=$'\e[1m' y=$'\e[33m' line REPLY
1846
+ local z=$TTHEME_SGR[reset] d=$TTHEME_SGR[dim] b=$TTHEME_SGR[bold] y=$TTHEME_SGR[warn] line REPLY
1773
1847
  local -i col=$1 end=$2 room=$(( $2 - $1 + 1 ))
1774
1848
  (( color )) || z= d= b= y=
1775
1849
  __tt_te_unsaved && (( room -= 11 ))
@@ -1782,7 +1856,7 @@ __tt_pv_te_head() {
1782
1856
  }
1783
1857
 
1784
1858
  __tt_pv_te_tile() {
1785
- local z=$'\e[0m' d=$'\e[2m' b=$'\e[1m' sty top side bot
1859
+ local z=$TTHEME_SGR[reset] d=$TTHEME_SGR[dim] b=$TTHEME_SGR[bold] sty top side bot
1786
1860
  local -i y=$1 col=$2 r tc=10
1787
1861
  (( color )) || z= d= b=
1788
1862
  if (( tfocus == 1 && tf == 5 )); then
@@ -1804,7 +1878,7 @@ __tt_pv_te_tile() {
1804
1878
  }
1805
1879
 
1806
1880
  __tt_pv_te_ghost() {
1807
- local z=$'\e[0m' d=$'\e[2m'
1881
+ local z=$TTHEME_SGR[reset] d=$TTHEME_SGR[dim]
1808
1882
  local -i r0=$1 col=$2 T=$(( $3 - $2 - 21 )) i
1809
1883
  (( color )) || z= d=
1810
1884
  (( T < 8 )) && T=8
@@ -1819,7 +1893,7 @@ __tt_pv_te_ghost() {
1819
1893
  }
1820
1894
 
1821
1895
  __tt_pv_te_edge() {
1822
- local left=$4 right=$5 sty=$6 hs=$7 head=$8 tail=$9 z=$'\e[0m' line
1896
+ local left=$4 right=$5 sty=$6 hs=$7 head=$8 tail=$9 z=$TTHEME_SGR[reset] line
1823
1897
  local -i y=$1 col=$2 w=$3 n
1824
1898
  (( color )) || z=
1825
1899
  n=$(( w - 3 - (${#head} ? ${#head} + 2 : 0) - (${#tail} ? ${#tail} + 3 : 0) ))
@@ -1832,7 +1906,7 @@ __tt_pv_te_edge() {
1832
1906
  }
1833
1907
 
1834
1908
  __tt_pv_te_sides() {
1835
- local sty=$5 z=$'\e[0m'
1909
+ local sty=$5 z=$TTHEME_SGR[reset]
1836
1910
  local -i y r1=$2 col=$3 w=$4
1837
1911
  (( color )) || z=
1838
1912
  for (( y = $1; y <= r1; y++ )); do
@@ -1841,7 +1915,7 @@ __tt_pv_te_sides() {
1841
1915
  }
1842
1916
 
1843
1917
  __tt_pv_te_images() {
1844
- local z=$'\e[0m' d=$'\e[2m' b=$'\e[1m' st=" " tt note="0/0"
1918
+ local z=$TTHEME_SGR[reset] d=$TTHEME_SGR[dim] b=$TTHEME_SGR[bold] st=" " tt note="0/0"
1845
1919
  local -a held
1846
1920
  local -i y=$1 col=$2 end=$3 n
1847
1921
  (( color )) || z= d= b=
@@ -1858,23 +1932,37 @@ __tt_pv_te_images() {
1858
1932
  pvz+=("$y $col $end teimg")
1859
1933
  }
1860
1934
 
1861
- __tt_pv_te_editrow() {
1862
- local z=$'\e[0m' d=$'\e[2m' b=$'\e[1m' note="tunes its colors full screen"
1863
- local -i y=$1 col=$2 end=$3
1864
- (( color )) || z= d= b=
1865
- pvz+=("$y $col $end teedit")
1866
- out+=$'\e['$y';'$(( col + 2 ))'H'
1867
- if (( tfocus == 0 )); then
1868
- (( color )) && out+=$ac"▶"$z" "$'\e[7;1m'$ac" Edit palette "$z || out+="▶ [Edit palette]"
1935
+ __tt_pv_te_button() {
1936
+ if (( tfocus == 0 && tbtn == $1 )); then
1937
+ (( color )) && out+=$ac"▶"$z" "$pl" $2 "$z || out+="▶ [$2]"
1869
1938
  else
1870
- (( color )) && out+=" "$b" Edit palette "$z || out+=" Edit palette "
1939
+ (( color )) && out+=" "$b" $2 "$z || out+=" $2 "
1871
1940
  fi
1872
- (( ${#note} > end - col - 21 )) && note=${note[1,end-col-21]}
1873
- out+=" "$d$note$z
1941
+ }
1942
+
1943
+ __tt_pv_te_editrow() {
1944
+ local z=$TTHEME_SGR[reset] d=$TTHEME_SGR[dim] b=$TTHEME_SGR[bold] note="tunes its colors full screen"
1945
+ local -i y=$1 col=$2 end=$3 x=$(( $2 + 2 ))
1946
+ local reset="Reset palette"
1947
+ (( color )) || z= d= b=
1948
+ out+=$'\e['$y';'$x'H'
1949
+ __tt_pv_te_button 0 "Edit palette"
1950
+ pvz+=("$y $col $(( x + 15 )) teedit")
1951
+ x+=16
1952
+ if (( ${TTHEME_TUNED[(Ie)$tename]} )); then
1953
+ out+=" "
1954
+ (( tearm )) && reset="Reset? enter again"
1955
+ __tt_pv_te_button 1 "$reset"
1956
+ pvz+=("$y $(( x + 2 )) $(( x + ${#reset} + 5 )) tereset")
1957
+ x+=$(( ${#reset} + 6 ))
1958
+ (( tfocus == 0 && tbtn )) && note="back to its own colors"
1959
+ (( tearm )) && note="drops your tone"
1960
+ fi
1961
+ (( ${#note} <= end - x - 3 )) && out+=" "$d$note$z
1874
1962
  }
1875
1963
 
1876
1964
  __tt_pv_te_panel() {
1877
- local z=$'\e[0m' d=$'\e[2m' b=$'\e[1m' fs hs st note row REPLY
1965
+ local z=$TTHEME_SGR[reset] d=$TTHEME_SGR[dim] b=$TTHEME_SGR[bold] dx=$TTHEME_SGR[/dim] bx=$TTHEME_SGR[/bold] ax=$TTHEME_SGR[/accent] fs hs st note row REPLY
1878
1966
  local -i col=$1 end=$2 r0=$3 r1=$4 ix=$(( $1 + 2 )) ie=$(( $2 - 2 )) R W T P I=3 V i y pics=0 tfs=$tf
1879
1967
  (( color )) || z= d= b=
1880
1968
  R=$(( r1 - r0 + 1 )) W=$(( end - col + 1 ))
@@ -1941,8 +2029,8 @@ __tt_pv_te_panel() {
1941
2029
  else
1942
2030
  row=${teframe[i == P ? T : i]}
1943
2031
  if (( tfocus == 0 && color )); then
1944
- row=${${row//$'\e[2m'/$ac}//$'\e[22m'/$'\e[22;39m'}
1945
- (( i == 1 )) && row=${row/ Palette /$'\e[1m Palette \e[22m'}
2032
+ row=${${row//$d/$ac}//$dx/$bx$ax}
2033
+ (( i == 1 )) && row=${row/ Palette /$b" Palette "$bx}
1946
2034
  fi
1947
2035
  out+=$'\e['$y';'$col'H'$row$z
1948
2036
  pvz+=("$y $col $end tepal")
@@ -1960,7 +2048,7 @@ __tt_pv_te_panel() {
1960
2048
  fi
1961
2049
  out+=$'\e['$y';'$ix'H'
1962
2050
  if (( tfocus == 2 )); then
1963
- (( color )) && out+=$ac"▶"$z" "$'\e[7;1m'$ac" Apply "$z || out+="▶ [Apply]"
2051
+ (( color )) && out+=$ac"▶"$z" "$pl" Apply "$z || out+="▶ [Apply]"
1964
2052
  else
1965
2053
  (( color )) && out+=" "$b" Apply "$z || out+=" Apply "
1966
2054
  fi
@@ -2084,7 +2172,7 @@ __tt_pv_handle() {
2084
2172
  if (( cur <= 1 )); then
2085
2173
  (( ${#rval} )) && cur=${#rval}
2086
2174
  else
2087
- cur=$(( cur - ph + 5 ))
2175
+ cur=$(( cur - ph + pvhd + 3 ))
2088
2176
  (( cur < 1 )) && cur=1
2089
2177
  [[ ${rtype[cur]} == rule ]] && cur=$(( cur - 1 ))
2090
2178
  fi
@@ -2093,7 +2181,7 @@ __tt_pv_handle() {
2093
2181
  if (( cur >= ${#rval} )); then
2094
2182
  cur=1
2095
2183
  else
2096
- cur=$(( cur + ph - 5 ))
2184
+ cur=$(( cur + ph - pvhd - 3 ))
2097
2185
  (( cur > ${#rval} )) && cur=${#rval}
2098
2186
  [[ ${rtype[cur]} == rule ]] && cur=$(( cur + 1 ))
2099
2187
  fi
@@ -2148,7 +2236,7 @@ __tt_preview() {
2148
2236
  print -u2 "ttheme $mode: needs a terminal"
2149
2237
  return 1
2150
2238
  fi
2151
- 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
2239
+ 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 pvhd=2 pvsr=1 pvsc=4
2152
2240
  local pick="" pk=1 pkdef=1 picked=0 canpick=0 bgcw=0 bgch=0 bgname="" bgshown="" bginc="" osd="" osdt=0
2153
2241
  local tune="" tpick="" tf=1 help=0 msg="" msgt=0 an="" bgrel=0 bgmx=0 bgmy=0 bganchor=0 bgcut="" bgnext=0 bgbytes=0 bgstrip="" pvscene="" pvscenes=""
2154
2242
  local -i scene=0
@@ -2157,7 +2245,7 @@ __tt_preview() {
2157
2245
  local -A bgpic=() bgpics=() bgact=() bgview=() bgswap=() bgthumb=() tsnaps=() pvseek=() bgcolors=() bgprep=() TTHEME_ALIASES=()
2158
2246
  local conf=0 cf=1
2159
2247
  local -a plabel=(" Default " " This tab ") pkeys=() reach=() csnap=() teframe=()
2160
- local te=0 tfocus=0 tetop=0 tewide=0 tename=""
2248
+ local te=0 tfocus=0 tetop=0 tewide=0 tbtn=0 tearm=0 tename=""
2161
2249
  local -i pvgone=0 bgprepid=0 mrow=0 mcol=0 mclick=0 mwheel=0 mlwheel=0 mlrow=0 mlcol=0
2162
2250
  local -F mlast=0
2163
2251
  local mact="" mzone="" pvmouse=""