@kecan0406/ttheme 1.2.9 → 1.2.10

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
@@ -4,7 +4,7 @@ __tt_pv_seek() {
4
4
  local t part key REPLY
5
5
  for t in ${(k)TTHEME_PALETTE}; do
6
6
  key=""
7
- for part in "$t" "${TTHEME_GROUP[$t]:-Other}" "${TTHEME_NATIVE[$t]}" "${TTHEME_CATALOG[$t]}" "${(@s:|:)TTHEME_NATIVE_NAMES[$t]}" "${TTHEME_CHARACTER[$t]}"; do
7
+ for part in "$t" "${TTHEME_GROUP[$t]:-Other}" "${TTHEME_NATIVE[$t]}" "${TTHEME_CATALOG[$t]}" "${(@s:|:)TTHEME_NATIVE_NAMES[$t]}" "${TTHEME_CHARACTER[$t]}" "${(@s:|:)TTHEME_ALIASES[$t]}"; do
8
8
  [[ -n $part ]] || continue
9
9
  __tt_pv_norm "$part"
10
10
  key+="|$REPLY"
@@ -110,7 +110,10 @@ __tt_pv_shows() {
110
110
  __tt_pv_focus() {
111
111
  if (( te )); then
112
112
  __tt_pv_shows $tename
113
- (( resized )) || [[ $REPLY == "$bgname" ]] || __tt_pv_bg_show "$REPLY"
113
+ if (( ! resized )) && [[ $REPLY != "$bgname" || "${tespec%% *} ${teframe[11]}" != "$telook" ]]; then
114
+ __tt_pv_bg_show "$REPLY"
115
+ telook="${tespec%% *} ${teframe[11]}"
116
+ fi
114
117
  return 0
115
118
  fi
116
119
  [[ ${rtype[cur]} == thm ]] || return 0
@@ -290,7 +293,7 @@ __tt_pv_row() {
290
293
  __tt_pv_hl "$name" "$base"
291
294
  hl=$REPLY
292
295
  extra=""
293
- for part in "${(@s:|:)TTHEME_NATIVE_NAMES[$t]}" "${TTHEME_CHARACTER[$t]}"; do
296
+ for part in "${(@s:|:)TTHEME_NATIVE_NAMES[$t]}" "${TTHEME_CHARACTER[$t]}" "${(@s:|:)TTHEME_ALIASES[$t]}"; do
294
297
  __tt_pv_alias "$name" "$part"
295
298
  [[ -n $REPLY ]] && { extra=$REPLY; break }
296
299
  done
@@ -308,7 +311,7 @@ __tt_pv_row() {
308
311
  __tt_pv_bg_title() {
309
312
  local by=${bgby[$tpick]} ref=${bgfrom[$tpick]} url=${bgurl[$tpick]} mark="" sgr=""
310
313
  local -i room=$1
311
- [[ -n $ref && $url == http(s|)://* ]] && (( ${TTHEME_LINKS[(Ie)$TTHEME_ADAPTER]} )) && mark="⧉ "
314
+ [[ -n $ref && $url == http(s|)://* ]] && __tt_links && mark="⧉ "
312
315
  REPLY=Background${by:+ · $by}${ref:+ · $mark$ref}$2
313
316
  (( ${#REPLY} > room )) && REPLY=Background${by:+ · $by}
314
317
  (( ${#REPLY} > room )) && REPLY=Background
@@ -326,9 +329,12 @@ __tt_pv_bar() {
326
329
  for title in $TTHEME_HUB_TITLES; do
327
330
  (( len += ${#title} + 2 ))
328
331
  done
332
+ local -i zc=2
329
333
  for (( i = 1; i <= ${#TTHEME_HUB_TITLES}; i++ )); do
330
334
  title=${TTHEME_HUB_TITLES[i]}
331
- (( i > 1 )) && line+=" "
335
+ (( i > 1 )) && { line+=" "; (( zc++ )) }
336
+ pvz+=("1 $zc $(( zc + ${(m)#title} + 1 )) hub $i")
337
+ (( zc += ${(m)#title} + 2 ))
332
338
  if (( i != at )); then
333
339
  line+=$d" $title "$z
334
340
  elif (( color )); then
@@ -395,9 +401,11 @@ __tt_pv_foot() {
395
401
  if [[ $temode == list ]]; then
396
402
  kk=("${kk[1]}" s "${(@)kk[2,-1]}" ⇧enter) kl=("${kl[1]}" save "${(@)kl[2,-1]}" apply)
397
403
  elif [[ $temode == tune ]]; then
398
- right=$b"esc"$z$d" undo"$z
399
- elif [[ $temode == (type|compare) ]]; then
400
- right=$b"esc"$z$d" back"$z
404
+ badge="$tb (TUNE)" right=$b"esc"$z$d" undo"$z
405
+ elif [[ $temode == type ]]; then
406
+ badge="$tb (TYPE)" right=$b"esc"$z$d" back"$z
407
+ elif [[ $temode == compare ]]; then
408
+ badge="$tb (BEFORE)" right=$b"esc"$z$d" back"$z
401
409
  fi
402
410
  elif (( te && tfocus == 2 )); then
403
411
  badge=$tb kk=(enter ↑↓ s) kl=(apply move save)
@@ -498,6 +506,29 @@ __tt_pv_foot() {
498
506
  done
499
507
  out+=$line$'\e[K'
500
508
  [[ -n $right ]] && out+=$'\e['$(( end - rwid + 1 ))'G'$right
509
+ local -i zc=1 zw
510
+ [[ -n $badge ]] && (( zc += ${(m)#badge} + (color ? 4 : 3) ))
511
+ if [[ -n $lead ]]; then
512
+ if [[ -n $pick ]]; then
513
+ zw=$(( zc + ${(m)#pick} + 2 ))
514
+ for (( i = 1; i <= ${#plabel}; i++ )); do
515
+ pvz+=("$ph $(( zw + 1 )) $(( zw + ${(m)#plabel[i]} )) pick $i")
516
+ (( zw += ${(m)#plabel[i]} + 1 ))
517
+ done
518
+ fi
519
+ plain=${lead//$'\e'\[[0-9;]##m/}
520
+ (( zc += ${(m)#plain} + 3 ))
521
+ fi
522
+ [[ -n $note ]] && (( zc += ${(m)#note} + 3 ))
523
+ for (( i = 1; i <= ${#kk}; i++ )); do
524
+ zw=$(( ${(m)#kk[i]} + 1 + ${(m)#kl[i]} ))
525
+ pvz+=("$ph $zc $(( zc + zw - 1 )) key ${kk[i]}")
526
+ (( zc += zw + 3 ))
527
+ done
528
+ if [[ -n $right ]]; then
529
+ plain=${right//$'\e'\[[0-9;]##m/}
530
+ pvz+=("$ph $(( end - rwid + 1 )) $end key ${plain%% *}")
531
+ fi
501
532
  return 0
502
533
  }
503
534
 
@@ -506,7 +537,7 @@ __tt_pv_help() {
506
537
  [[ -n ${TTHEME_PALETTE[$cn]} ]] && back=$cn
507
538
  local -a hk=() hv=()
508
539
  if (( te )); then
509
- hk=(Move Image "" "" "" Palette "" "" "" Apply Save Cancel)
540
+ hk=(Move Image "" "" "" Palette "" "" "" "" "" Apply Save Cancel)
510
541
  hv=(
511
542
  "↑↓ j k the image, the palette, then Apply · home end"
512
543
  "Images ←→ , . pick one · D removes it · f finds one"
@@ -514,6 +545,8 @@ __tt_pv_help() {
514
545
  "←→ step ⇧←→ ×10 1-9 place · = resets · + all"
515
546
  "space hides · c colors"
516
547
  "←→ normal or bright · enter tab tune it · # a color"
548
+ "tuning: ↑↓ L C H ◐ · ◐ home the floor · a scope"
549
+ "g relations · n N the next and last miss"
517
550
  "r resets a slot · R all · space the colors before"
518
551
  "c copies · v pastes · = bright follows normal"
519
552
  "f moves the colors the gate misses · u undo"
@@ -750,9 +783,20 @@ __tt_pv_conf_put() {
750
783
  TTHEME_SORT) __tt_pv_regroup ;;
751
784
  TTHEME_FX) [[ -n $flt ]] || { __tt_pv_roll; gstep=8 } ;;
752
785
  TTHEME_TAB_PALETTE) __tt_pv_canpick ;;
786
+ TTHEME_MOUSE) __tt_pv_pointer ;;
753
787
  esac
754
788
  }
755
789
 
790
+ __tt_pv_pointer() {
791
+ if [[ $1 == off || $TTHEME_MOUSE == off ]]; then
792
+ [[ -n $pvmouse ]] && printf '\e[?1006l\e[?1002l\e[?1000l'
793
+ pvmouse="" mzone=""
794
+ else
795
+ pvmouse=$'\e[?1000h\e[?1002h\e[?1006h'
796
+ printf %s "$pvmouse"
797
+ fi
798
+ }
799
+
756
800
  __tt_pv_unconf() {
757
801
  local -i i
758
802
  for (( i = 1; i <= ${#cvars}; i++ )); do
@@ -814,6 +858,7 @@ __tt_pv_conf_panel() {
814
858
  var=${cvars[k]} ch=(${=cchoice[k]}) sh=(${=cshow[k]})
815
859
  i=${ch[(Ie)${(P)var}]}
816
860
  out+=$'\e['$(( r0 + k - 1 ))';'$col'H'
861
+ pvz+=("$(( r0 + k - 1 )) $col $end conf $k")
817
862
  if (( k == cf )); then
818
863
  out+=$c"▶"$z" "$b
819
864
  else
@@ -825,12 +870,18 @@ __tt_pv_conf_panel() {
825
870
  (( i )) && v=${sh[i]}
826
871
  if (( k == cf )); then
827
872
  out+=$c"‹ "$z$b$v$z$c" ›"$z
873
+ pvz+=("$(( r0 + k - 1 )) $(( col + 13 )) $(( col + 14 )) confs $k -1")
874
+ pvz+=("$(( r0 + k - 1 )) $(( col + 15 + ${(m)#v} )) $(( col + 17 + ${(m)#v} )) confs $k 1")
828
875
  else
829
876
  out+=" "$v
830
877
  fi
831
878
  continue
832
879
  fi
880
+ local -i zc=$(( col + 13 ))
833
881
  for (( j = 1; j <= ${#sh}; j++ )); do
882
+ (( j > 1 )) && (( zc++ ))
883
+ pvz+=("$(( r0 + k - 1 )) $zc $(( zc + ${(m)#sh[j]} + 1 )) confv $k $j")
884
+ (( zc += ${(m)#sh[j]} + 2 ))
834
885
  (( j > 1 )) && out+=" "
835
886
  if (( j != i )); then
836
887
  out+=$d" ${sh[j]} "$z
@@ -972,9 +1023,10 @@ __tt_pv_draw() {
972
1023
  out=$'\e[H'
973
1024
  if (( resized )); then
974
1025
  out+=$'\e[K\e[2H\e[J\e[H'
975
- (( bgcw )) && out+=$'\e_Ga=d,d=A,q=2\e\\'
1026
+ (( bgcw )) && { __tt_bg_wipe; out+=$REPLY }
976
1027
  resized=0 wiped=1
977
1028
  fi
1029
+ [[ $1 == hint ]] && (( ! wiped )) || pvz=()
978
1030
  if (( pw < 40 || ph < 12 )); then
979
1031
  line="ttheme preview"
980
1032
  (( color )) && line=$'\e[1m'$ac$line$'\e[0m'
@@ -1030,7 +1082,10 @@ __tt_pv_draw() {
1030
1082
  else
1031
1083
  out+=$line$'\e[K'$tail$'\n\e[K\n'
1032
1084
  fi
1033
- (( N > h && top > 1 )) && out+=" "$dd"…"$zz
1085
+ if (( N > h && top > 1 )); then
1086
+ out+=" "$dd"…"$zz
1087
+ pvz+=("3 1 $lw more -1")
1088
+ fi
1034
1089
  out+=$'\e[K\n'
1035
1090
  for (( k = 0; k < ph - 4; k++ )); do
1036
1091
  i=$(( top + k ))
@@ -1041,9 +1096,15 @@ __tt_pv_draw() {
1041
1096
  elif (( i <= N )); then
1042
1097
  __tt_pv_row $i
1043
1098
  line=$REPLY
1099
+ pvz+=("$(( 4 + k )) 1 $lw row $i")
1100
+ case ${rtype[i]} in
1101
+ hdr) pvz+=("$(( 4 + k )) 3 5 fold $i") ;;
1102
+ cat) pvz+=("$(( 4 + k )) 5 7 fold $i") ;;
1103
+ esac
1044
1104
  fi
1045
1105
  elif (( k == h && N > h && top + h <= N )); then
1046
1106
  line=" "$dd"…"$zz
1107
+ pvz+=("$(( 4 + k )) 1 $lw more 1")
1047
1108
  fi
1048
1109
  out+=$line$'\e[K\n'
1049
1110
  done
@@ -1221,10 +1282,233 @@ __tt_pv_read() {
1221
1282
  "1;2D") key=sleft ;;
1222
1283
  "27;2;13~"|"13;2u") key=senter ;;
1223
1284
  Z) key=stab ;;
1285
+ '<'<->';'<->';'<->[Mm]) __tt_pv_sgr $seq ;;
1286
+ M) __tt_pv_x10 ;;
1224
1287
  *) key=nop ;;
1225
1288
  esac
1226
1289
  }
1227
1290
 
1291
+ __tt_pv_sgr() {
1292
+ local -a p=(${(s:;:)${${1#<}%[Mm]}})
1293
+ local -i b=$p[1]
1294
+ key=mouse mrow=$p[3] mcol=$p[2] mwheel=0
1295
+ if (( b & 128 || mrow < 1 || mcol < 1 )); then
1296
+ key=nop
1297
+ elif (( b & 64 )); then
1298
+ mact=wheel mwheel=$(( b & 1 ? 1 : -1 ))
1299
+ (( b & 2 || mwheel == mlwheel )) && key=nop
1300
+ mlwheel=$mwheel
1301
+ elif (( b & 32 )); then
1302
+ mact=drag
1303
+ (( b & 3 )) && key=nop
1304
+ elif [[ $1 == *m ]] || (( (b & 3) == 3 )); then
1305
+ mact=release
1306
+ elif (( b & 3 )); then
1307
+ key=nop
1308
+ else
1309
+ mact=press
1310
+ if (( mrow == mlrow && mcol - mlcol <= 1 && mlcol - mcol <= 1 && EPOCHREALTIME - mlast <= 0.5 )); then
1311
+ (( ++mclick ))
1312
+ else
1313
+ mclick=1
1314
+ fi
1315
+ mlast=$EPOCHREALTIME mlrow=$mrow mlcol=$mcol
1316
+ fi
1317
+ return 0
1318
+ }
1319
+
1320
+ __tt_pv_x10() {
1321
+ local a b c
1322
+ key=nop
1323
+ __tt_pv_getch 0.05 && a=$REPLY || return 0
1324
+ __tt_pv_getch 0.05 && b=$REPLY || return 0
1325
+ __tt_pv_getch 0.05 && c=$REPLY || return 0
1326
+ (( #a < 128 && #b > 32 && #b < 128 && #c > 32 && #c < 128 )) || return 0
1327
+ __tt_pv_sgr "<$(( #a - 32 ));$(( #b - 32 ));$(( #c - 32 ))M"
1328
+ }
1329
+
1330
+ __tt_pv_spot() {
1331
+ local z
1332
+ local -a f
1333
+ for z in "${(@Oa)pvz}"; do
1334
+ f=(${=z})
1335
+ (( f[1] == $1 && $2 >= f[2] && $2 <= f[3] )) || continue
1336
+ REPLY=$z
1337
+ return 0
1338
+ done
1339
+ REPLY=""
1340
+ return 1
1341
+ }
1342
+
1343
+ __tt_pv_word() {
1344
+ case $1 in
1345
+ enter) REPLY=$'\r' ;;
1346
+ esc) REPLY=esc ;;
1347
+ tab) REPLY=$'\t' ;;
1348
+ bksp) REPLY=$'\x7f' ;;
1349
+ space) REPLY=' ' ;;
1350
+ ⇧enter) REPLY=senter ;;
1351
+ ←) REPLY=left ;;
1352
+ →) REPLY=right ;;
1353
+ '?'|'#'|[a-zA-Z]|'='|'+') REPLY=$1 ;;
1354
+ *) REPLY="" ;;
1355
+ esac
1356
+ [[ -n $REPLY ]]
1357
+ }
1358
+
1359
+ __tt_pv_mouse() {
1360
+ local REPLY
1361
+ local -a z
1362
+ if [[ $mact == wheel ]]; then
1363
+ __tt_pv_wheel
1364
+ return
1365
+ fi
1366
+ if [[ $mact == press ]]; then
1367
+ if (( help )); then
1368
+ help=0 mzone=""
1369
+ return 0
1370
+ fi
1371
+ __tt_pv_spot $mrow $mcol
1372
+ mzone=$REPLY
1373
+ fi
1374
+ z=(${=mzone})
1375
+ (( ${#z} )) || return 0
1376
+ [[ $mact == release ]] && mzone=""
1377
+ if [[ $z[4] == tone ]]; then
1378
+ __tt_pv_te_mouse $z
1379
+ return
1380
+ fi
1381
+ case $mact in
1382
+ press) __tt_pv_press $z ;;
1383
+ drag) [[ $z[4] == track ]] && __tt_pv_bg_track $z[5] $(( mcol - z[2] )) $(( z[3] - z[2] )) ;;
1384
+ release) (( mrow == z[1] && mcol >= z[2] && mcol <= z[3] )) && __tt_pv_release $z ;;
1385
+ esac
1386
+ }
1387
+
1388
+ __tt_pv_free() {
1389
+ (( ! conf && ! te && ! help )) && [[ -z $pick && -z $tune ]]
1390
+ }
1391
+
1392
+ __tt_pv_press() {
1393
+ case $4 in
1394
+ row|fold) __tt_pv_free && [[ ${rtype[$5]} != rule ]] && cur=$5 ;;
1395
+ pick) pk=$5 ;;
1396
+ conf) cf=$5 ;;
1397
+ teimg) (( tfocus == 1 )) || __tt_te_to_image ;;
1398
+ tefield|track|place|colors)
1399
+ (( tfocus == 1 )) || __tt_te_to_image
1400
+ case $4 in
1401
+ place) tf=2 ;;
1402
+ colors) tf=4 ;;
1403
+ *) tf=$5 ;;
1404
+ esac
1405
+ [[ $4 == track ]] && __tt_pv_bg_track $5 $(( mcol - $2 )) $(( $3 - $2 ))
1406
+ ;;
1407
+ esac
1408
+ return 0
1409
+ }
1410
+
1411
+ __tt_pv_release() {
1412
+ case $4 in
1413
+ key)
1414
+ __tt_pv_word $5 || return 0
1415
+ key=$REPLY
1416
+ __tt_pv_handle
1417
+ return
1418
+ ;;
1419
+ row|pick)
1420
+ (( mclick == 2 )) || return 0
1421
+ if [[ $4 == row ]]; then
1422
+ __tt_pv_free || return 0
1423
+ else
1424
+ [[ -n $pick ]] || return 0
1425
+ fi
1426
+ key=$'\r'
1427
+ __tt_pv_handle
1428
+ return
1429
+ ;;
1430
+ fold) __tt_pv_free && [[ ${rtype[cur]} == (hdr|cat) ]] && __tt_pv_toggle ;;
1431
+ more)
1432
+ __tt_pv_free || return 0
1433
+ key=pgdn
1434
+ (( $5 < 0 )) && key=pgup
1435
+ __tt_pv_handle
1436
+ return
1437
+ ;;
1438
+ hub)
1439
+ local -i at=${TTHEME_HUB_TABS[(Ie)preview]}
1440
+ __tt_pv_free && (( $5 != at )) || return 0
1441
+ __tt_pv_screen $(( $5 - at )) || return 1
1442
+ ;;
1443
+ confv)
1444
+ cf=$5
1445
+ local -a ch=(${=cchoice[$5]})
1446
+ __tt_pv_conf_put ${cvars[$5]} ${ch[$6]}
1447
+ ;;
1448
+ confs)
1449
+ cf=$5
1450
+ __tt_pv_conf_step $6
1451
+ ;;
1452
+ tefind) __tt_te_find ;;
1453
+ teapply) __tt_te_apply || return 1 ;;
1454
+ place) __tt_pv_bg_adjust at $5 ;;
1455
+ colors)
1456
+ __tt_bg_coloring $tpick
1457
+ [[ $5 == "$REPLY" ]] || __tt_pv_bg_recolor
1458
+ ;;
1459
+ esac
1460
+ return 0
1461
+ }
1462
+
1463
+ __tt_pv_te_mouse() {
1464
+ local -i li=$(( $5 + mrow - $1 )) ci=$(( mcol - $2 ))
1465
+ if [[ $mact == press ]] && (( tfocus != 0 )); then
1466
+ tfocus=0
1467
+ __tt_te_ask "focus 1" || return 0
1468
+ fi
1469
+ (( li < 0 )) && li=0
1470
+ (( ci < 0 )) && ci=0
1471
+ __tt_te_ask "mouse $mact $li $ci $mclick" || { __tt_te_close; return 0 }
1472
+ __tt_te_act
1473
+ }
1474
+
1475
+ __tt_pv_bg_track() {
1476
+ local -i x=$2 w=$3
1477
+ (( x < 0 )) && x=0
1478
+ (( x > w )) && x=$w
1479
+ (( w > 0 )) || return 0
1480
+ if (( $1 == 3 )); then
1481
+ __tt_pv_bg_adjust opto $(( (x * 100 + w / 2) / w ))
1482
+ else
1483
+ __tt_pv_bg_adjust sizeat $(( x * 1000 / w ))
1484
+ fi
1485
+ }
1486
+
1487
+ __tt_pv_wheel() {
1488
+ local -i i
1489
+ if (( help )); then
1490
+ return 0
1491
+ elif (( conf )); then
1492
+ (( cf += mwheel ))
1493
+ (( cf < 1 )) && cf=1
1494
+ (( cf > ${#cvars} )) && cf=${#cvars}
1495
+ elif (( te )); then
1496
+ if (( tfocus == 0 )); then
1497
+ __tt_te_ask "mouse wheel 0 0 $mwheel"
1498
+ else
1499
+ key=down
1500
+ (( mwheel < 0 )) && key=up
1501
+ __tt_pv_te
1502
+ return
1503
+ fi
1504
+ elif [[ -z $pick && -z $tune ]] && (( ${#rval} )); then
1505
+ i=$(( cur + mwheel ))
1506
+ [[ ${rtype[i]} == rule ]] && (( i += mwheel ))
1507
+ (( i >= 1 && i <= ${#rval} )) && cur=$i
1508
+ fi
1509
+ return 0
1510
+ }
1511
+
1228
1512
  __tt_pv_pick() {
1229
1513
  case $key in
1230
1514
  $'\x03') return 1 ;;
@@ -1244,6 +1528,7 @@ __tt_pv_screen() {
1244
1528
  local -i at=${TTHEME_HUB_TABS[(Ie)preview]} n=${#TTHEME_HUB_TABS} rc
1245
1529
  local -i to=$(( (at - 1 + $1 + n) % n + 1 ))
1246
1530
  __tt_pv_bg_close
1531
+ __tt_pv_leave
1247
1532
  while (( to != at )); do
1248
1533
  hubwas="$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}"
1249
1534
  err=$(TTHEME_HUB=${TTHEME_HUB_TABS[to]} __tt_cli ${TTHEME_HUB_TABS[to]} 2>&1 >/dev/tty)
@@ -1259,7 +1544,7 @@ __tt_pv_screen() {
1259
1544
  to=$at
1260
1545
  fi
1261
1546
  done
1262
- printf '\e[?2026h\e[?25l'
1547
+ printf '\e[?2026h\e[?25l%s' "$pvmouse"
1263
1548
  if [[ -n $applied ]]; then
1264
1549
  __tt_pv_paint "$applied"
1265
1550
  else
@@ -1328,7 +1613,7 @@ __tt_te_open() {
1328
1613
  coproc __tt_cli tone $name 2>/dev/null
1329
1614
  exec {rfd}<&p {wfd}>&p
1330
1615
  TE_OUT=$rfd TE_IN=$wfd TE_PID=$!
1331
- tename=$name tfocus=0 tespec="" tesz="" teframe=() tedirty=0 temode=list tetop=0 msgt=0
1616
+ tename=$name tfocus=0 tespec="" tesz="" teframe=() tedirty=0 temode=list tetop=0 msgt=0 teshown="" telook=""
1332
1617
  if ! __tt_te_ask "focus 1"; then
1333
1618
  msg="Could not start the palette panel for $name" msgt=300
1334
1619
  __tt_te_stop
@@ -1344,7 +1629,7 @@ __tt_te_open() {
1344
1629
  __tt_te_close() {
1345
1630
  [[ -n $tune ]] && __tt_pv_untune
1346
1631
  __tt_te_stop
1347
- te=0 tfocus=0 tename="" tespec="" tesz="" teframe=() tetop=0 help=0 pick=""
1632
+ te=0 tfocus=0 tename="" tespec="" tesz="" teframe=() tetop=0 help=0 pick="" teshown="" telook=""
1348
1633
  resized=1 bgname=""
1349
1634
  return 0
1350
1635
  }
@@ -1441,6 +1726,10 @@ __tt_te_key() {
1441
1726
  ;;
1442
1727
  esac
1443
1728
  __tt_te_ask "$m" || { __tt_te_close; return 0 }
1729
+ __tt_te_act
1730
+ }
1731
+
1732
+ __tt_te_act() {
1444
1733
  case ${teframe[2]} in
1445
1734
  save) __tt_te_save ;;
1446
1735
  cancel) __tt_te_close ;;
@@ -1582,14 +1871,13 @@ __tt_pv_te_ghost() {
1582
1871
  __tt_pv_te_panel() {
1583
1872
  local z=$'\e[0m' d=$'\e[2m' b=$'\e[1m' tt st note REPLY
1584
1873
  local -a held
1585
- local -i col=$1 end=$2 r0=$3 r1=$4 R W T I=3 V at i n y tfs=$tf lo=15
1874
+ local -i col=$1 end=$2 r0=$3 r1=$4 R W T I=3 V at i n y tfs=$tf
1586
1875
  (( color )) || z= d= b=
1587
1876
  R=$(( r1 - r0 + 1 )) W=$(( end - col + 1 ))
1588
- [[ $temode == list ]] || lo=21
1589
1877
  [[ -n $tune ]] || __tt_pv_bg_findable $tename && I=17
1590
1878
  T=$(( R - I - 3 ))
1591
1879
  (( T > 26 )) && T=26
1592
- (( T < 21 )) && T=$lo
1880
+ (( T < 21 )) && T=15
1593
1881
  if [[ "$W $T" != "$tesz" ]]; then
1594
1882
  tesz="$W $T"
1595
1883
  __tt_te_ask "size $W $T"
@@ -1610,9 +1898,11 @@ __tt_pv_te_panel() {
1610
1898
  tt=$d
1611
1899
  (( tfocus == 1 )) && tt=$b$ac
1612
1900
  out+=$'\e['$y';'$(( col + 2 ))'H'$tt"Image"$z
1901
+ pvz+=("$y $col $end teimg")
1613
1902
  if [[ -n $tune ]]; then
1614
1903
  (( bgoff[$tpick] )) && st=off || st=on
1615
- __tt_pv_bg_title $(( W - 14 ))
1904
+ [[ ${teframe[10]} == 1 ]] && ! __tt_bg_tints && st="recolors on save $st"
1905
+ __tt_pv_bg_title $(( W - 12 - ${#st} ))
1616
1906
  out+=" "$d$REPLY$z$'\e['$y';'$(( end - ${#st} + 1 ))'H'$d$st$z
1617
1907
  fi
1618
1908
  if (( I == 17 )); then
@@ -1627,6 +1917,7 @@ __tt_pv_te_panel() {
1627
1917
  st=" " tt=$d
1628
1918
  (( tfocus == 1 && tf == 5 )) && st=$ac"▶"$z" " tt=$b
1629
1919
  out+=$'\e['$(( y + 2 ))';'$col'H'$st$tt"Images"$z$'\e['$(( y + 2 ))';'$(( end - ${#note} + 1 ))'H'$d$note$z
1920
+ pvz+=("$(( y + 2 )) $col $end teimg")
1630
1921
  if [[ -n $tune ]]; then
1631
1922
  bgstrip="$(( y + 2 )) $col $end"
1632
1923
  (( tfocus == 1 )) || tf=0
@@ -1634,6 +1925,9 @@ __tt_pv_te_panel() {
1634
1925
  tf=$tfs
1635
1926
  else
1636
1927
  __tt_pv_te_tile $(( y + 3 )) $col
1928
+ for (( i = 3; i <= 7; i++ )); do
1929
+ pvz+=("$(( y + i )) $col $(( col + 30 )) tefind")
1930
+ done
1637
1931
  __tt_pv_te_ghost $(( y + 9 )) $col $end
1638
1932
  fi
1639
1933
  elif (( bgcw )); then
@@ -1645,10 +1939,12 @@ __tt_pv_te_panel() {
1645
1939
  for (( i = 1; i <= T; i++ )); do
1646
1940
  y=$(( r0 + I + i - tetop ))
1647
1941
  (( y >= r0 && y <= r1 )) || continue
1648
- out+=$'\e['$y';'$col'H'${teframe[9 + i]}$z
1942
+ out+=$'\e['$y';'$col'H'${teframe[11 + i]}$z
1943
+ pvz+=("$y $col $end tone $(( i - 1 ))")
1649
1944
  done
1650
1945
  y=$(( r0 + V - 1 - tetop ))
1651
1946
  (( y >= r0 && y <= r1 )) || return 0
1947
+ pvz+=("$y $col $end teapply")
1652
1948
  if [[ $mode == pin ]]; then
1653
1949
  note="saves, then asks how far it reaches"
1654
1950
  elif (( canpick )); then
@@ -1692,6 +1988,10 @@ __tt_pv_te_draw() {
1692
1988
 
1693
1989
  __tt_pv_handle() {
1694
1990
  local name
1991
+ if [[ $key == mouse ]]; then
1992
+ __tt_pv_mouse
1993
+ return
1994
+ fi
1695
1995
  if (( help )); then
1696
1996
  case $key in
1697
1997
  $'\x03') return 1 ;;
@@ -1846,25 +2146,29 @@ __tt_preview() {
1846
2146
  local -i scene=0
1847
2147
  local -a bgorder=()
1848
2148
  local -A bgfrom=() bgurl=() bgby=() bgsent=() bgcost=() bgdim=() bgsrc=() bgfill=() bgfocus=() bgsize=() bgpos=() bgop=() bgdef=() bgoff=() bgbase=() bgload=() bgshot=() bgshotkey=() bgedit=() bgtunef=() bgofff=() bgimages=()
1849
- local -A bgpic=() bgpics=() bgact=() bgview=() bgswap=() bgthumb=() tsnaps=() pvseek=() bgcolors=() bgprep=()
2149
+ local -A bgpic=() bgpics=() bgact=() bgview=() bgswap=() bgthumb=() tsnaps=() pvseek=() bgcolors=() bgprep=() TTHEME_ALIASES=()
1850
2150
  local conf=0 cf=1
1851
2151
  local -a plabel=(" Default " " This tab ") pkeys=() reach=() csnap=() teframe=()
1852
- local te=0 tfocus=0 tetop=0 tename="" tedirty=0 temode=list tespec="" tesz=""
1853
- local -i TE_IN=0 TE_OUT=0 TE_PID=0 pvgone=0 bgprepid=0
1854
- local -a cvars=(TTHEME_TAB_PALETTE TTHEME_ANNOUNCE TTHEME_FX TTHEME_SORT TTHEME_BG_BLUR TTHEME_BG_COLORS) clabel=("New tabs" Announce "Search fx" Sort Blur Colors)
1855
- local -a cchoice=("off seq" "1 0" "typewriter decode glitch" "abc series" "0 1 2 3 4" "tone original") cshow=("off seq" "on off" "typewriter decode glitch" "abc series" "off 1px 2px 3px 4px" "tone original")
2152
+ local te=0 tfocus=0 tetop=0 tename="" tedirty=0 temode=list tespec="" tesz="" teshown="" telook=""
2153
+ local -i TE_IN=0 TE_OUT=0 TE_PID=0 pvgone=0 bgprepid=0 mrow=0 mcol=0 mclick=0 mwheel=0 mlwheel=0 mlrow=0 mlcol=0
2154
+ local -F mlast=0
2155
+ local mact="" mzone="" pvmouse=""
2156
+ local -a pvz=()
2157
+ local -a cvars=(TTHEME_TAB_PALETTE TTHEME_ANNOUNCE TTHEME_FX TTHEME_SORT TTHEME_MOUSE TTHEME_BG_BLUR TTHEME_BG_COLORS) clabel=("New tabs" Announce "Search fx" Sort Mouse Blur Colors)
2158
+ local -a cchoice=("off seq" "1 0" "typewriter decode glitch" "abc series" "on off" "0 1 2 3 4" "tone original") cshow=("off seq" "on off" "typewriter decode glitch" "abc series" "on off" "off 1px 2px 3px 4px" "tone original")
1856
2159
  local -A cnote=(
1857
2160
  TTHEME_TAB_PALETTE:seq "New tabs rotate through palettes" TTHEME_TAB_PALETTE:off "New tabs keep the terminal theme"
1858
2161
  TTHEME_ANNOUNCE:1 "Shows the palette notice" TTHEME_ANNOUNCE:0 "Silences the palette notice"
1859
2162
  TTHEME_FX:typewriter "The search hint types itself" TTHEME_FX:decode "The search hint decodes" TTHEME_FX:glitch "The search hint glitches in"
1860
2163
  TTHEME_SORT:abc "Series and palettes by name" TTHEME_SORT:series "Series in the order added"
2164
+ TTHEME_MOUSE:on "Clicks, the wheel and drags work in ttheme's screens" TTHEME_MOUSE:off "The terminal keeps the mouse, so a drag selects text"
1861
2165
  TTHEME_BG_BLUR:0 "Pictures stay sharp" TTHEME_BG_BLUR:1 "Pictures soften a little behind the text"
1862
2166
  TTHEME_BG_BLUR:2 "Pictures soften behind the text" TTHEME_BG_BLUR:3 "Pictures blur behind the text"
1863
2167
  TTHEME_BG_BLUR:4 "Pictures blur well behind the text"
1864
2168
  TTHEME_BG_COLORS:tone "New pictures are tinted in one color of the palette"
1865
2169
  TTHEME_BG_COLORS:original "New pictures keep their own colors"
1866
2170
  )
1867
- __tt_pv_conf_rows
2171
+ [[ -r $TTHEME_HOME/aliases.zsh ]] && source $TTHEME_HOME/aliases.zsh
1868
2172
  [[ $mode == pin ]] && __tt_pin_scopes "$pdir"
1869
2173
  __tt_pv_canpick
1870
2174
  __tt_pv_size
@@ -1882,6 +2186,7 @@ __tt_preview() {
1882
2186
  TTHEME_RAW=$(( ${#tty} > 0 ))
1883
2187
  __tt_pv_bg_open
1884
2188
  printf '\e[?2026h\e[?1049h\e[?7l\e[?25l'
2189
+ __tt_pv_pointer
1885
2190
  while :; do
1886
2191
  printf '\e[?2026h'
1887
2192
  if (( tick && ! te )); then
@@ -1891,7 +2196,7 @@ __tt_preview() {
1891
2196
  [[ ${rtype[cur]} == thm ]] && an=${rval[cur]}
1892
2197
  __tt_pv_draw
1893
2198
  fi
1894
- tick=0
2199
+ tick=0 mlwheel=0
1895
2200
  if ! __tt_pv_read; then
1896
2201
  (( pvgone )) && break
1897
2202
  [[ -t 0 ]] && continue
@@ -1918,6 +2223,7 @@ __tt_preview() {
1918
2223
  elif [[ $applied != "$orig" ]]; then
1919
2224
  __tt_pv_paint "${TTHEME_PAINTED:+$orig}"
1920
2225
  fi
2226
+ __tt_pv_pointer off
1921
2227
  printf '\e[?7h'
1922
2228
  (( hubleft )) || printf '\e[?1049l'
1923
2229
  printf '\e[?25h\e[?2026l'
package/shell/ttheme.zsh CHANGED
@@ -127,12 +127,16 @@ __tt_pins_load
127
127
 
128
128
  : ${TTHEME_SORT:=abc}
129
129
 
130
+ : ${TTHEME_MOUSE:=on}
131
+
130
132
  : ${TTHEME_BG_BLUR:=0}
131
133
 
132
134
  : ${TTHEME_BG_COLORS:=tone}
133
135
 
134
136
  : ${TTHEME_WARP_FAST:=on}
135
137
 
138
+ : ${TTHEME_MARKET_LOOKUP:=on}
139
+
136
140
  typeset -g TTHEME_STATE_DIR=${XDG_STATE_HOME:-$HOME/.local/state}/ttheme
137
141
 
138
142
  () {
@@ -1293,6 +1297,7 @@ __tt_cli() {
1293
1297
  for k in $TTHEME_SETTINGS; do
1294
1298
  (( $+parameters[$k] )) && pass+=("$k=${(P)k}")
1295
1299
  done
1300
+ __tt_cli_env
1296
1301
  env $pass node $TTHEME_HOME/ttheme.js "$@"
1297
1302
  }
1298
1303
 
@@ -1430,6 +1435,27 @@ __tt_rotate() {
1430
1435
 
1431
1436
  source $TTHEME_HOME/preview.zsh
1432
1437
 
1438
+ __tt_hook() {
1439
+ autoload -Uz add-zsh-hook add-zle-hook-widget
1440
+ zle -N __tt_line_init
1441
+ add-zle-hook-widget line-init __tt_line_init
1442
+ add-zsh-hook chpwd __tt_chpwd
1443
+ add-zsh-hook precmd __tt_prompt
1444
+ if (( ! TTHEME_TMUX )); then
1445
+ add-zsh-hook preexec __tt_ran
1446
+ add-zsh-hook precmd __tt_unmux
1447
+ fi
1448
+ if __tt_follows_focus || (( TTHEME_TMUX )); then
1449
+ add-zsh-hook precmd __tt_precmd
1450
+ add-zsh-hook preexec __tt_preexec
1451
+ __tt_bind_focus
1452
+ else
1453
+ __tt_sync
1454
+ fi
1455
+ __tt_follows_prompt && add-zsh-hook precmd __tt_prompted
1456
+ return 0
1457
+ }
1458
+
1433
1459
  ttheme() {
1434
1460
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
1435
1461
  if (( $# > 1 && ${${argv[2,-1]}[(I)(-h|--help)]} )); then
@@ -1449,8 +1475,7 @@ ttheme() {
1449
1475
  __tt_fresh
1450
1476
  (( $+functions[ttheme] )) || { print -u2 "ttheme: uninstalled — \`npx @kecan0406/ttheme@latest init\` sets it up again"; return 1 }
1451
1477
  if ! __tt_paints && (( ! $# || ${TTHEME_TAB_VERBS[(Ie)$1]} )); then
1452
- __tt_unpainted
1453
- return 1
1478
+ __tt_unpainted && __tt_paints || return 1
1454
1479
  fi
1455
1480
  if (( ! $# )); then
1456
1481
  (( ${#TTHEME_PALETTE} )) || { __tt_empty; return }
@@ -1558,23 +1583,7 @@ fi
1558
1583
  fi
1559
1584
  __tt_dir_sync
1560
1585
  }
1561
- autoload -Uz add-zsh-hook add-zle-hook-widget
1562
- zle -N __tt_line_init
1563
- add-zle-hook-widget line-init __tt_line_init
1564
- add-zsh-hook chpwd __tt_chpwd
1565
- add-zsh-hook precmd __tt_prompt
1566
- if (( ! TTHEME_TMUX )); then
1567
- add-zsh-hook preexec __tt_ran
1568
- add-zsh-hook precmd __tt_unmux
1569
- fi
1570
- if __tt_follows_focus || (( TTHEME_TMUX )); then
1571
- add-zsh-hook precmd __tt_precmd
1572
- add-zsh-hook preexec __tt_preexec
1573
- __tt_bind_focus
1574
- else
1575
- __tt_sync
1576
- fi
1577
- __tt_follows_prompt && add-zsh-hook precmd __tt_prompted
1586
+ __tt_hook
1578
1587
  __tt_announce
1579
1588
  }
1580
1589