@kecan0406/ttheme 1.1.4 → 1.1.5

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
@@ -679,16 +679,45 @@ __tt_rotate() {
679
679
  __tt_announce
680
680
  }
681
681
 
682
+ __tt_pv_norm() { REPLY=${(L)1//[^[:alnum:]]/} }
683
+
684
+ __tt_pv_seek() {
685
+ local t part key REPLY
686
+ for t in ${(k)TTHEME_PALETTE}; do
687
+ key=""
688
+ for part in "$t" "${TTHEME_GROUP[$t]:-Other}" "${TTHEME_NATIVE[$t]}" "${TTHEME_CATALOG[$t]}" "${(@s:|:)TTHEME_NATIVE_NAMES[$t]}" "${TTHEME_CHARACTER[$t]}"; do
689
+ [[ -n $part ]] || continue
690
+ __tt_pv_norm "$part"
691
+ key+="|$REPLY"
692
+ done
693
+ pvseek[$t]=$key
694
+ done
695
+ }
696
+
697
+ __tt_pv_alias() {
698
+ REPLY=""
699
+ [[ -n $nflt && -n $2 ]] || return 0
700
+ local main
701
+ __tt_pv_norm "$1"
702
+ main=$REPLY
703
+ __tt_pv_norm "$2"
704
+ [[ $main != *$nflt* && $REPLY == *$nflt* ]] && REPLY=$2 || REPLY=""
705
+ return 0
706
+ }
707
+
682
708
  __tt_pv_rows() {
683
709
  rtype=() rval=() rcnt=()
684
- local g t c gm ruled=""
710
+ local g t c ruled="" nflt="" REPLY
685
711
  local -a ts cs loose inside
712
+ if [[ -n $flt ]]; then
713
+ (( ${#pvseek} )) || __tt_pv_seek
714
+ __tt_pv_norm "$flt"
715
+ nflt=$REPLY
716
+ fi
686
717
  for g in $groups; do
687
718
  ts=()
688
- gm=""
689
- [[ -n $flt && ${(L)g} == *$flt* ]] && gm=1
690
719
  for t in ${=gthemes[$g]}; do
691
- [[ -z $flt || -n $gm || $t == *$flt* || ${(L)TTHEME_CATALOG[$t]} == *$flt* ]] && ts+=($t)
720
+ [[ -z $flt || ${pvseek[$t]} == *$nflt* ]] && ts+=($t)
692
721
  done
693
722
  [[ -n $flt ]] && (( ! ${#ts} )) && continue
694
723
  if [[ $g == *@* && -z $ruled ]]; then
@@ -753,9 +782,16 @@ __tt_pv_goto() {
753
782
  cur=1
754
783
  }
755
784
 
785
+ __tt_pv_shows() {
786
+ REPLY=${bgview[$1]:-$1}
787
+ [[ -n $tune && $1 == "$tune" ]] && REPLY=$tpick
788
+ return 0
789
+ }
790
+
756
791
  __tt_pv_focus() {
757
792
  [[ ${rtype[cur]} == thm ]] || return 0
758
- (( resized )) || [[ ${rval[cur]} == "$bgname" ]] || __tt_pv_bg_show "${rval[cur]}"
793
+ __tt_pv_shows ${rval[cur]}
794
+ (( resized )) || [[ $REPLY == "$bgname" ]] || __tt_pv_bg_show "$REPLY"
759
795
  local spec=${TTHEME_PALETTE[${rval[cur]}]}
760
796
  [[ $spec == "$applied" ]] && return 0
761
797
  __tt_pv_paint "$spec"
@@ -854,8 +890,20 @@ __tt_pv_hl() {
854
890
  REPLY=${t[1,${#pre}]}$'\e[1;4m'$ac${t[${#pre}+1,${#pre}+${#flt}]}$'\e[22;24;39m'$2${t[${#pre}+${#flt}+1,-1]}
855
891
  }
856
892
 
893
+ __tt_pv_fit() {
894
+ local extra=$1
895
+ REPLY=""
896
+ [[ -n $extra ]] || return 0
897
+ while [[ -n $extra ]] && (( ${(m)#extra} + 3 > w )); do
898
+ extra=${extra[1,-2]}
899
+ done
900
+ [[ -n $extra ]] || return 0
901
+ (( w -= ${(m)#extra} + 2 ))
902
+ REPLY=" "$d$extra$r
903
+ }
904
+
857
905
  __tt_pv_row() {
858
- 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=" "
906
+ 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
859
907
  local -i w
860
908
  (( color )) || b= d= r= z= lead=
861
909
  if (( $1 == cur )); then
@@ -878,9 +926,13 @@ __tt_pv_row() {
878
926
  lead=""
879
927
  fi
880
928
  __tt_pv_hl "$name" "$base"
929
+ hl=$REPLY
881
930
  w=$(( lw - 6 - ${(m)#name} - ${#rcnt[$1]} ))
931
+ __tt_pv_alias "$t" "${TTHEME_NATIVE[${${=gthemes[$t]}[1]}]}"
932
+ __tt_pv_fit "$REPLY"
933
+ extra=$REPLY
882
934
  (( w < 1 )) && w=1
883
- REPLY=$gut$on" "$lead$arrow$r" "$base$REPLY$r${(l:w:: :)}$d${rcnt[$1]}$r" "$z
935
+ REPLY=$gut$on" "$lead$arrow$r" "$base$hl$r$extra${(l:w:: :)}$d${rcnt[$1]}$r" "$z
884
936
  return 0
885
937
  fi
886
938
  if [[ ${rtype[$1]} == cat ]]; then
@@ -907,16 +959,36 @@ __tt_pv_row() {
907
959
  name=${t##*/}
908
960
  [[ -n ${TTHEME_CATALOG[$t]} && ${TTHEME_GROUP[$t]} == *@* ]] && ind=" "
909
961
  __tt_pv_hl "$name" "$base"
962
+ hl=$REPLY
963
+ extra=""
964
+ for part in "${(@s:|:)TTHEME_NATIVE_NAMES[$t]}" "${TTHEME_CHARACTER[$t]}"; do
965
+ __tt_pv_alias "$name" "$part"
966
+ [[ -n $REPLY ]] && { extra=$REPLY; break }
967
+ done
910
968
  if (( color )); then
911
969
  [[ -n ${tstrip[$t]} ]] || __tt_pv_strip $t
912
970
  w=$(( lw - 16 - ${#ind} - ${#name} ))
971
+ __tt_pv_fit "$extra"
913
972
  (( w < 1 )) && w=1
914
- REPLY=$gut$on"$ind$mark $base$REPLY$r${(l:w:: :)}${tstrip[$t]} "$z
973
+ REPLY=$gut$on"$ind$mark $base$hl$r$REPLY${(l:w:: :)}${tstrip[$t]} "$z
915
974
  else
916
- REPLY="$gut$ind$mark $REPLY"
975
+ REPLY="$gut$ind$mark $hl${extra:+ $extra}"
917
976
  fi
918
977
  }
919
978
 
979
+ __tt_pv_bg_title() {
980
+ local by=${bgby[$tpick]} ref=${bgfrom[$tpick]} url=${bgurl[$tpick]} mark="" sgr=""
981
+ local -i room=$1
982
+ [[ -n $ref && $url == http(s|)://* && $TTHEME_ADAPTER == (ghostty|kitty|wezterm|alacritty|iterm2|windows-terminal|foot) ]] && mark="⧉ "
983
+ REPLY=Background${by:+ · $by}${ref:+ · $mark$ref}$2
984
+ (( ${#REPLY} > room )) && REPLY=Background${by:+ · $by}
985
+ (( ${#REPLY} > room )) && REPLY=Background
986
+ [[ -n $mark && $REPLY == *"$mark$ref"* ]] || return 0
987
+ (( color )) && [[ -n ${TTHEME_SITE_ANSI[${ref%% *}]} ]] && sgr=$'\e[3'${TTHEME_SITE_ANSI[${ref%% *}]}m
988
+ REPLY=${REPLY/"$mark$ref"/$sgr⧉${sgr:+$'\e[39m'} $'\e]8;;'$url$'\e\\'$ref$'\e]8;;\e\\'}
989
+ return 0
990
+ }
991
+
920
992
  __tt_pv_head() {
921
993
  local b=$'\e[1m' d=$'\e[2m' z=$'\e[0m' right=$6
922
994
  (( color )) || b= d= z=
@@ -958,14 +1030,14 @@ __tt_pv_foot() {
958
1030
  kk=(enter) kl=(confirm)
959
1031
  right=$b"esc"$z$d" back"$z
960
1032
  elif [[ -n $tune ]]; then
961
- badge=TUNE kk=(↑↓ ←→) kl=(field step)
1033
+ badge=TUNE kk=(↑↓ ←→ '=' +) kl=(field step reset "reset all")
962
1034
  if (( tf == 2 )); then
963
1035
  kl[2]=move kk+=(1-9) kl+=(place)
964
1036
  else
965
1037
  kk+=(⇧←→) kl+=(×10)
966
1038
  fi
967
- kk+=(space '=' enter)
968
- if (( bgoff[$tune] )); then kl+=(show default keep); else kl+=(hide default keep); fi
1039
+ kk+=(space enter)
1040
+ if (( bgoff[$tpick] )); then kl+=(show keep); else kl+=(hide keep); fi
969
1041
  __tt_pv_bg_images $tune
970
1042
  (( REPLY > 1 )) && { kk+=(', .' D); kl+=("image ×$REPLY" remove) }
971
1043
  __tt_pv_bg_findable $tune && { kk+=(f); kl+=(find) }
@@ -991,6 +1063,7 @@ __tt_pv_foot() {
991
1063
  elif __tt_pv_bg_findable ${rval[cur]}; then
992
1064
  kk+=(tab) kl+=("find bg")
993
1065
  fi
1066
+ (( split )) && { kk+=(⇧←→); kl+=(example) }
994
1067
  [[ -n $flt ]] && { kk+=(bksp); kl+=(edit) }
995
1068
  fi
996
1069
  kk+=('?') kl+=(keys)
@@ -1050,15 +1123,17 @@ __tt_pv_foot() {
1050
1123
  __tt_pv_help() {
1051
1124
  local back="the tab" z=$'\e[0m' b=$'\e[1m' blank
1052
1125
  [[ -n ${TTHEME_PALETTE[$cn]} ]] && back=$cn
1053
- local -a hk=(Move Series Filter Apply) hv=(
1126
+ local -a hk=(Move Series Filter "" Example Apply) hv=(
1054
1127
  "↑↓ home end pgup pgdn"
1055
1128
  "←→ · enter or space on a series"
1056
- "a-z 0-9 - · bksp · ctrl-u clears"
1129
+ "Any text · bksp · ctrl-u clears"
1130
+ "Names and titles, in Japanese too"
1131
+ "⇧←→ ${(Lj:, :)TTHEME_SCENES}"
1057
1132
  "enter · esc restores $back"
1058
1133
  )
1059
1134
  if (( bgcw )); then
1060
- hk+=("Tune bg" "" "" "" "")
1061
- hv+=("tab · finds one on the boorus, or takes your own, if none" "↑↓ field ←→ step ⇧←→ ×10 1-9 place" "space hides · = default · f adds one from the boorus or your own" "enter keeps · esc undoes" ", . other saved images · D removes this one")
1135
+ hk+=("Tune bg" "" "" "" "" "")
1136
+ hv+=("tab · finds one on the boorus, or takes your own, if none" "↑↓ field ←→ step ⇧←→ ×10 1-9 place" "= resets a field · + resets all" "space hides · enter keeps · esc undoes" ", . other pictures · D removes one" "f adds one from the boorus or your own")
1062
1137
  fi
1063
1138
  hk+=(Config "")
1064
1139
  hv+=("alt-c · ↑↓ setting ←→ value" "enter saves · esc undoes")
@@ -1090,45 +1165,82 @@ __tt_pv_help() {
1090
1165
  }
1091
1166
 
1092
1167
  __tt_pv_specimen() {
1093
- local -a sp=(${=applied}) ln=() fg=()
1168
+ local -a sp=(${=applied}) lines parts
1094
1169
  (( ${#sp} >= 20 )) || return 0
1095
- local z=$'\e[0m' d=$'\e[2m' sel cu cell line="" lo hi pr bd
1096
- local -i i r cw=4
1170
+ local z=$'\e[0m' d=$'\e[2m' cell hex fore line text piece role tabs="" built="" key="$applied|$painted|$scene|$sw|$sc|$ph"
1171
+ local -A rs=(p "" d $'\e[2m' b $'\e[1m')
1172
+ local -i i r=6 cw=4 k n=${#TTHEME_SCENES} at
1173
+ (( n )) || return 0
1174
+ if [[ $key == "$pvscene" ]]; then
1175
+ out+=$pvscenes
1176
+ return 0
1177
+ fi
1178
+ at=$(( (scene % n + n) % n + 1 ))
1097
1179
  if [[ $applied == "$painted" ]]; then
1098
- fg=($'\e[31m' $'\e[32m' $'\e[33m' $'\e[34m' $'\e[35m') bd=$'\e[1;34m'
1180
+ for (( i = 0; i < 16; i++ )); do
1181
+ k=$(( i < 8 ? 30 + i : 82 + i ))
1182
+ rs[$i]=$'\e['$k'm' rs[B$i]=$'\e[1;'$k'm' rs[K$i]=$'\e[30;'$(( k + 10 ))'m'
1183
+ done
1099
1184
  else
1100
- for i in 6 7 8 9 10 17; do
1101
- lo=${sp[i]#\#}
1102
- printf -v cell '\e[38;2;%d;%d;%dm' $((16#${lo:0:2})) $((16#${lo:2:2})) $((16#${lo:4:2}))
1103
- fg+=($cell)
1185
+ fore=${sp[5]#\#}
1186
+ for (( i = 0; i < 16; i++ )); do
1187
+ hex=${sp[i+5]#\#}
1188
+ printf -v cell '\e[38;2;%d;%d;%dm' $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2}))
1189
+ rs[$i]=$cell
1190
+ printf -v cell '\e[38;2;%d;%d;%d;48;2;%d;%d;%dm' $((16#${fore:0:2})) $((16#${fore:2:2})) $((16#${fore:4:2})) \
1191
+ $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2}))
1192
+ rs[K$i]=$cell
1193
+ hex=${sp[(i < 8 ? i + 13 : i + 5)]#\#}
1194
+ printf -v cell '\e[1;38;2;%d;%d;%dm' $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2}))
1195
+ rs[B$i]=$cell
1196
+ done
1197
+ fi
1198
+ printf -v cell '\e[48;2;%d;%d;%dm' $((16#${sp[4]:1:2})) $((16#${sp[4]:3:2})) $((16#${sp[4]:5:2}))
1199
+ rs[s]=$cell
1200
+ printf -v cell '\e[48;2;%d;%d;%dm' $((16#${sp[3]:1:2})) $((16#${sp[3]:3:2})) $((16#${sp[3]:5:2}))
1201
+ rs[c]=$cell
1202
+ if (( ${#${(j: :)TTHEME_SCENES}} <= sw )); then
1203
+ for (( k = 1; k <= n; k++ )); do
1204
+ (( k > 1 )) && tabs+=" "
1205
+ if (( k == at )); then
1206
+ tabs+=$'\e[1m'$ac$TTHEME_SCENES[k]$z
1207
+ else
1208
+ tabs+=$d$TTHEME_SCENES[k]$z
1209
+ fi
1104
1210
  done
1105
- bd=$'\e[1m'$fg[6]
1211
+ else
1212
+ tabs=$'\e[1m'$ac$TTHEME_SCENES[at]$z" "$d"$at/$n"$z
1106
1213
  fi
1107
- pr=$fg[2]'❯'$z' '
1214
+ built+=$'\e[2;'$sc'H'$tabs
1108
1215
  (( sw < 44 )) && cw=3
1109
1216
  (( sw >= 56 )) && cw=$(( (sw + 1) / 8 - 1 ))
1110
1217
  (( cw > 7 )) && cw=7
1111
- printf -v sel '\e[48;2;%d;%d;%dm' $((16#${sp[4]:1:2})) $((16#${sp[4]:3:2})) $((16#${sp[4]:5:2}))
1112
- printf -v cu '\e[48;2;%d;%d;%dm' $((16#${sp[3]:1:2})) $((16#${sp[3]:3:2})) $((16#${sp[3]:5:2}))
1218
+ line=""
1113
1219
  for (( i = 0; i < 8; i++ )); do
1114
- lo=${sp[i+5]#\#} hi=${sp[i+13]#\#}
1220
+ fore=${sp[i+5]#\#} hex=${sp[i+13]#\#}
1115
1221
  printf -v cell '\e[38;2;%d;%d;%d;48;2;%d;%d;%dm%s\e[0m ' \
1116
- $((16#${lo:0:2})) $((16#${lo:2:2})) $((16#${lo:4:2})) \
1117
- $((16#${hi:0:2})) $((16#${hi:2:2})) $((16#${hi:4:2})) "${(l:cw::▀:)}"
1222
+ $((16#${fore:0:2})) $((16#${fore:2:2})) $((16#${fore:4:2})) \
1223
+ $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2})) "${(l:cw::▀:)}"
1118
1224
  line+=$cell
1119
1225
  done
1120
- out+=$'\e[4;'$sc'H'$line
1121
- ln=($bd'~/code/demo'$z$d' on '$z$fg[5]'main'$fg[2]' +2'$fg[3]' ~1'$z "${pr}git status -sb")
1122
- (( sw >= 44 )) && ln+=('## '$fg[2]'main'$z'...'$fg[1]'origin/main'$fg[3]' [ahead 1]'$z)
1123
- ln+=($fg[1]' M'$z' src/main.rs' $fg[1]'??'$z' notes.md' "")
1124
- (( sw >= 44 )) && ln+=("${pr}ls" $bd'docs'$z' '$bd'src'$z' '$bd'tests'$z' Cargo.toml README.md' "")
1125
- ln+=("${pr}cargo test" $fg[2]' ✓'$z' parses config' $fg[1]' ✗'$z' renders frame')
1126
- (( sw >= 44 )) && ln[-1]+=$d' expected '$z$fg[2]'3'$z$d', received '$z$fg[1]'2'$z
1127
- ln+=("" "${pr}echo ${sel}selected text${z} ${cu} ${z}")
1128
- for (( r = 1; r <= ${#ln}; r++ )); do
1129
- (( r + 5 < ph )) || break
1130
- out+=$'\e['$(( r + 5 ))';'$sc'H'${ln[r]}
1226
+ built+=$'\e[4;'$sc'H'$line
1227
+ lines=("${(@P)${:-TTHEME_SCENE_$at}}")
1228
+ for line in "${lines[@]}"; do
1229
+ [[ $line == «w»* ]] && (( sw < 44 )) && continue
1230
+ [[ $line == «n»* ]] && (( sw >= 44 )) && continue
1231
+ (( r < ph )) || break
1232
+ parts=("${(@s:«:)line}")
1233
+ text=$parts[1]
1234
+ for piece in "${(@)parts[2,-1]}"; do
1235
+ role=${piece%%»*}
1236
+ [[ $role == [wn] ]] && role=p
1237
+ text+=$z${rs[${role:-p}]}${piece#*»}
1238
+ done
1239
+ built+=$'\e['$r';'$sc'H'$text$z
1240
+ (( ++r ))
1131
1241
  done
1242
+ pvscene=$key pvscenes=$built
1243
+ out+=$built
1132
1244
  }
1133
1245
 
1134
1246
  __tt_pv_tune() {
@@ -1137,8 +1249,8 @@ __tt_pv_tune() {
1137
1249
  local name
1138
1250
  case $key in
1139
1251
  $'\x03') return 1 ;;
1140
- up) (( tf > 1 )) && tf=$(( tf - 1 )) ;;
1141
- down) (( tf < 3 )) && tf=$(( tf + 1 )) ;;
1252
+ up) tf=$(( tf > 1 ? tf - 1 : 3 )) ;;
1253
+ down) tf=$(( tf < 3 ? tf + 1 : 1 )) ;;
1142
1254
  left|right|sleft|sright)
1143
1255
  [[ $key == *left ]] && n=-1
1144
1256
  [[ $key == s* ]] && (( tf != 2 )) && n=$(( n * 10 ))
@@ -1149,32 +1261,54 @@ __tt_pv_tune() {
1149
1261
  __tt_pv_bg_adjust at $key
1150
1262
  ;;
1151
1263
  ' ') __tt_pv_bg_adjust on ;;
1152
- '=') __tt_pv_bg_adjust def ;;
1153
- ',') __tt_pv_bg_image prev ;;
1154
- '.') __tt_pv_bg_image next ;;
1155
- D) __tt_pv_bg_image drop ;;
1264
+ '=') __tt_pv_bg_adjust def $tf ;;
1265
+ '+') __tt_pv_bg_adjust def ;;
1266
+ ',') __tt_pv_bg_pick -1 ;;
1267
+ '.') __tt_pv_bg_pick 1 ;;
1268
+ D) __tt_pv_bg_drop ;;
1156
1269
  f)
1157
1270
  __tt_pv_bg_findable $tune || return 0
1158
1271
  name=$tune
1159
1272
  __tt_pv_untune
1160
1273
  __tt_pv_bg_find $name
1161
- tune=$name tf=1 tsnap="${bgsize[$name]} ${bgpos[$name]} ${bgop[$name]} ${bgoff[$name]}"
1162
- ;;
1163
- $'\r'|$'\n')
1164
- if [[ "${bgsize[$tune]} ${bgpos[$tune]} ${bgop[$tune]} ${bgoff[$tune]}" != "$tsnap" ]]; then
1165
- bgedit[$tune]=1 msg="Kept · saved when preview closes" msgt=200
1166
- fi
1167
- tune=""
1274
+ __tt_pv_tune_open $name
1168
1275
  ;;
1276
+ $'\r'|$'\n') __tt_pv_tune_keep ;;
1169
1277
  esc) __tt_pv_untune ;;
1170
1278
  '?') help=1 ;;
1171
1279
  esac
1172
1280
  return 0
1173
1281
  }
1174
1282
 
1283
+ __tt_pv_tune_keep() {
1284
+ local img was=${bgview[$tune]:-$tune}
1285
+ local -i changed=0
1286
+ for img in ${(k)tsnaps}; do
1287
+ [[ "${bgsize[$img]} ${bgpos[$img]} ${bgop[$img]} ${bgoff[$img]}" == "${tsnaps[$img]}" ]] && continue
1288
+ bgedit[$img]=1 changed=1
1289
+ done
1290
+ if [[ $tpick != "$was" ]]; then
1291
+ changed=1
1292
+ if [[ $tpick == "$tune" ]]; then
1293
+ unset "bgview[$tune]" "bgswap[$tune]"
1294
+ else
1295
+ bgview[$tune]=$tpick bgswap[$tune]=${tpick##*:}
1296
+ fi
1297
+ fi
1298
+ (( changed )) && msg="Kept · saved when preview closes" msgt=200
1299
+ __tt_pv_bg_strip_off
1300
+ tune="" tpick="" tsnaps=() bgname=""
1301
+ }
1302
+
1175
1303
  __tt_pv_untune() {
1176
- local -a s=(${=tsnap})
1177
- bgsize[$tune]=$s[1] bgpos[$tune]=$s[2] bgop[$tune]=$s[3] bgoff[$tune]=$s[4] bgname="" tune=""
1304
+ local img
1305
+ local -a s
1306
+ for img in ${(k)tsnaps}; do
1307
+ s=(${=tsnaps[$img]})
1308
+ bgsize[$img]=$s[1] bgpos[$img]=$s[2] bgop[$img]=$s[3] bgoff[$img]=$s[4]
1309
+ done
1310
+ __tt_pv_bg_strip_off
1311
+ tune="" tpick="" tsnaps=() bgname=""
1178
1312
  }
1179
1313
 
1180
1314
  __tt_pv_regroup() {
@@ -1190,8 +1324,8 @@ __tt_pv_regroup() {
1190
1324
  __tt_pv_conf() {
1191
1325
  case $key in
1192
1326
  $'\x03') return 1 ;;
1193
- up) (( cf > 1 )) && cf=$(( cf - 1 )) ;;
1194
- down) (( cf < ${#cvars} )) && cf=$(( cf + 1 )) ;;
1327
+ up) cf=$(( cf > 1 ? cf - 1 : ${#cvars} )) ;;
1328
+ down) cf=$(( cf < ${#cvars} ? cf + 1 : 1 )) ;;
1195
1329
  left|sleft) __tt_pv_conf_step -1 ;;
1196
1330
  right|sright) __tt_pv_conf_step 1 ;;
1197
1331
  $'\r'|$'\n') __tt_pv_conf_save ;;
@@ -1318,18 +1452,33 @@ __tt_pv_conf_panel() {
1318
1452
  }
1319
1453
 
1320
1454
  __tt_pv_flush() {
1455
+ local REPLY
1321
1456
  print -rn -- "$out"
1322
1457
  if (( wiped )); then
1323
1458
  local bn=$bgname
1324
- [[ ${rtype[cur]} == thm ]] && bn=${rval[cur]}
1459
+ if [[ ${rtype[cur]} == thm ]]; then
1460
+ __tt_pv_shows ${rval[cur]}
1461
+ bn=$REPLY
1462
+ fi
1325
1463
  [[ -n $bn ]] && __tt_pv_bg_show "$bn" 1
1326
1464
  fi
1327
- printf '\e[?2026l'
1465
+ if [[ -n $bgstrip ]]; then
1466
+ __tt_pv_bg_strip ${=bgstrip}
1467
+ elif (( ${#bgthumb} )); then
1468
+ __tt_pv_bg_strip_off
1469
+ fi
1470
+ printf '\e[1;%dH\e[?2026l' $(( 4 + ${(m)#flt} ))
1328
1471
  }
1329
1472
 
1330
1473
  __tt_pv_draw() {
1331
- local out line cnt ex ag="" acat="" ac="" sb="" dd="" zz="" state=on src="" REPLY
1474
+ local out line cnt ex ag="" acat="" ac="" sb="" dd="" zz="" state=on src="" nflt="" REPLY
1332
1475
  local -i lw sw split sc se=$(( pw - 2 )) h k i N=${#rval} mt=${#TTHEME_ORDER} wiped=0
1476
+ local -a pk
1477
+ bgstrip=""
1478
+ if [[ -n $flt ]]; then
1479
+ __tt_pv_norm "$flt"
1480
+ nflt=$REPLY
1481
+ fi
1333
1482
  __tt_pv_lw
1334
1483
  lw=$reply[1] sw=$reply[2]
1335
1484
  split=$(( sw > 0 )) sc=$(( pw - 1 - sw ))
@@ -1407,7 +1556,7 @@ __tt_pv_draw() {
1407
1556
  [[ -n $flt ]] && tail=$'\e['$(( lw - ${#cnt} ))'G'$cnt
1408
1557
  if [[ $1 == hint ]] && (( ! wiped )); then
1409
1558
  print -rn -- $'\e[H\e[0m\e['$lw'X'$line$tail
1410
- printf '\e[?2026l'
1559
+ printf '\e[1;%dH\e[?2026l' $(( 4 + ${(m)#flt} ))
1411
1560
  return 0
1412
1561
  fi
1413
1562
  out+=$line$'\e[K'$tail$'\n\e[K\n'
@@ -1434,12 +1583,10 @@ __tt_pv_draw() {
1434
1583
  __tt_pv_head 1 $sc $se Keys
1435
1584
  __tt_pv_help
1436
1585
  elif [[ -n $tune ]]; then
1437
- (( bgoff[$tune] )) && state=off
1438
- src=Background
1439
- [[ -n ${bgfrom[$tune]} ]] && src+=" · ${bgfrom[$tune]}"
1440
- (( ${#tune} + ${#src} + 6 > sw )) && src=Background
1441
- __tt_pv_head 1 $sc $se $tune "$src" $state
1442
- __tt_pv_bg_panel $tune 4 $sc $se
1586
+ (( bgoff[$tpick] )) && state=off
1587
+ __tt_pv_bg_title $(( sw - ${#tune} - 6 ))
1588
+ __tt_pv_head 1 $sc $se $tune "$REPLY" $state
1589
+ __tt_pv_bg_panel $tpick 4 $sc $se
1443
1590
  elif (( conf )); then
1444
1591
  __tt_tilde "$TTHEME_CONFIG"
1445
1592
  src=$REPLY
@@ -1455,12 +1602,17 @@ __tt_pv_draw() {
1455
1602
  (( help && sw < 48 )) && __tt_pv_help
1456
1603
  else
1457
1604
  if [[ -n $tune ]]; then
1458
- (( bgoff[$tune] )) && state=off
1459
- src=Background
1460
- [[ -n ${bgfrom[$tune]} ]] && src+=" · ${bgfrom[$tune]}"
1461
- (( ${#tune} + ${#src} + 6 > lw )) && src=Background
1462
- __tt_pv_head $(( ph - 9 )) 1 $lw $tune "$src" $state
1463
- __tt_pv_bg_panel $tune $(( ph - 8 )) 1 $lw
1605
+ (( bgoff[$tpick] )) && state=off
1606
+ pk=(${=bgpics[$tune]})
1607
+ src=""
1608
+ if (( ${#pk} > 1 )); then
1609
+ k=${pk[(Ie)${${tpick#$tune}#:}]}
1610
+ (( k )) || k=${pk[(Ie)${bgact[$tune]}]}
1611
+ src=" · $k/${#pk}"
1612
+ fi
1613
+ __tt_pv_bg_title $(( lw - ${#tune} - 6 )) "$src"
1614
+ __tt_pv_head $(( ph - 9 )) 1 $lw $tune "$REPLY" $state
1615
+ __tt_pv_bg_panel $tpick $(( ph - 8 )) 1 $lw
1464
1616
  elif (( conf )); then
1465
1617
  __tt_pv_head $(( ph - 7 )) 1 $lw Config
1466
1618
  __tt_pv_conf_panel $(( ph - 6 )) 1 $lw
@@ -1594,6 +1746,7 @@ __tt_pv_read() {
1594
1746
  "6~") key=pgdn ;;
1595
1747
  "1;2C") key=sright ;;
1596
1748
  "1;2D") key=sleft ;;
1749
+ Z) key=stab ;;
1597
1750
  *) key=nop ;;
1598
1751
  esac
1599
1752
  }
@@ -1602,7 +1755,7 @@ __tt_pv_pick() {
1602
1755
  case $key in
1603
1756
  $'\x03') return 1 ;;
1604
1757
  esc) pick="" ;;
1605
- left|right|$'\t') pk=$(( 3 - pk )) ;;
1758
+ left|right|$'\t'|stab) pk=$(( 3 - pk )) ;;
1606
1759
  $'\r'|$'\n')
1607
1760
  sel=$pick picked=$pk
1608
1761
  return 1
@@ -1662,29 +1815,50 @@ __tt_pv_handle() {
1662
1815
  __tt_pv_toggle
1663
1816
  fi
1664
1817
  ;;
1665
- up) (( cur > 1 )) && cur=$(( cur - 1 )); [[ ${rtype[cur]} == rule ]] && cur=$(( cur - 1 )) ;;
1666
- down) (( cur < ${#rval} )) && cur=$(( cur + 1 )); [[ ${rtype[cur]} == rule ]] && cur=$(( cur + 1 )) ;;
1818
+ up)
1819
+ if (( cur > 1 )); then
1820
+ cur=$(( cur - 1 ))
1821
+ [[ ${rtype[cur]} == rule ]] && cur=$(( cur - 1 ))
1822
+ elif (( ${#rval} )); then
1823
+ cur=${#rval}
1824
+ fi
1825
+ ;;
1826
+ down)
1827
+ if (( cur < ${#rval} )); then
1828
+ cur=$(( cur + 1 ))
1829
+ [[ ${rtype[cur]} == rule ]] && cur=$(( cur + 1 ))
1830
+ elif (( ${#rval} )); then
1831
+ cur=1
1832
+ fi
1833
+ ;;
1667
1834
  right) [[ ${rtype[cur]} == (hdr|cat) && -z ${exp[${rval[cur]}]} ]] && __tt_pv_toggle ;;
1668
1835
  left) __tt_pv_left ;;
1669
1836
  home) cur=1 ;;
1670
1837
  end) (( ${#rval} )) && cur=${#rval} ;;
1671
1838
  pgup)
1672
- cur=$(( cur - ph + 5 ))
1673
- (( cur < 1 )) && cur=1
1674
- [[ ${rtype[cur]} == rule ]] && cur=$(( cur - 1 ))
1839
+ if (( cur <= 1 )); then
1840
+ (( ${#rval} )) && cur=${#rval}
1841
+ else
1842
+ cur=$(( cur - ph + 5 ))
1843
+ (( cur < 1 )) && cur=1
1844
+ [[ ${rtype[cur]} == rule ]] && cur=$(( cur - 1 ))
1845
+ fi
1675
1846
  ;;
1676
1847
  pgdn)
1677
- cur=$(( cur + ph - 5 ))
1678
- (( cur > ${#rval} )) && cur=${#rval}
1679
- (( cur < 1 )) && cur=1
1680
- [[ ${rtype[cur]} == rule ]] && cur=$(( cur + 1 ))
1848
+ if (( cur >= ${#rval} )); then
1849
+ cur=1
1850
+ else
1851
+ cur=$(( cur + ph - 5 ))
1852
+ (( cur > ${#rval} )) && cur=${#rval}
1853
+ [[ ${rtype[cur]} == rule ]] && cur=$(( cur + 1 ))
1854
+ fi
1681
1855
  ;;
1682
1856
  ' ') [[ ${rtype[cur]} == (hdr|cat) ]] && __tt_pv_toggle ;;
1683
1857
  $'\t')
1684
1858
  [[ ${rtype[cur]} == thm ]] || return 0
1685
1859
  name=${rval[cur]}
1686
1860
  if __tt_pv_bg_state $name || { __tt_pv_bg_findable $name && __tt_pv_bg_find $name }; then
1687
- tune=$name tf=1 tsnap="${bgsize[$name]} ${bgpos[$name]} ${bgop[$name]} ${bgoff[$name]}"
1861
+ __tt_pv_tune_open $name
1688
1862
  elif __tt_pv_bg_findable $name; then
1689
1863
  :
1690
1864
  elif (( bgcw )); then
@@ -1698,6 +1872,8 @@ __tt_pv_handle() {
1698
1872
  done
1699
1873
  ;;
1700
1874
  '?') help=1 ;;
1875
+ sleft) (( --scene )) ;;
1876
+ sright) (( ++scene )) ;;
1701
1877
  $'\x7f'|$'\x08')
1702
1878
  if [[ -n $flt ]]; then
1703
1879
  name=""
@@ -1707,9 +1883,9 @@ __tt_pv_handle() {
1707
1883
  __tt_pv_first "$name"
1708
1884
  fi
1709
1885
  ;;
1710
- [a-zA-Z0-9-])
1886
+ [[:print:]])
1711
1887
  __tt_pv_lw
1712
- (( ${#flt} >= reply[1] - 12 )) && return 0
1888
+ (( ${(m)#flt} + ${(m)#key} > reply[1] - 12 )) && return 0
1713
1889
  name=""
1714
1890
  [[ ${rtype[cur]} == thm ]] && name=${rval[cur]}
1715
1891
  flt+=${(L)key}
@@ -1729,9 +1905,11 @@ __tt_preview() {
1729
1905
  fi
1730
1906
  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
1731
1907
  local pick="" pk=1 pkdef=1 picked=0 canpick=0 bgcw=0 bgch=0 bgname="" bgshown="" bginc="" osd="" osdt=0
1732
- local tune="" tsnap="" tf=1 help=0 msg="" msgt=0 an="" bgrel=0 bgmx=0 bgmy=0 bganchor=0 bgcut="" bgnext=0 bgbytes=0
1908
+ 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=""
1909
+ local -i scene=0
1733
1910
  local -a bgorder=()
1734
- local -A bgfrom=() bgsent=() bgcost=() bgdim=() bgsrc=() bgfill=() bgfocus=() bgsize=() bgpos=() bgop=() bgdef=() bgoff=() bgbase=() bgload=() bgshot=() bgshotkey=() bgedit=() bgtunef=() bgofff=() bgimages=()
1911
+ local -A bgfrom=() bgurl=() bgby=() bgsent=() bgcost=() bgdim=() bgsrc=() bgfill=() bgfocus=() bgsize=() bgpos=() bgop=() bgdef=() bgoff=() bgbase=() bgload=() bgshot=() bgshotkey=() bgedit=() bgtunef=() bgofff=() bgimages=()
1912
+ local -A bgpic=() bgpics=() bgact=() bgview=() bgswap=() bgthumb=() tsnaps=() pvseek=()
1735
1913
  local conf=0 cf=1
1736
1914
  local -a plabel=(" This tab " " Default ") csnap=()
1737
1915
  local -a cvars=(TTHEME_TAB_PALETTE TTHEME_ANNOUNCE TTHEME_FX TTHEME_SORT TTHEME_BG_BLUR) clabel=("New tabs" Announce "Search fx" Sort Blur)
@@ -1815,7 +1993,7 @@ __tt_preview() {
1815
1993
  __tt_shown "$sel" force && __tt_reload
1816
1994
  fi
1817
1995
  else
1818
- (( ${#bgedit} )) && [[ -n ${TTHEME_PALETTE[$cn]} ]] && { __tt_shown "$cn" && __tt_reload }
1996
+ (( ${#bgedit} + ${#bgswap} )) && [[ -n ${TTHEME_PALETTE[$cn]} ]] && { __tt_shown "$cn" && __tt_reload }
1819
1997
  fi
1820
1998
  }
1821
1999
  return 0