@kecan0406/ttheme 1.2.8 → 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/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
  () {
@@ -274,12 +278,6 @@ __tt_empty() {
274
278
  return 1
275
279
  }
276
280
 
277
- __tt_spec() {
278
- local spec=${TTHEME_PALETTE[$1]}
279
- [[ -n $spec ]] || return 1
280
- print -r -- "$spec"
281
- }
282
-
283
281
  __tt_name_of() { REPLY=${${(k)TTHEME_PALETTE[(re)$1]}:-custom} }
284
282
 
285
283
  __tt_color() { [[ -t 1 && -z $NO_COLOR && $TERM != dumb ]] }
@@ -1299,6 +1297,7 @@ __tt_cli() {
1299
1297
  for k in $TTHEME_SETTINGS; do
1300
1298
  (( $+parameters[$k] )) && pass+=("$k=${(P)k}")
1301
1299
  done
1300
+ __tt_cli_env
1302
1301
  env $pass node $TTHEME_HOME/ttheme.js "$@"
1303
1302
  }
1304
1303
 
@@ -1434,2023 +1433,95 @@ __tt_rotate() {
1434
1433
  __tt_announce
1435
1434
  }
1436
1435
 
1437
- __tt_pv_norm() { REPLY=${(L)1//[^[:alnum:]]/} }
1438
-
1439
- __tt_pv_seek() {
1440
- local t part key REPLY
1441
- for t in ${(k)TTHEME_PALETTE}; do
1442
- key=""
1443
- for part in "$t" "${TTHEME_GROUP[$t]:-Other}" "${TTHEME_NATIVE[$t]}" "${TTHEME_CATALOG[$t]}" "${(@s:|:)TTHEME_NATIVE_NAMES[$t]}" "${TTHEME_CHARACTER[$t]}"; do
1444
- [[ -n $part ]] || continue
1445
- __tt_pv_norm "$part"
1446
- key+="|$REPLY"
1447
- done
1448
- pvseek[$t]=$key
1449
- done
1450
- }
1451
-
1452
- __tt_pv_alias() {
1453
- REPLY=""
1454
- [[ -n $nflt && -n $2 ]] || return 0
1455
- local main
1456
- __tt_pv_norm "$1"
1457
- main=$REPLY
1458
- __tt_pv_norm "$2"
1459
- [[ $main != *$nflt* && $REPLY == *$nflt* ]] && REPLY=$2 || REPLY=""
1460
- return 0
1461
- }
1462
-
1463
- __tt_pv_rows() {
1464
- rtype=() rval=() rcnt=()
1465
- local g t c ruled="" nflt="" REPLY
1466
- local -a ts cs loose inside
1467
- if [[ -n $flt ]]; then
1468
- (( ${#pvseek} )) || __tt_pv_seek
1469
- __tt_pv_norm "$flt"
1470
- nflt=$REPLY
1471
- fi
1472
- for g in $groups; do
1473
- ts=()
1474
- for t in ${=gthemes[$g]}; do
1475
- [[ -z $flt || ${pvseek[$t]} == *$nflt* ]] && ts+=($t)
1476
- done
1477
- [[ -n $flt ]] && (( ! ${#ts} )) && continue
1478
- if [[ $g == *@* && -z $ruled ]]; then
1479
- ruled=1
1480
- (( ${#rtype} )) && { rtype+=(rule); rval+=(''); rcnt+=(0) }
1481
- fi
1482
- rtype+=(hdr); rval+=($g); rcnt+=(${#ts})
1483
- [[ -n $flt || -n ${exp[$g]} ]] || continue
1484
- cs=() loose=()
1485
- for t in $ts; do
1486
- c=${TTHEME_CATALOG[$t]}
1487
- if [[ -n $c && $g == *@* ]]; then
1488
- (( ${cs[(Ie)$c]} )) || cs+=($c)
1489
- else
1490
- loose+=($t)
1491
- fi
1492
- done
1493
- for c in $cs; do
1494
- inside=()
1495
- for t in $ts; do
1496
- [[ ${TTHEME_CATALOG[$t]} == "$c" ]] && inside+=($t)
1497
- done
1498
- rtype+=(cat); rval+=("$g/$c"); rcnt+=(${#inside})
1499
- if [[ -n $flt || -n ${exp[$g/$c]} ]]; then
1500
- for t in $inside; do rtype+=(thm); rval+=($t); rcnt+=(0); done
1501
- fi
1502
- done
1503
- for t in $loose; do rtype+=(thm); rval+=($t); rcnt+=(0); done
1504
- done
1505
- }
1506
-
1507
- __tt_pv_at() {
1508
- local i
1509
- for (( i = 1; i <= ${#rval}; i++ )); do
1510
- [[ ${rtype[i]} == (hdr|cat) && ${rval[i]} == "$1" ]] && { cur=$i; return 0 }
1511
- done
1512
- return 0
1513
- }
1514
-
1515
- __tt_pv_first() {
1516
- local name=$1 i
1517
- cur=1 top=1
1518
- if [[ -n $name ]]; then
1519
- for (( i = 1; i <= ${#rval}; i++ )); do
1520
- [[ ${rtype[i]} == thm && ${rval[i]} == $name ]] && { cur=$i; return 0 }
1521
- done
1522
- fi
1523
- for (( i = 1; i <= ${#rtype}; i++ )); do
1524
- [[ ${rtype[i]} == thm ]] && { cur=$i; return 0 }
1525
- done
1526
- return 0
1527
- }
1528
-
1529
- __tt_pv_goto() {
1530
- local name=$1 i g=${TTHEME_GROUP[$1]:-Other} c=${TTHEME_CATALOG[$1]}
1531
- exp[$g]=1
1532
- [[ -n $c && $g == *@* ]] && exp[$g/$c]=1
1533
- __tt_pv_rows
1534
- for (( i = 1; i <= ${#rval}; i++ )); do
1535
- [[ ${rtype[i]} == thm && ${rval[i]} == $name ]] && { cur=$i; return 0 }
1536
- done
1537
- cur=1
1538
- }
1539
-
1540
- __tt_pv_shows() {
1541
- REPLY=${bgview[$1]:-$1}
1542
- [[ -n $tune && $1 == "$tune" ]] && REPLY=$tpick
1543
- return 0
1544
- }
1545
-
1546
- __tt_pv_focus() {
1547
- if (( te )); then
1548
- __tt_pv_shows $tename
1549
- (( resized )) || [[ $REPLY == "$bgname" ]] || __tt_pv_bg_show "$REPLY"
1550
- return 0
1551
- fi
1552
- [[ ${rtype[cur]} == thm ]] || return 0
1553
- __tt_pv_shows ${rval[cur]}
1554
- (( resized )) || [[ $REPLY == "$bgname" ]] || __tt_pv_bg_show "$REPLY"
1555
- local spec=${TTHEME_PALETTE[${rval[cur]}]}
1556
- [[ $spec == "$applied" ]] && return 0
1557
- __tt_pv_paint "$spec"
1558
- applied=$spec
1559
- }
1560
-
1561
- __tt_pv_toggle() {
1562
- [[ -n $flt ]] && return 0
1563
- local g=${rval[cur]}
1564
- if [[ -n ${exp[$g]} ]]; then
1565
- exp[$g]=""
1566
- else
1567
- exp[$g]=1
1568
- fi
1569
- __tt_pv_rows
1570
- }
1571
-
1572
- __tt_pv_left() {
1573
- [[ -n $flt ]] && return 0
1574
- if [[ ${rtype[cur]} == (hdr|cat) ]]; then
1575
- if [[ -n ${exp[${rval[cur]}]} ]]; then
1576
- __tt_pv_toggle
1577
- elif [[ ${rtype[cur]} == cat ]]; then
1578
- __tt_pv_at ${rval[cur]%%/*}
1579
- fi
1580
- return 0
1581
- fi
1582
- local g=${TTHEME_GROUP[${rval[cur]}]:-Other} c=${TTHEME_CATALOG[${rval[cur]}]}
1583
- [[ -n $c && $g == *@* ]] && g=$g/$c
1584
- exp[$g]=""
1585
- __tt_pv_rows
1586
- __tt_pv_at $g
1587
- }
1588
-
1589
- typeset -gA TTHEME_GLYPHS=(
1590
- 0 111101101101111 1 010110010010111 2 111001111100111 3 111001111001111 4 101101111001001
1591
- 5 111100111001111 6 111100111101111 7 111001001001001 8 111101111101111 9 111101111001111
1592
- '%' 101001010100101 F 111100110100100 I 111010010010111 L 100100100100111
1593
- )
1594
-
1595
- __tt_pv_osd() {
1596
- local text=${(U)osd} bits line oc=$'\e[1m' blank
1597
- local -i s=2 n=${#text} w r c k i top left
1598
- (( n * 16 + 4 <= pw && ph >= 14 )) || s=1
1599
- w=$(( n * 8 * s - 2 * s + 4 ))
1600
- top=$(( (ph - 5 * s) / 2 )) left=$(( (pw - w) / 2 + 1 ))
1601
- (( top < 2 )) && top=2
1602
- (( left < 1 )) && left=1
1603
- if (( color )) && [[ ${rtype[cur]} == thm ]]; then
1604
- local -a fp=(${=TTHEME_PALETTE[${rval[cur]}]})
1605
- local fc=${fp[3]#\#}
1606
- printf -v oc '\e[1;38;2;%d;%d;%dm' $((16#${fc:0:2})) $((16#${fc:2:2})) $((16#${fc:4:2}))
1607
- fi
1608
- blank=${(l:w:: :)}
1609
- out+=$'\e['$(( top - 1 ))';'${left}H$blank
1610
- for (( r = 0; r < 5; r++ )); do
1611
- line=" "
1612
- for (( k = 1; k <= n; k++ )); do
1613
- bits=${TTHEME_GLYPHS[${text[k]}]}
1614
- for (( c = 1; c <= 3; c++ )); do
1615
- if [[ ${bits[r * 3 + c]} == 1 ]]; then
1616
- line+=${(l:2*s::█:)}
1617
- else
1618
- line+=${(l:2*s:: :)}
1619
- fi
1620
- done
1621
- (( k < n )) && line+=${(l:2*s:: :)}
1622
- done
1623
- line+=" "
1624
- for (( i = 0; i < s; i++ )); do
1625
- out+=$'\e['$(( top + r * s + i ))';'${left}H$oc$line$'\e[0m'
1626
- done
1627
- done
1628
- out+=$'\e['$(( top + 5 * s ))';'${left}H$blank
1629
- }
1630
-
1631
- __tt_pv_lw() {
1632
- local -i lw=$(( pw - 2 < 48 ? pw - 2 : 48 )) l=$(( pw * 3 / 10 )) sw=$(( pw * 45 / 100 ))
1633
- (( l < 38 )) && l=38
1634
- (( l > 56 )) && l=56
1635
- (( sw > 64 )) && sw=64
1636
- if (( te && sw < 50 )); then
1637
- sw=50
1638
- (( pw - l - 6 < sw )) && l=$(( pw - sw - 6 ))
1639
- (( l < 30 )) && l=30
1640
- fi
1641
- (( sw > pw - l - 6 )) && sw=$(( pw - l - 6 ))
1642
- if (( color && sw >= 32 )); then
1643
- lw=$l
1644
- else
1645
- sw=0
1646
- fi
1647
- reply=($lw $sw)
1648
- }
1649
-
1650
- __tt_pv_hl() {
1651
- local t=$1 lt=${(L)1} pre
1652
- REPLY=$t
1653
- (( color )) && [[ -n $flt && $lt == *$flt* ]] || return 0
1654
- pre=${lt%%$flt*}
1655
- REPLY=${t[1,${#pre}]}$'\e[1;4m'$ac${t[${#pre}+1,${#pre}+${#flt}]}$'\e[22;24;39m'$2${t[${#pre}+${#flt}+1,-1]}
1656
- }
1436
+ source $TTHEME_HOME/preview.zsh
1657
1437
 
1658
- __tt_pv_fit() {
1659
- local extra=$1
1660
- REPLY=""
1661
- [[ -n $extra ]] || return 0
1662
- while [[ -n $extra ]] && (( ${(m)#extra} + 3 > w )); do
1663
- extra=${extra[1,-2]}
1664
- done
1665
- [[ -n $extra ]] || return 0
1666
- (( w -= ${(m)#extra} + 2 ))
1667
- REPLY=" "$d$extra$r
1668
- }
1669
-
1670
- __tt_pv_row() {
1671
- 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
1672
- local -i w
1673
- (( color )) || b= d= r= z= lead=
1674
- if (( $1 == cur )); then
1675
- gut=$ac"▌"$r" "
1676
- (( color )) && on=$sb
1677
- fi
1678
- if [[ ${rtype[$1]} == rule ]]; then
1679
- name='── Markets '
1680
- REPLY=" "$d$name${(l:lw - 4 - ${#name}::─:)}$z
1681
- return 0
1682
- fi
1683
- if [[ ${rtype[$1]} == hdr ]]; then
1684
- [[ -n $flt || -n ${exp[$t]} ]] && arrow=▾
1685
- name=$t
1686
- (( ${(m)#name} > lw - 10 )) && name="${name[1,lw-11]}…"
1687
- base=$b
1688
- if (( color )) && [[ $t == "$ag" ]]; then
1689
- base+=$ac lead=$ac
1690
- elif (( $1 == cur )); then
1691
- lead=""
1692
- fi
1693
- __tt_pv_hl "$name" "$base"
1694
- hl=$REPLY
1695
- w=$(( lw - 6 - ${(m)#name} - ${#rcnt[$1]} ))
1696
- __tt_pv_alias "$t" "${TTHEME_NATIVE[${${=gthemes[$t]}[1]}]}"
1697
- __tt_pv_fit "$REPLY"
1698
- extra=$REPLY
1699
- (( w < 1 )) && w=1
1700
- REPLY=$gut$on" "$lead$arrow$r" "$base$hl$r$extra${(l:w:: :)}$d${rcnt[$1]}$r" "$z
1701
- return 0
1702
- fi
1703
- if [[ ${rtype[$1]} == cat ]]; then
1704
- [[ -n $flt || -n ${exp[$t]} ]] && arrow=▾
1705
- name=${t#*/}
1706
- (( ${(m)#name} > lw - 12 )) && name="${name[1,lw-13]}…"
1707
- base=$b
1708
- if (( color )) && [[ $t == "$acat" ]]; then
1709
- base+=$ac lead=$ac
1710
- elif (( $1 == cur )); then
1711
- lead=""
1712
- fi
1713
- __tt_pv_hl "$name" "$base"
1714
- w=$(( lw - 8 - ${(m)#name} - ${#rcnt[$1]} ))
1715
- (( w < 1 )) && w=1
1716
- REPLY=$gut$on" "$lead$arrow$r" "$base$REPLY$r${(l:w:: :)}$d${rcnt[$1]}$r" "$z
1717
- return 0
1718
- fi
1719
- if (( $1 == cur )); then
1720
- mark=$ac"■"$r base=$b
1721
- elif [[ -n $cdot && $t == "$cn" ]]; then
1722
- mark=$cdot
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
1723
1447
  fi
1724
- name=${t##*/}
1725
- [[ -n ${TTHEME_CATALOG[$t]} && ${TTHEME_GROUP[$t]} == *@* ]] && ind=" "
1726
- __tt_pv_hl "$name" "$base"
1727
- hl=$REPLY
1728
- extra=""
1729
- for part in "${(@s:|:)TTHEME_NATIVE_NAMES[$t]}" "${TTHEME_CHARACTER[$t]}"; do
1730
- __tt_pv_alias "$name" "$part"
1731
- [[ -n $REPLY ]] && { extra=$REPLY; break }
1732
- done
1733
- if (( color )); then
1734
- [[ -n ${tstrip[$t]} ]] || __tt_pv_strip $t
1735
- w=$(( lw - 16 - ${#ind} - ${#name} ))
1736
- __tt_pv_fit "$extra"
1737
- (( w < 1 )) && w=1
1738
- REPLY=$gut$on"$ind$mark $base$hl$r$REPLY${(l:w:: :)}${tstrip[$t]} "$z
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
1739
1452
  else
1740
- REPLY="$gut$ind$mark $hl${extra:+ $extra}"
1453
+ __tt_sync
1741
1454
  fi
1742
- }
1743
-
1744
- __tt_pv_bg_title() {
1745
- local by=${bgby[$tpick]} ref=${bgfrom[$tpick]} url=${bgurl[$tpick]} mark="" sgr=""
1746
- local -i room=$1
1747
- [[ -n $ref && $url == http(s|)://* ]] && (( ${TTHEME_LINKS[(Ie)$TTHEME_ADAPTER]} )) && mark="⧉ "
1748
- REPLY=Background${by:+ · $by}${ref:+ · $mark$ref}$2
1749
- (( ${#REPLY} > room )) && REPLY=Background${by:+ · $by}
1750
- (( ${#REPLY} > room )) && REPLY=Background
1751
- [[ -n $mark && $REPLY == *"$mark$ref"* ]] || return 0
1752
- (( color )) && [[ -n ${TTHEME_SITE_ANSI[${ref%% *}]} ]] && sgr=$'\e[3'${TTHEME_SITE_ANSI[${ref%% *}]}m
1753
- REPLY=${REPLY/"$mark$ref"/$sgr⧉${sgr:+$'\e[39m'} $'\e]8;;'$url$'\e\\'$ref$'\e]8;;\e\\'}
1754
- return 0
1755
- }
1756
-
1757
- __tt_pv_bar() {
1758
- local z=$'\e[0m' d=$'\e[2m' on=$'\e[7;1m'$ac line=" " title hint="tab next"
1759
- local -i i at=${TTHEME_HUB_TABS[(Ie)preview]} len=${#TTHEME_HUB_TITLES}
1760
- (( color )) || z= d= on=
1761
- [[ ${rtype[cur]} == thm ]] && hint="⇧tab switch"
1762
- for title in $TTHEME_HUB_TITLES; do
1763
- (( len += ${#title} + 2 ))
1764
- done
1765
- for (( i = 1; i <= ${#TTHEME_HUB_TITLES}; i++ )); do
1766
- title=${TTHEME_HUB_TITLES[i]}
1767
- (( i > 1 )) && line+=" "
1768
- if (( i != at )); then
1769
- line+=$d" $title "$z
1770
- elif (( color )); then
1771
- line+=$on" $title "$z
1772
- else
1773
- line+="[$title]"
1774
- fi
1775
- done
1776
- (( len + ${#hint} + 2 <= $1 )) && line+=" "$d$hint$z
1777
- REPLY=$line
1778
- }
1779
-
1780
- __tt_pv_head() {
1781
- local b=$'\e[1m' d=$'\e[2m' z=$'\e[0m' right=$6
1782
- (( color )) || b= d= z=
1783
- out+=$'\e['$1';'$2'H'$b$ac$4$z
1784
- [[ -n $5 ]] && out+=" "$d$5$z
1785
- [[ -n $right ]] && out+=$'\e['$(( $3 - ${(m)#right} + 1 ))'G'$d$right$z
1455
+ __tt_follows_prompt && add-zsh-hook precmd __tt_prompted
1786
1456
  return 0
1787
1457
  }
1788
1458
 
1789
- __tt_pv_foot() {
1790
- setopt localoptions extendedglob
1791
- 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
1792
- local -a kk=() kl=() seg=()
1793
- local -i end=$1 i lwid rwid room
1794
- (( color )) || b= d= z= y= on=
1795
- if (( color )) && [[ -n $applied && $applied != "$painted" ]]; then
1796
- hex=${${=applied}[8]#\#}
1797
- printf -v y '\e[38;2;%d;%d;%dm' $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2}))
1459
+ ttheme() {
1460
+ emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
1461
+ if (( $# > 1 && ${${argv[2,-1]}[(I)(-h|--help)]} )); then
1462
+ __tt_verb_help $1
1463
+ return
1798
1464
  fi
1799
- if (( help )); then
1800
- badge=HELP right=$b"? esc"$z$d" close"$z
1801
- elif [[ -n $pick ]]; then
1802
- badge='PREVIEW (APPLY)' lead="$pick →"
1803
- (( te )) && badge="$tb (APPLY)"
1804
- for (( i = 1; i <= ${#plabel}; i++ )); do
1805
- if (( i != pk )); then
1806
- lead+=" "$d${plabel[i]}$z
1807
- elif (( color )); then
1808
- lead+=" "$on${plabel[i]}$z
1809
- else
1810
- lead+=" [${${plabel[i]# }% }]"
1811
- fi
1812
- done
1813
- if [[ $mode == pin ]]; then
1814
- badge='PREVIEW (PIN)'
1815
- (( te )) && badge="$tb (PIN)"
1816
- __tt_pin_where "${pkeys[pk]}"
1817
- note=$REPLY
1818
- elif (( pk == 2 )); then
1819
- note="Until this tab closes"
1820
- else
1821
- note="New tabs · the default palette"
1822
- fi
1823
- kk=(enter) kl=(confirm)
1824
- right=$b"esc"$z$d" back"$z
1825
- elif (( te && tfocus == 0 )); then
1826
- badge=$tb
1827
- kk=("${(@ps:\x1e:)teframe[6]}") kl=("${(@ps:\x1e:)teframe[7]}")
1828
- i=${kk[(Ie)esc]}
1829
- (( i )) && kk[i]=() kl[i]=()
1830
- right=$b"esc"$z$d" cancel"$z
1831
- if [[ $temode == list ]]; then
1832
- kk=("${kk[1]}" s "${(@)kk[2,-1]}" ⇧enter) kl=("${kl[1]}" save "${(@)kl[2,-1]}" apply)
1833
- elif [[ $temode == tune ]]; then
1834
- right=$b"esc"$z$d" undo"$z
1835
- elif [[ $temode == (type|compare) ]]; then
1836
- right=$b"esc"$z$d" back"$z
1837
- fi
1838
- elif (( te && tfocus == 2 )); then
1839
- badge=$tb kk=(enter ↑↓ s) kl=(apply move save)
1840
- right=$b"esc"$z$d" cancel"$z
1841
- elif (( te )); then
1842
- badge=$tb
1843
- kk=(↑↓ ←→ s) kl=(field step save)
1844
- if [[ -n $tune ]] && (( tf == 5 )); then
1845
- __tt_pv_bg_images $tune
1846
- kl[2]="image ×$REPLY"
1847
- (( REPLY > 1 )) || { kk[2]=() kl[2]=() }
1848
- __tt_pv_bg_findable $tune && { kk+=(f); kl+=(find) }
1849
- kk+=(D) kl+=(remove)
1850
- elif [[ -n $tune ]]; then
1851
- __tt_pv_bg_findable $tune && { kk+=(f); kl+=(find) }
1852
- if (( tf == 2 )); then
1853
- kl[2]=move kk+=(1-9 '=' +) kl+=(place reset "reset all")
1854
- elif (( tf == 4 )); then
1855
- kl[2]=switch kk+=(+) kl+=("reset all")
1856
- else
1857
- kk+=('=' + ⇧←→) kl+=(reset "reset all" ×10)
1858
- fi
1859
- (( bgoff[$tpick] )) && { kk+=(space); kl+=(show) } || { kk+=(c space); kl+=(colors hide) }
1860
- __tt_pv_bg_images $tune
1861
- (( REPLY > 1 )) && { kk+=(', .' D); kl+=("image ×$REPLY" remove) }
1862
- else
1863
- kk=(enter ↑↓ s) kl=(find move save)
1864
- fi
1865
- kk+=(⇧enter) kl+=(apply)
1866
- right=$b"esc"$z$d" cancel"$z
1867
- elif (( conf )); then
1868
- badge=CONFIG kk=(↑↓ ←→ enter) kl=(setting value save)
1869
- right=$b"esc"$z$d" undo"$z
1870
- else
1871
- badge=PREVIEW
1872
- [[ -n $flt ]] && badge='PREVIEW (FILTER)'
1873
- if (( ! ${#rval} )); then
1874
- kk=(bksp) kl=(edit)
1875
- elif [[ ${rtype[cur]} == (hdr|cat) ]]; then
1876
- if [[ -z $flt && -n ${exp[${rval[cur]}]} ]]; then
1877
- kk=(←) kl=(close)
1878
- elif [[ -z $flt ]]; then
1879
- kk=(→) kl=(open)
1880
- fi
1881
- else
1882
- kk=(enter tab) kl=(apply edit)
1883
- (( split )) && { kk+=(⇧←→); kl+=(example) }
1884
- [[ -n $flt ]] && { kk+=(bksp); kl+=(edit) }
1885
- fi
1886
- kk+=('?') kl+=(keys)
1887
- if [[ -n $flt ]]; then
1888
- right=$b"esc"$z$d" clear filter"$z
1889
- else
1890
- right=$b"esc"$z$d" restore"$z
1891
- [[ -n $cdot ]] && right+=" $cdot$z $cn"
1892
- fi
1465
+ case $1 in
1466
+ -h|--help) __tt_help; return 0 ;;
1467
+ -V|--version) __tt_cli --version; return ;;
1468
+ help) __tt_verb_help $2; return 0 ;;
1469
+ -*) print -u2 "ttheme: unknown option $1 — see \`ttheme help\`"; return 1 ;;
1470
+ esac
1471
+ if (( $# )) && [[ -z ${TTHEME_VERB_ABOUT[$1]} ]]; then
1472
+ print -u2 "ttheme: unknown command '$1' — see \`ttheme help\`"
1473
+ return 1
1893
1474
  fi
1894
- if (( msgt > 0 )) && [[ -z $pick ]]; then
1895
- text=$msg
1896
- room=$(( end - (${#badge} ? ${#badge} + 4 : 0) ))
1897
- if (( ${(m)#text} > room )); then
1898
- while [[ -n $text ]] && (( ${(m)#text} > room - 1 )); do text=${text[1,-2]}; done
1899
- text+=…
1900
- fi
1901
- lead=$y$text$z note="" kk=() kl=()
1475
+ __tt_fresh
1476
+ (( $+functions[ttheme] )) || { print -u2 "ttheme: uninstalled — \`npx @kecan0406/ttheme@latest init\` sets it up again"; return 1 }
1477
+ if ! __tt_paints && (( ! $# || ${TTHEME_TAB_VERBS[(Ie)$1]} )); then
1478
+ __tt_unpainted && __tt_paints || return 1
1902
1479
  fi
1903
- while :; do
1904
- seg=()
1905
- [[ -n $lead ]] && seg+=("$lead")
1906
- [[ -n $note ]] && seg+=("$d$note$z")
1907
- for (( i = 1; i <= ${#kk}; i++ )); do
1908
- seg+=("$b${kk[i]}$z$d ${kl[i]}$z")
1909
- done
1910
- line=${(j: :)seg}
1911
- if [[ -n $badge ]]; then
1912
- if (( color )); then
1913
- line=$'\e[7;1m'$ac" $badge "$z" "$line
1914
- else
1915
- line="[$badge] $line"
1916
- fi
1917
- fi
1918
- plain=${line//$'\e'\[[0-9;]##m/}
1919
- lwid=${(m)#plain}
1920
- plain=${right//$'\e'\[[0-9;]##m/}
1921
- rwid=${(m)#plain}
1922
- (( lwid <= end && (! rwid || lwid + 3 + rwid <= end) )) && break
1923
- if [[ -n $note ]]; then
1924
- note=""
1925
- elif (( ${#kk} > 2 )); then
1926
- kk[-2]=() kl[-2]=()
1927
- elif [[ -n $right ]]; then
1928
- right=""
1929
- elif (( ${#kk} > 1 )); then
1930
- kk[-2]=() kl[-2]=()
1480
+ if (( ! $# )); then
1481
+ (( ${#TTHEME_PALETTE} )) || { __tt_empty; return }
1482
+ if [[ -t 0 && -t 1 ]]; then
1483
+ __tt_preview hub
1931
1484
  else
1932
- break
1485
+ __tt_menu
1933
1486
  fi
1934
- done
1935
- out+=$line$'\e[K'
1936
- [[ -n $right ]] && out+=$'\e['$(( end - rwid + 1 ))'G'$right
1937
- return 0
1938
- }
1939
-
1940
- __tt_pv_help() {
1941
- local back="the tab" z=$'\e[0m' b=$'\e[1m' blank
1942
- [[ -n ${TTHEME_PALETTE[$cn]} ]] && back=$cn
1943
- local -a hk=() hv=()
1944
- if (( te )); then
1945
- hk=(Move Image "" "" "" Palette "" "" "" Apply Save Cancel)
1946
- hv=(
1947
- "↑↓ j k the image, the palette, then Apply · home end"
1948
- "Images ←→ , . pick one · D removes it · f finds one"
1949
- "enter on the empty frame · finds the first one"
1950
- "←→ step ⇧←→ ×10 1-9 place · = resets · + all"
1951
- "space hides · c colors"
1952
- "←→ normal or bright · enter tab tune it · # a color"
1953
- "r resets a slot · R all · space the colors before"
1954
- "c copies · v pastes · = bright follows normal"
1955
- "f moves the colors the gate misses · u undo"
1956
- "enter on Apply, or ⇧enter anywhere · saves, asks where"
1957
- "s · keeps the picture and the palette"
1958
- "esc · back to the list, dropping what changed since s"
1959
- )
1960
- else
1961
- hk=(Move Series Filter "" Example Apply Edit)
1962
- hv=(
1963
- "↑↓ home end pgup pgdn"
1964
- "←→ · enter or space on a series"
1965
- "Any text · bksp · ctrl-u clears"
1966
- "Names and titles, in Japanese too"
1967
- "⇧←→ ${(Lj:, :)TTHEME_SCENES}"
1968
- "enter applies · esc restores $back"
1969
- "tab → ctrl+e · its colors and picture"
1970
- )
1971
- hk+=(Config "")
1972
- hv+=("alt-c · ↑↓ setting ←→ value" "enter saves · esc undoes")
1973
- (( hub )) && { hk+=(Screens); hv+=("shift+tab · tab on a series") }
1974
- fi
1975
- hk+=(Close)
1976
- hv+=("? esc")
1977
- (( color )) || z= b=
1978
- local -i i r x y w hh
1979
- if (( split && sw >= 48 )); then
1980
- for (( i = 1; i <= ${#hk}; i++ )); do
1981
- r=$(( i + 3 ))
1982
- (( r < ph )) || break
1983
- out+=$'\e['$r';'$sc'H'$b${hk[i]}$z$'\e['$r';'$(( sc + 10 ))'H'${hv[i][1,se-sc-9]}
1984
- done
1985
- return 0
1986
- fi
1987
- w=$(( pw - 2 < 58 ? pw - 2 : 58 )) hh=$(( ${#hk} + 4 ))
1988
- (( te )) && w=$(( pw - 2 < 76 ? pw - 2 : 76 ))
1989
- x=$(( (pw - w) / 2 + 1 )) y=$(( (ph - hh) / 2 ))
1990
- (( y < 4 )) && y=4
1991
- blank=${(l:w:: :)}
1992
- out+=$'\e['$y';'$x'H'"╭─ Help ${(l:$(( w - 9 ))::─:)}╮"
1993
- for (( r = y + 1; r < y + hh - 1; r++ )); do
1994
- out+=$'\e['$r';'$x'H'$blank$'\e['$r';'$x'H│'$'\e['$r';'$(( x + w - 1 ))'H│'
1995
- done
1996
- for (( i = 1; i <= ${#hk}; i++ )); do
1997
- r=$(( y + 1 + i ))
1998
- out+=$'\e['$r';'$(( x + 3 ))'H'$b${hk[i]}$z$'\e['$r';'$(( x + 13 ))'H'${hv[i][1,w-16]}
1999
- done
2000
- out+=$'\e['$(( y + hh - 1 ))';'$x'H'"╰${(l:$(( w - 2 ))::─:)}╯"
2001
- }
2002
-
2003
- __tt_pv_specimen() {
2004
- local -a sp=(${=applied}) lines parts
2005
- (( ${#sp} >= 20 )) || return 0
2006
- local z=$'\e[0m' d=$'\e[2m' cell hex fore line text piece role tabs="" built="" key="$applied|$painted|$scene|$sw|$sc|$ph"
2007
- local -A rs=(p "" d $'\e[2m' b $'\e[1m')
2008
- local -i i r=6 cw=4 k n=${#TTHEME_SCENES} at
2009
- (( n )) || return 0
2010
- if [[ $key == "$pvscene" ]]; then
2011
- out+=$pvscenes
2012
1487
  return 0
2013
1488
  fi
2014
- at=$(( (scene % n + n) % n + 1 ))
2015
- if [[ $applied == "$painted" ]]; then
2016
- for (( i = 0; i < 16; i++ )); do
2017
- k=$(( i < 8 ? 30 + i : 82 + i ))
2018
- rs[$i]=$'\e['$k'm' rs[B$i]=$'\e[1;'$k'm' rs[K$i]=$'\e[30;'$(( k + 10 ))'m'
2019
- done
2020
- else
2021
- fore=${sp[5]#\#}
2022
- for (( i = 0; i < 16; i++ )); do
2023
- hex=${sp[i+5]#\#}
2024
- printf -v cell '\e[38;2;%d;%d;%dm' $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2}))
2025
- rs[$i]=$cell
2026
- 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})) \
2027
- $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2}))
2028
- rs[K$i]=$cell
2029
- hex=${sp[(i < 8 ? i + 13 : i + 5)]#\#}
2030
- printf -v cell '\e[1;38;2;%d;%d;%dm' $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2}))
2031
- rs[B$i]=$cell
2032
- done
2033
- fi
2034
- printf -v cell '\e[48;2;%d;%d;%dm' $((16#${sp[4]:1:2})) $((16#${sp[4]:3:2})) $((16#${sp[4]:5:2}))
2035
- rs[s]=$cell
2036
- printf -v cell '\e[48;2;%d;%d;%dm' $((16#${sp[3]:1:2})) $((16#${sp[3]:3:2})) $((16#${sp[3]:5:2}))
2037
- rs[c]=$cell
2038
- if (( ${#${(j: :)TTHEME_SCENES}} <= sw )); then
2039
- for (( k = 1; k <= n; k++ )); do
2040
- (( k > 1 )) && tabs+=" "
2041
- if (( k == at )); then
2042
- tabs+=$'\e[1m'$ac$TTHEME_SCENES[k]$z
2043
- else
2044
- tabs+=$d$TTHEME_SCENES[k]$z
2045
- fi
2046
- done
2047
- else
2048
- tabs=$'\e[1m'$ac$TTHEME_SCENES[at]$z" "$d"$at/$n"$z
2049
- fi
2050
- built+=$'\e[2;'$sc'H'$tabs
2051
- (( sw < 44 )) && cw=3
2052
- (( sw >= 56 )) && cw=$(( (sw + 1) / 8 - 1 ))
2053
- (( cw > 7 )) && cw=7
2054
- line=""
2055
- for (( i = 0; i < 8; i++ )); do
2056
- fore=${sp[i+5]#\#} hex=${sp[i+13]#\#}
2057
- printf -v cell '\e[38;2;%d;%d;%d;48;2;%d;%d;%dm%s\e[0m ' \
2058
- $((16#${fore:0:2})) $((16#${fore:2:2})) $((16#${fore:4:2})) \
2059
- $((16#${hex:0:2})) $((16#${hex:2:2})) $((16#${hex:4:2})) "${(l:cw::▀:)}"
2060
- line+=$cell
2061
- done
2062
- built+=$'\e[4;'$sc'H'$line
2063
- lines=("${(@P)${:-TTHEME_SCENE_$at}}")
2064
- for line in "${lines[@]}"; do
2065
- [[ $line == «w»* ]] && (( sw < 44 )) && continue
2066
- [[ $line == «n»* ]] && (( sw >= 44 )) && continue
2067
- (( r < ph )) || break
2068
- parts=("${(@s:«:)line}")
2069
- text=$parts[1]
2070
- for piece in "${(@)parts[2,-1]}"; do
2071
- role=${piece%%»*}
2072
- [[ $role == [wn] ]] && role=p
2073
- text+=$z${rs[${role:-p}]}${piece#*»}
2074
- done
2075
- built+=$'\e['$r';'$sc'H'$text$z
2076
- (( ++r ))
2077
- done
2078
- pvscene=$key pvscenes=$built
2079
- out+=$built
2080
- }
2081
-
2082
- __tt_pv_tune() {
2083
- local -a fields=(size pos op)
2084
- local -i n=1
2085
- local name
2086
- case $key in
2087
- $'\x03') return 1 ;;
2088
- up) tf=$(( tf > 1 ? tf - 1 : 4 )) ;;
2089
- down) tf=$(( tf < 4 ? tf + 1 : 1 )) ;;
2090
- c) (( bgoff[$tpick] )) || __tt_pv_bg_recolor ;;
2091
- left|right|sleft|sright)
2092
- if (( tf == 4 )); then
2093
- (( bgoff[$tpick] )) || __tt_pv_bg_recolor
2094
- return 0
2095
- fi
2096
- [[ $key == *left ]] && n=-1
2097
- [[ $key == s* ]] && (( tf != 2 )) && n=$(( n * 10 ))
2098
- __tt_pv_bg_adjust ${fields[tf]} $n
2099
- ;;
2100
- [1-9])
2101
- tf=2
2102
- __tt_pv_bg_adjust at $key
2103
- ;;
2104
- ' ') __tt_pv_bg_adjust on ;;
2105
- '=') (( tf == 4 )) || __tt_pv_bg_adjust def $tf ;;
2106
- '+') __tt_pv_bg_adjust def ;;
2107
- ',') __tt_pv_bg_pick -1 ;;
2108
- '.') __tt_pv_bg_pick 1 ;;
2109
- D) __tt_pv_bg_drop ;;
2110
- esac
2111
- return 0
2112
- }
2113
-
2114
- __tt_pv_tune_stage() {
2115
- local img was=${bgview[$tune]:-$tune}
2116
- local -i changed=0
2117
- for img in ${(k)tsnaps}; do
2118
- [[ "${bgsize[$img]} ${bgpos[$img]} ${bgop[$img]} ${bgoff[$img]}" == "${tsnaps[$img]}" ]] && continue
2119
- bgedit[$img]=1 changed=1
2120
- done
2121
- if [[ $tpick != "$was" ]]; then
2122
- changed=1
2123
- if [[ $tpick == "$tune" ]]; then
2124
- unset "bgview[$tune]" "bgswap[$tune]"
2125
- else
2126
- bgview[$tune]=$tpick bgswap[$tune]=${tpick##*:}
2127
- fi
2128
- fi
2129
- (( changed )) && msg="Kept · saved when preview closes" msgt=200
2130
- tune="" tpick="" tsnaps=() bgname=""
2131
- }
2132
-
2133
- __tt_pv_tune_keep() {
2134
- __tt_pv_bg_strip_off
2135
- __tt_pv_tune_stage
2136
- }
2137
-
2138
- __tt_pv_untune() {
2139
- local img
2140
- local -a s
2141
- for img in ${(k)tsnaps}; do
2142
- s=(${=tsnaps[$img]})
2143
- bgsize[$img]=$s[1] bgpos[$img]=$s[2] bgop[$img]=$s[3] bgoff[$img]=$s[4]
2144
- done
2145
- __tt_pv_bg_strip_off
2146
- tune="" tpick="" tsnaps=() bgname=""
2147
- }
2148
1489
 
2149
- __tt_pv_regroup() {
2150
- local ty=${rtype[cur]} v=${rval[cur]} i
2151
- __tt_pv_group
2152
- __tt_pv_rows
2153
- for (( i = 1; i <= ${#rval}; i++ )); do
2154
- [[ ${rtype[i]} == "$ty" && ${rval[i]} == "$v" ]] && { cur=$i; return 0 }
2155
- done
2156
- cur=1
2157
- }
2158
-
2159
- __tt_pv_conf() {
2160
- case $key in
2161
- $'\x03') return 1 ;;
2162
- up|k) cf=$(( cf > 1 ? cf - 1 : ${#cvars} )) ;;
2163
- down|j) cf=$(( cf < ${#cvars} ? cf + 1 : 1 )) ;;
2164
- left|sleft) __tt_pv_conf_step -1 ;;
2165
- right|sright) __tt_pv_conf_step 1 ;;
2166
- $'\r'|$'\n') __tt_pv_conf_save ;;
2167
- esc) __tt_pv_unconf ;;
2168
- '?') help=1 ;;
1490
+ case $1 in
1491
+ browse|list|add|remove|update|market|new|edit|check|share) __tt_catalog "$@"; return ;;
1492
+ on|off) __tt_switch "$@"; return ;;
1493
+ info) TTHEME_ZSH=$ZSH_VERSION __tt_cli "$@"; return ;;
2169
1494
  esac
2170
- return 0
2171
- }
2172
-
2173
- __tt_pv_conf_step() {
2174
- local var=${cvars[cf]}
2175
- local -a ch=(${=cchoice[cf]})
2176
- local -i i=${ch[(Ie)${(P)var}]}
2177
- (( i += $1 ))
2178
- (( i >= 1 && i <= ${#ch} )) || return 0
2179
- __tt_pv_conf_put $var ${ch[i]}
2180
- }
1495
+ __tt_arity "$@" || return
1496
+ [[ $1 == config ]] && { __tt_config; return }
1497
+ (( ${#TTHEME_PALETTE} )) || { __tt_empty; return }
2181
1498
 
2182
- __tt_pv_conf_put() {
2183
- [[ ${(P)1} == "$2" ]] && return 0
2184
- typeset -g "$1=$2"
1499
+ local REPLY
2185
1500
  case $1 in
2186
- TTHEME_SORT) __tt_pv_regroup ;;
2187
- TTHEME_FX) [[ -n $flt ]] || { __tt_pv_roll; gstep=8 } ;;
2188
- TTHEME_TAB_PALETTE) __tt_pv_canpick ;;
2189
- esac
2190
- }
2191
-
2192
- __tt_pv_unconf() {
2193
- local -i i
2194
- for (( i = 1; i <= ${#cvars}; i++ )); do
2195
- __tt_pv_conf_put ${cvars[i]} "${csnap[i]}"
2196
- done
2197
- conf=0
2198
- }
2199
-
2200
- __tt_pv_conf_save() {
2201
- local var REPLY
2202
- local -a pairs=()
2203
- local -i i
2204
- for (( i = 1; i <= ${#cvars}; i++ )); do
2205
- var=${cvars[i]}
2206
- [[ ${(P)var} == "${csnap[i]}" ]] || pairs+=($var "${(P)var}")
2207
- done
2208
- if (( ! ${#pairs} )); then
2209
- conf=0
2210
- return 0
2211
- fi
2212
- __tt_tilde "$TTHEME_CONFIG"
2213
- if __tt_config_write "${pairs[@]}"; then
2214
- conf=0 msg="Saved · $REPLY" msgt=200
2215
- (( ${pairs[(Ie)TTHEME_BG_BLUR]} )) && __tt_pv_redraw
2216
- else
2217
- __tt_pv_unconf
2218
- msg="Could not write $REPLY" msgt=200
2219
- fi
2220
- }
2221
-
2222
- __tt_pv_redraw() {
2223
- local name out
2224
- if (( $+functions[__tt_bg_write] )); then
2225
- for name in ${(k)bgedit}; do
2226
- __tt_bg_write $name
2227
- done
2228
- fi
2229
- bgedit=()
2230
- msg="Drawing the background pictures again" msgt=300
2231
- printf '\e[?2026h'
2232
- __tt_pv_draw
2233
- out=$(__tt_cli redraw 2>&1)
2234
- bgsrc=() resized=1 bgname="" bgshown="" bgdim=()
2235
- __tt_reload
2236
- (( $+functions[__tt_bg_refresh] )) && __tt_bg_refresh $TTHEME_ORDER
2237
- msg=${${out//$'\n'/ }:-"Saved · no background pictures to draw"} msgt=300
2238
- }
2239
-
2240
- __tt_pv_conf_panel() {
2241
- local z=$'\e[0m' b=$'\e[1m' d=$'\e[2m' c=$ac on=$'\e[7;1m'$ac var v note
2242
- local -a ch sh
2243
- local -i r0=$1 col=$2 end=$3 k i j fit=1
2244
- (( color )) || z= b= d= c= on=
2245
- for (( k = 1; k <= ${#cvars}; k++ )); do
2246
- sh=(${=cshow[k]})
2247
- (( 13 + ${#${(j: :)sh}} + 2 * ${#sh} > end - col + 1 )) && fit=0
2248
- done
2249
- for (( k = 1; k <= ${#cvars}; k++ )); do
2250
- var=${cvars[k]} ch=(${=cchoice[k]}) sh=(${=cshow[k]})
2251
- i=${ch[(Ie)${(P)var}]}
2252
- out+=$'\e['$(( r0 + k - 1 ))';'$col'H'
2253
- if (( k == cf )); then
2254
- out+=$c"▶"$z" "$b
2255
- else
2256
- out+=" "$d
2257
- fi
2258
- out+=${(r:11:)clabel[k]}$z
2259
- if (( ! fit )); then
2260
- v=${(P)var}
2261
- (( i )) && v=${sh[i]}
2262
- if (( k == cf )); then
2263
- out+=$c"‹ "$z$b$v$z$c" ›"$z
2264
- else
2265
- out+=" "$v
2266
- fi
2267
- continue
2268
- fi
2269
- for (( j = 1; j <= ${#sh}; j++ )); do
2270
- (( j > 1 )) && out+=" "
2271
- if (( j != i )); then
2272
- out+=$d" ${sh[j]} "$z
2273
- elif (( ! color )); then
2274
- out+="[${sh[j]}]"
2275
- elif (( k == cf )); then
2276
- out+=$on" ${sh[j]} "$z
2277
- else
2278
- out+=" ${sh[j]} "
2279
- fi
2280
- done
2281
- done
2282
- var=${cvars[cf]}
2283
- note=${cnote[$var:${(P)var}]}
2284
- [[ -n $note ]] && out+=$'\e['$(( r0 + ${#cvars} + 1 ))';'$col'H'$d${note[1,end-col+1]}$z
2285
- return 0
2286
- }
2287
-
2288
- __tt_pv_flush() {
2289
- local REPLY
2290
- print -rn -- "$out"
2291
- if (( wiped )); then
2292
- local bn=$bgname
2293
- if [[ ${rtype[cur]} == thm ]]; then
2294
- __tt_pv_shows ${rval[cur]}
2295
- bn=$REPLY
2296
- fi
2297
- [[ -n $bn ]] && __tt_pv_bg_show "$bn" 1
2298
- fi
2299
- if [[ -n $bgstrip ]]; then
2300
- __tt_pv_bg_strip ${=bgstrip}
2301
- elif (( ${#bgthumb} )); then
2302
- __tt_pv_bg_strip_off
2303
- fi
2304
- printf '\e[1;%dH\e[?2026l' $(( 4 + ${(m)#flt} ))
2305
- }
2306
-
2307
- __tt_pv_reach() {
2308
- local key=${pkeys[pk]} base top k home=${HOME:a} here=${PWD:a} htip="" d=$'\e[2m' z=$'\e[0m' REPLY
2309
- local -A own=() below=() parent=() mark=() tstrip=()
2310
- local -a roots=() lp=() lpw=() ll=() lat=() lpal=() lnote=() lflag=() reply was=()
2311
- local -A TTHEME_PINS=("${(@kv)TTHEME_PINS}")
2312
- local -i room=$2
2313
- (( color )) || d= z=
2314
- (( room < 2 )) && room=2
2315
- if [[ $key == ssh:* ]]; then
2316
- __tt_pin_scope "$key"
2317
- [[ -n ${TTHEME_PINS[$key]} && $TTHEME_PINS[$key] != "$pick" ]] && was+=("${TTHEME_PINS[$key]} · $REPLY")
2318
- TTHEME_PINS[$key]=$pick
2319
- mark[$key]=new
2320
- __tt_map_ssh
2321
- else
2322
- __tt_pin_base "$key"
2323
- base=$REPLY
2324
- for k in ${(k)TTHEME_PINS}; do
2325
- [[ $k == /* ]] || continue
2326
- __tt_pin_base "$k"
2327
- [[ $REPLY == "$base" ]] || continue
2328
- if [[ $k != "$key" || $TTHEME_PINS[$k] != "$pick" ]]; then
2329
- __tt_pin_scope "$k"
2330
- was+=("${TTHEME_PINS[$k]} · $REPLY")
2331
- fi
2332
- unset "TTHEME_PINS[$k]"
2333
- done
2334
- TTHEME_PINS[$key]=$pick
2335
- top=$base
2336
- [[ $base != / ]] && __tt_pin_cover "${base:h}" && __tt_pin_base "$REPLY" && top=$REPLY
2337
- mark[$base]=new
2338
- __tt_map_build "$top"
2339
- fi
2340
- __tt_map_fit $1
2341
- (( ${#reply} > room )) && reply=("${(@)reply[1,room-1]}" " …")
2342
- reach=("${reply[@]}")
2343
- [[ $key == /* || ${#was} -gt 0 ]] && reach+=("")
2344
- __tt_pin_where "$key"
2345
- base=$REPLY
2346
- for k in $was; do
2347
- __tt_clip "${d}Replaces ${k% · *} on $base · ${k##* · }$z" $1
2348
- reach+=("$REPLY")
2349
- done
2350
- __tt_pin_scope "$key"
2351
- __tt_clip "→ $base · $REPLY" $(( $1 - ${(m)#pick} - 2 ))
2352
- rsub=$REPLY
2353
- [[ $key == /* ]] || return 0
2354
- __tt_here_fit "Then here" $1
2355
- reach+=("${reply[@]}")
2356
- }
2357
-
2358
- __tt_pv_draw() {
2359
- local out line cnt ex ag="" acat="" ac="" sb="" dd="" zz="" state=on src="" nflt="" rsub="" REPLY
2360
- local -i lw sw split sc se=$(( pw - 2 )) h k i N=${#rval} mt=${#TTHEME_ORDER} wiped=0
2361
- local -a held
2362
- bgstrip=""
2363
- if [[ -n $flt ]]; then
2364
- __tt_pv_norm "$flt"
2365
- nflt=$REPLY
2366
- fi
2367
- if (( te )) && [[ -n $tespec && $tespec != "$applied" ]]; then
2368
- __tt_pv_paint "$tespec"
2369
- applied=$tespec
2370
- fi
2371
- __tt_pv_lw
2372
- lw=$reply[1] sw=$reply[2]
2373
- split=$(( sw > 0 )) sc=$(( pw - 1 - sw ))
2374
- h=$(( ph - 5 ))
2375
- (( conf && ! split )) && h=$(( ph - 6 - ${#cvars} ))
2376
- reach=()
2377
- if [[ -n $pick && $mode == pin ]]; then
2378
- if (( split )); then
2379
- __tt_pv_reach $sw $(( ph - 6 ))
2380
- else
2381
- __tt_pv_reach $se $(( ph - 13 ))
2382
- h=$(( ph - 6 - ${#reach} ))
2383
- fi
2384
- fi
2385
- (( h < 1 )) && h=1
2386
- (( cur < top )) && top=$cur
2387
- (( cur >= top + h )) && top=$(( cur - h + 1 ))
2388
- (( top < 1 )) && top=1
2389
- (( N > h && top > N - h + 1 )) && top=$(( N - h + 1 ))
2390
- if (( color )); then
2391
- dd=$'\e[2m' zz=$'\e[0m'
2392
- if [[ -n $applied ]]; then
2393
- local -a ap=(${=applied})
2394
- local acx=${ap[3]#\#} sbx=${ap[4]#\#}
2395
- printf -v ac '\e[38;2;%d;%d;%dm' $((16#${acx:0:2})) $((16#${acx:2:2})) $((16#${acx:4:2}))
2396
- printf -v sb '\e[48;2;%d;%d;%dm' $((16#${sbx:0:2})) $((16#${sbx:2:2})) $((16#${sbx:4:2}))
2397
- fi
2398
- if [[ ${rtype[cur]} == thm ]]; then
2399
- ag=${TTHEME_GROUP[${rval[cur]}]:-Other}
2400
- [[ -n ${TTHEME_CATALOG[${rval[cur]}]} ]] && acat=$ag/${TTHEME_CATALOG[${rval[cur]}]}
2401
- fi
2402
- fi
2403
- if [[ -n $flt ]]; then
2404
- local -a mm=(${(M)rtype:#thm})
2405
- mt=${#mm}
2406
- fi
2407
- cnt="$mt/${#TTHEME_ORDER}"
2408
- out=$'\e[H'
2409
- if (( resized )); then
2410
- out+=$'\e[K\e[2H\e[J\e[H'
2411
- (( bgcw )) && out+=$'\e_Ga=d,d=A,q=2\e\\'
2412
- resized=0 wiped=1
2413
- fi
2414
- if (( pw < 40 || ph < 12 )); then
2415
- line="ttheme preview"
2416
- (( color )) && line=$'\e[1m'$ac$line$'\e[0m'
2417
- out+=$line$'\e[K\n'"Needs 40×12 — now ${pw}×${ph}"$'\e[K\n'
2418
- line="esc quits"
2419
- (( color )) && line=$'\e[2m'$line$'\e[0m'
2420
- out+=$line$'\e[K\e[J'
2421
- __tt_pv_flush
2422
- return 0
2423
- fi
2424
- if (( te && ! split )); then
2425
- __tt_pv_te_draw
2426
- return 0
2427
- fi
2428
- if [[ -n $flt ]]; then
2429
- if (( color )); then
2430
- line=" "$'\e[1m'$flt$zz$ac$'\e[7m \e[0m'
2431
- else
2432
- line=" ${flt}_"
2433
- fi
2434
- else
2435
- ex="$expal | $exgrp"
2436
- (( ${#ex} > lw - 19 - ${#cnt} )) && ex="${ex[1,lw-20-${#cnt}]}…"
2437
- if (( gstep > 0 )); then
2438
- local gkeep=$(( ${#ex} * (8 - gstep) / 8 ))
2439
- if [[ $TTHEME_FX == (decode|glitch) ]]; then
2440
- local gpool='▓▒░#*+=<>?/-_' gstill=' ' gout="" gi
2441
- [[ $TTHEME_FX == decode ]] && gpool='abcdefghijklmnopqrstuvwxyz' gstill='[^[:alnum:]]'
2442
- for (( gi = 1; gi <= ${#ex}; gi++ )); do
2443
- if (( gi + (gi * 7 + gseed) % 3 <= gkeep )) || [[ ${ex[gi]} == $~gstill ]]; then
2444
- gout+=${ex[gi]}
2445
- else
2446
- gout+=${gpool[RANDOM % ${#gpool} + 1]}
2447
- fi
2448
- done
2449
- ex=$gout
2450
- else
2451
- ex="${ex[1,gkeep]}▏"
2452
- fi
2453
- fi
2454
- line=" "$dd"Search… e.g. $ex"$zz
2455
- fi
2456
- local tail=$'\e['$(( lw - ${#cnt} ))'G'$dd$cnt$zz
2457
- [[ -n $flt ]] && tail=$'\e['$(( lw - ${#cnt} ))'G'$cnt
2458
- if [[ $1 == hint ]] && (( ! wiped )); then
2459
- print -rn -- $'\e['$(( 1 + hub ))$'H\e[0m\e['$lw'X'$line$tail
2460
- printf '\e[%d;%dH\e[?2026l' $(( 1 + hub )) $(( 4 + ${(m)#flt} ))
2461
- return 0
2462
- fi
2463
- if (( hub )); then
2464
- __tt_pv_bar $(( split ? sc - 2 : pw - 1 ))
2465
- out+=$REPLY$'\e[K\n'$line$'\e[K'$tail$'\n'
2466
- else
2467
- out+=$line$'\e[K'$tail$'\n\e[K\n'
2468
- fi
2469
- (( N > h && top > 1 )) && out+=" "$dd"…"$zz
2470
- out+=$'\e[K\n'
2471
- for (( k = 0; k < ph - 4; k++ )); do
2472
- i=$(( top + k ))
2473
- line=""
2474
- if (( k < h )); then
2475
- if (( ! N )); then
2476
- (( k == 0 )) && line=" ${dd}No palettes match '$flt'$zz"
2477
- elif (( i <= N )); then
2478
- __tt_pv_row $i
2479
- line=$REPLY
2480
- fi
2481
- elif (( k == h && N > h && top + h <= N )); then
2482
- line=" "$dd"…"$zz
2483
- fi
2484
- out+=$line$'\e[K\n'
2485
- done
2486
- __tt_pv_foot $(( split ? se : pw ))
2487
- if (( split )); then
2488
- if (( help && sw >= 48 )); then
2489
- __tt_pv_head 1 $sc $se Help
2490
- __tt_pv_help
2491
- elif (( ${#reach} )); then
2492
- __tt_pv_head 1 $sc $se "$pick" "$rsub"
2493
- for (( k = 1; k <= ${#reach} && k + 2 < ph; k++ )); do
2494
- out+=$'\e['$(( k + 2 ))';'$sc'H'${reach[k]}
2495
- done
2496
- elif (( conf )); then
2497
- __tt_tilde "$TTHEME_CONFIG"
2498
- src=$REPLY
2499
- (( 8 + ${#src} > sw )) && src=""
2500
- __tt_pv_head 1 $sc $se Config "" "$src"
2501
- __tt_pv_conf_panel 4 $sc $se
2502
- elif (( te )); then
2503
- __tt_pv_te_head $sc $se
2504
- __tt_pv_te_panel $sc $se 3 $(( ph - 1 ))
2505
- else
2506
- [[ -n $an ]] && src=${TTHEME_SRC[$an]}
2507
- (( ${#an} + 2 + ${#src} > sw )) && src=""
2508
- __tt_pv_head 1 $sc $se ${an:-custom} "" "$src"
2509
- __tt_pv_specimen
2510
- fi
2511
- (( help && sw < 48 )) && __tt_pv_help
2512
- else
2513
- if (( ${#reach} )); then
2514
- __tt_pv_head $(( ph - 1 - ${#reach} )) 1 $se "$pick" "$rsub"
2515
- for (( k = 1; k <= ${#reach}; k++ )); do
2516
- out+=$'\e['$(( ph - 1 - ${#reach} + k ))';1H'${reach[k]}
2517
- done
2518
- elif (( conf )); then
2519
- __tt_pv_head $(( ph - 2 - ${#cvars} )) 1 $lw Config
2520
- __tt_pv_conf_panel $(( ph - 1 - ${#cvars} )) 1 $lw
2521
- fi
2522
- (( help )) && __tt_pv_help
2523
- fi
2524
- (( osdt > 0 )) && __tt_pv_osd
2525
- __tt_pv_flush
2526
- }
2527
-
2528
- __tt_pv_group() {
2529
- local k g
2530
- groups=() gthemes=()
2531
- __tt_order
2532
- for k in $reply; do
2533
- g=${TTHEME_GROUP[$k]:-Other}
2534
- [[ -n ${gthemes[$g]} ]] || groups+=($g)
2535
- gthemes[$g]+=" $k"
2536
- done
2537
- }
2538
-
2539
- __tt_pv_canpick() {
2540
- canpick=0
2541
- if [[ $mode == pin ]]; then
2542
- canpick=1
2543
- elif __tt_keepable && [[ $TTHEME_TAB_PALETTE == off ]]; then
2544
- canpick=1
2545
- fi
2546
- }
2547
-
2548
- __tt_pv_strip() {
2549
- local hex cell=""
2550
- local -a sw=(${=TTHEME_SWATCH[$1]})
2551
- local -i j
2552
- for (( j = 1; j <= 6; j++ )); do
2553
- hex=${sw[j]#\#}
2554
- (( j > 1 )) && cell+=" "
2555
- if [[ -n $hex ]]; then
2556
- cell+=$'\e[38;2;'$((16#${hex:0:2}))';'$((16#${hex:2:2}))';'$((16#${hex:4:2}))'m■'
2557
- else
2558
- cell+=" "
2559
- fi
2560
- done
2561
- tstrip[$1]=$cell$'\e[39m'
2562
- }
2563
-
2564
- __tt_pv_init() {
2565
- local lo
2566
- local -a tp
2567
- __tt_pv_group
2568
- [[ -n $orig ]] && __tt_name_of "$orig" && cn=$REPLY
2569
- [[ -n ${TTHEME_PALETTE[$cn]} ]] || return 0
2570
- cdot="◆"
2571
- (( color )) || return 0
2572
- tp=(${=TTHEME_PALETTE[$cn]})
2573
- lo=${tp[3]#\#}
2574
- printf -v cdot '\e[38;2;%d;%d;%dm◆\e[39m' $((16#${lo:0:2})) $((16#${lo:2:2})) $((16#${lo:4:2}))
2575
- }
2576
-
2577
- __tt_pv_roll() {
2578
- expal=${TTHEME_ORDER[RANDOM % ${#TTHEME_ORDER} + 1]}
2579
- exgrp=${groups[RANDOM % ${#groups} + 1]}
2580
- gseed=$RANDOM
2581
- exnext=$(( SECONDS + 3 ))
2582
- }
2583
-
2584
- __tt_pv_size() {
2585
- local sz=$(stty size 2>/dev/null)
2586
- [[ $sz == <1->" "<1-> ]] || return 1
2587
- [[ $sz == "$ph $pw" ]] && return 1
2588
- ph=${sz%% *} pw=${sz##* } resized=1
2589
- return 0
2590
- }
2591
-
2592
- __tt_pv_getch() {
2593
- if (( $# )); then
2594
- read -sk 1 -t $1 2>/dev/null
2595
- return
2596
- fi
2597
- local -F t=0.2 at
2598
- local -i quick=0
2599
- (( gstep )) && t=0.06
2600
- while :; do
2601
- at=$EPOCHREALTIME
2602
- read -sk 1 -t $t 2>/dev/null && return 0
2603
- if (( EPOCHREALTIME - at < t / 4 )); then
2604
- (( ++quick >= 5 )) && { pvgone=1; return 1 }
2605
- else
2606
- quick=0
2607
- fi
2608
- [[ -t 0 ]] || return 1
2609
- __tt_pv_size && return 1
2610
- if (( osdt > 0 )); then
2611
- (( osdt -= gstep ? 6 : 20 ))
2612
- (( osdt > 0 )) || return 1
2613
- fi
2614
- if (( msgt > 0 )); then
2615
- (( msgt -= gstep ? 6 : 20 ))
2616
- (( msgt > 0 )) || return 1
2617
- fi
2618
- (( gstep )) && { gstep=$(( gstep - 1 )); tick=1; return 1 }
2619
- (( ! te && SECONDS >= exnext )) && { __tt_pv_roll; gstep=8; tick=1; return 1 }
2620
- done
2621
- }
2622
-
2623
- __tt_pv_read() {
2624
- key=""
2625
- if (( $# )); then
2626
- __tt_pv_getch 0 || return 1
2627
- else
2628
- __tt_pv_getch || return 1
2629
- fi
2630
- key=$REPLY
2631
- [[ $key == ç ]] && key=altc
2632
- [[ $key == $'\e' ]] || return 0
2633
- local seq=""
2634
- if ! __tt_pv_getch 0.05; then
2635
- key=esc
2636
- return 0
2637
- fi
2638
- if [[ $REPLY != '[' && $REPLY != O ]]; then
2639
- key=nop
2640
- [[ $REPLY == c ]] && key=altc
2641
- return 0
2642
- fi
2643
- while __tt_pv_getch 0.05; do
2644
- seq+=$REPLY
2645
- [[ $REPLY == [A-Za-z~] ]] && break
2646
- done
2647
- case $seq in
2648
- A) key=up ;;
2649
- B) key=down ;;
2650
- C) key=right ;;
2651
- D) key=left ;;
2652
- H|"1~"|"7~") key=home ;;
2653
- F|"4~"|"8~") key=end ;;
2654
- "5~") key=pgup ;;
2655
- "6~") key=pgdn ;;
2656
- "1;2C") key=sright ;;
2657
- "1;2D") key=sleft ;;
2658
- "27;2;13~"|"13;2u") key=senter ;;
2659
- Z) key=stab ;;
2660
- *) key=nop ;;
2661
- esac
2662
- }
2663
-
2664
- __tt_pv_pick() {
2665
- case $key in
2666
- $'\x03') return 1 ;;
2667
- esc) pick="" ;;
2668
- left|stab) pk=$(( (pk + ${#plabel} - 2) % ${#plabel} + 1 )) ;;
2669
- right|$'\t') pk=$(( pk % ${#plabel} + 1 )) ;;
2670
- $'\r'|$'\n'|senter)
2671
- sel=$pick picked=$pk
2672
- return 1
2673
- ;;
2674
- esac
2675
- return 0
2676
- }
2677
-
2678
- __tt_pv_screen() {
2679
- local err
2680
- local -i at=${TTHEME_HUB_TABS[(Ie)preview]} n=${#TTHEME_HUB_TABS} rc
2681
- local -i to=$(( (at - 1 + $1 + n) % n + 1 ))
2682
- __tt_pv_bg_close
2683
- while (( to != at )); do
2684
- hubwas="$TTHEME_STARTUP ${TTHEME_PALETTE[$TTHEME_STARTUP]}"
2685
- err=$(TTHEME_HUB=${TTHEME_HUB_TABS[to]} __tt_cli ${TTHEME_HUB_TABS[to]} 2>&1 >/dev/tty)
2686
- rc=$?
2687
- if (( rc == TTHEME_HUB_CLOSED )); then
2688
- hubleft=1
2689
- return 1
2690
- elif (( rc > TTHEME_HUB_SWITCH && rc <= TTHEME_HUB_SWITCH + n )); then
2691
- to=$(( rc - TTHEME_HUB_SWITCH ))
2692
- else
2693
- err=${${err//$'\n'/ }## #}
2694
- msg=${err:-"${TTHEME_HUB_TITLES[to]} failed"} msgt=300
2695
- to=$at
2696
- fi
2697
- done
2698
- printf '\e[?2026h\e[?25l'
2699
- if [[ -n $applied ]]; then
2700
- __tt_pv_paint "$applied"
2701
- else
2702
- __tt_osc_reset
2703
- painted=""
2704
- fi
2705
- resized=1 bgname="" bgshown="" bgdim=()
2706
- return 0
2707
- }
2708
-
2709
- __tt_te_stop() {
2710
- setopt localoptions nomonitor nonotify
2711
- (( TE_IN )) && { print -r -u $TE_IN -- quit 2>/dev/null; exec {TE_IN}>&- }
2712
- (( TE_OUT )) && exec {TE_OUT}<&-
2713
- TE_IN=0 TE_OUT=0
2714
- (( TE_PID )) && { kill $TE_PID 2>/dev/null; wait $TE_PID 2>/dev/null }
2715
- TE_PID=0
2716
- return 0
2717
- }
2718
-
2719
- __tt_te_ask() {
2720
- local line
2721
- (( TE_IN && TE_OUT )) || return 1
2722
- print -r -u $TE_IN -- "$1" 2>/dev/null || { __tt_te_stop; return 1 }
2723
- if ! IFS= read -r -u $TE_OUT -t 5 line 2>/dev/null; then
2724
- __tt_te_stop
2725
- msg="The palette panel stopped" msgt=300
2726
- return 1
2727
- fi
2728
- teframe=("${(@ps:\x1f:)line}")
2729
- temode=${teframe[3]:-list}
2730
- tedirty=${teframe[4]:-0}
2731
- [[ ${teframe[1]} == error ]] && { msg=${teframe[8]:-"Could not save the tone"} msgt=300 }
2732
- [[ -n ${teframe[5]} ]] && tespec=${teframe[5]}
2733
- return 0
2734
- }
2735
-
2736
- __tt_te_unsaved_image() {
2737
- local img
2738
- for img in ${(k)tsnaps}; do
2739
- [[ "${bgsize[$img]} ${bgpos[$img]} ${bgop[$img]} ${bgoff[$img]}" == "${tsnaps[$img]}" ]] || return 0
2740
- done
2741
- [[ -n $tune && $tpick != "${bgview[$tune]:-$tune}" ]] && return 0
2742
- return 1
2743
- }
2744
-
2745
- __tt_te_unsaved() {
2746
- (( tedirty )) && return 0
2747
- __tt_te_unsaved_image
2748
- }
2749
-
2750
- __tt_te_save_image() {
2751
- __tt_te_unsaved_image || return 0
2752
- __tt_pv_tune_keep
2753
- __tt_pv_bg_save > /dev/null 2>&1
2754
- bgedit=() bgswap=() bgview=()
2755
- __tt_pv_bg_reset $tename
2756
- bgload[$tename]=""
2757
- __tt_pv_tune_open $tename
2758
- }
2759
-
2760
- __tt_te_open() {
2761
- local name=$1
2762
- local -i rfd wfd
2763
- setopt localoptions nomonitor nonotify
2764
- coproc __tt_cli tone $name 2>/dev/null
2765
- exec {rfd}<&p {wfd}>&p
2766
- TE_OUT=$rfd TE_IN=$wfd TE_PID=$!
2767
- tename=$name tfocus=0 tespec="" tesz="" teframe=() tedirty=0 temode=list tetop=0 msgt=0
2768
- if ! __tt_te_ask "focus 1"; then
2769
- msg="Could not start the palette panel for $name" msgt=300
2770
- __tt_te_stop
2771
- return 0
2772
- fi
2773
- te=1
2774
- (( bgcw )) && __tt_pv_bg_state $name && __tt_pv_tune_open $name
2775
- __tt_te_image && __tt_te_to_image 1
2776
- resized=1
2777
- return 0
2778
- }
2779
-
2780
- __tt_te_close() {
2781
- [[ -n $tune ]] && __tt_pv_untune
2782
- __tt_te_stop
2783
- te=0 tfocus=0 tename="" tespec="" tesz="" teframe=() tetop=0 help=0 pick=""
2784
- resized=1 bgname=""
2785
- return 0
2786
- }
2787
-
2788
- __tt_te_save() {
2789
- __tt_te_save_image
2790
- if (( tedirty )); then
2791
- __tt_te_ask save || return 1
2792
- if [[ ${teframe[1]} == saved ]]; then
2793
- __tt_palettes_load && __tt_reloaded
2794
- __tt_reload
2795
- applied=${TTHEME_PALETTE[$tename]:-$applied}
2796
- tespec=$applied
2797
- else
2798
- return 1
2799
- fi
2800
- fi
2801
- msg="Saved" msgt=200
2802
- return 0
2803
- }
2804
-
2805
- __tt_te_apply() {
2806
- if __tt_te_unsaved; then
2807
- __tt_te_save || return 0
2808
- fi
2809
- if (( canpick )); then
2810
- pick=$tename pk=$pkdef
2811
- return 0
2812
- fi
2813
- sel=$tename
2814
- return 1
2815
- }
2816
-
2817
- __tt_te_image() {
2818
- [[ -n $tune ]] || __tt_pv_bg_findable $tename
2819
- }
2820
-
2821
- __tt_te_to_image() {
2822
- tfocus=1 tf=5
2823
- [[ $1 == last && -n $tune ]] && tf=3
2824
- __tt_te_ask "focus 0"
2825
- }
2826
-
2827
- __tt_te_to_palette() {
2828
- tfocus=0
2829
- __tt_te_ask "focus 1" && __tt_te_ask "key $1"
2830
- }
2831
-
2832
- __tt_te_to_apply() {
2833
- tfocus=2
2834
- __tt_te_ask "focus 0"
2835
- }
2836
-
2837
- __tt_te_to_top() {
2838
- if __tt_te_image; then
2839
- __tt_te_to_image first
2840
- else
2841
- __tt_te_to_palette home
2842
- fi
2843
- }
2844
-
2845
- __tt_te_find() {
2846
- local name=$tename
2847
- __tt_pv_bg_findable $name || return 0
2848
- __tt_te_save_image
2849
- __tt_pv_untune
2850
- __tt_pv_bg_find $name
2851
- __tt_pv_bg_state $name && __tt_pv_tune_open $name
2852
- tf=5
2853
- return 0
2854
- }
2855
-
2856
- __tt_te_key() {
2857
- local m
2858
- if [[ $temode == list ]]; then
2859
- case $key in
2860
- home) __tt_te_to_top; return 0 ;;
2861
- end) __tt_te_to_apply; return 0 ;;
2862
- esac
2863
- fi
2864
- case $key in
2865
- up|down|left|right|home|end|pgup|pgdn|esc) m="key $key" ;;
2866
- sleft) m="key shift-left" ;;
2867
- sright) m="key shift-right" ;;
2868
- stab) m="key shift-tab" ;;
2869
- $'\t') m="key tab" ;;
2870
- $'\r'|$'\n') m="key enter" ;;
2871
- $'\x7f'|$'\x08') m="key backspace" ;;
2872
- $'\x03') m="key ctrl-c" ;;
2873
- nop|altc) return 0 ;;
2874
- *)
2875
- (( ${#key} == 1 )) || return 0
2876
- m="ch $(( #key ))"
2877
- ;;
2878
- esac
2879
- __tt_te_ask "$m" || { __tt_te_close; return 0 }
2880
- case ${teframe[2]} in
2881
- save) __tt_te_save ;;
2882
- cancel) __tt_te_close ;;
2883
- below) __tt_te_to_apply ;;
2884
- above)
2885
- if __tt_te_image; then
2886
- __tt_te_to_image last
2887
- else
2888
- __tt_te_to_apply
2889
- fi
2890
- ;;
2891
- esac
2892
- return 0
2893
- }
2894
-
2895
- __tt_pv_te_image() {
2896
- local -a order=(5)
2897
- local -i i
2898
- [[ -n $tune ]] && order=(5 4 1 2 3)
2899
- i=${order[(Ie)$tf]}
2900
- (( i )) || { tf=5; i=1 }
2901
- case $key in
2902
- s) __tt_te_save ;;
2903
- esc) __tt_te_close ;;
2904
- up|k)
2905
- if (( i > 1 )); then
2906
- tf=${order[i-1]}
2907
- else
2908
- __tt_te_to_apply
2909
- fi
2910
- ;;
2911
- down|j)
2912
- if (( i < ${#order} )); then
2913
- tf=${order[i+1]}
2914
- else
2915
- __tt_te_to_palette home
2916
- fi
2917
- ;;
2918
- home) tf=5 ;;
2919
- end) __tt_te_to_apply ;;
2920
- $'\r'|$'\n') [[ -n $tune ]] || __tt_te_find ;;
2921
- f) __tt_te_find ;;
2922
- left|right|sleft|sright)
2923
- if (( tf == 5 )); then
2924
- if [[ -z $tune ]]; then
2925
- :
2926
- elif [[ $key == *left ]]; then
2927
- __tt_pv_bg_pick -1
2928
- else
2929
- __tt_pv_bg_pick 1
2930
- fi
2931
- elif [[ -n $tune ]]; then
2932
- __tt_pv_tune
2933
- fi
2934
- ;;
2935
- '=') [[ -n $tune ]] && (( tf != 5 )) && __tt_pv_tune ;;
2936
- *) [[ -n $tune ]] && __tt_pv_tune ;;
2937
- esac
2938
- [[ -n $tune ]] || tf=5
2939
- return 0
2940
- }
2941
-
2942
- __tt_te_button() {
2943
- case $key in
2944
- $'\r'|$'\n') __tt_te_apply; return $? ;;
2945
- s) __tt_te_save ;;
2946
- esc) __tt_te_close ;;
2947
- up|k) __tt_te_to_palette end ;;
2948
- down|j|home) __tt_te_to_top ;;
2949
- esac
2950
- return 0
2951
- }
2952
-
2953
- __tt_pv_te() {
2954
- case $key in
2955
- $'\x03') return 1 ;;
2956
- $'\x05') return 0 ;;
2957
- senter) __tt_te_apply; return $? ;;
2958
- '?') help=1; return 0 ;;
2959
- esac
2960
- case $tfocus in
2961
- 0) __tt_te_key ;;
2962
- 1) __tt_pv_te_image ;;
2963
- *) __tt_te_button ;;
2964
- esac
2965
- return $?
2966
- }
2967
-
2968
- __tt_pv_te_head() {
2969
- local z=$'\e[0m' d=$'\e[2m' b=$'\e[1m' y=$'\e[33m' line REPLY
2970
- local -i col=$1 end=$2 room=$(( $2 - $1 + 1 ))
2971
- (( color )) || z= d= b= y=
2972
- __tt_te_unsaved && (( room -= 11 ))
2973
- line=$b$ac"◆"$z" "$b$tename$z
2974
- [[ -n ${TTHEME_GROUP[$tename]} ]] && line+=" "$d"· ${TTHEME_GROUP[$tename]}"$z
2975
- __tt_clip "$line" $room
2976
- out+=$'\e[1;'$col'H'$REPLY$z
2977
- __tt_te_unsaved && out+=$'\e[1;'$(( end - 8 ))'H'$y"●"$z" "$d"unsaved"$z
2978
- return 0
2979
- }
2980
-
2981
- __tt_pv_te_tile() {
2982
- local z=$'\e[0m' d=$'\e[2m' b=$'\e[1m' sty top side bot
2983
- local -i y=$1 col=$2 r tc=10
2984
- (( color )) || z= d= b=
2985
- if (( tfocus == 1 && tf == 5 )); then
2986
- sty=$b$ac top="┏${(l:tc::━:)}┓" side="┃" bot="┗${(l:tc::━:)}┛"
2987
- else
2988
- sty=$d top="╭${(l:tc::─:)}╮" side="│" bot="╰${(l:tc::─:)}╯"
2989
- fi
2990
- out+=$'\e['$y';'$col'H'$sty$top$z
2991
- for (( r = 1; r <= 3; r++ )); do
2992
- out+=$'\e['$(( y + r ))';'$col'H'$sty$side${(l:tc::░:)}$side$z
2993
- done
2994
- out+=$'\e['$(( y + 4 ))';'$col'H'$sty$bot$z$'\e['$(( y + 2 ))';'$(( col + tc + 4 ))'H'
2995
- if (( tfocus == 1 && tf == 5 )); then
2996
- out+=$b"enter"$z$d" finds one"$z
2997
- else
2998
- out+=$d"enter finds one"$z
2999
- fi
3000
- return 0
3001
- }
3002
-
3003
- __tt_pv_te_ghost() {
3004
- local z=$'\e[0m' d=$'\e[2m'
3005
- local -i r0=$1 col=$2 T=$(( $3 - $2 - 21 )) i
3006
- (( color )) || z= d=
3007
- (( T < 8 )) && T=8
3008
- out+=$'\e['$r0';'$col'H '$d"Colors"$'\e['$r0';'$(( col + 12 ))'H'" tone original "$z
3009
- out+=$'\e['$(( r0 + 1 ))';'$col'H '$d"Size"$'\e['$(( r0 + 1 ))';'$(( col + 12 ))'H'${(l:T::─:)}$z
3010
- for (( i = 1; i <= 9; i++ )); do
3011
- out+=$'\e['$(( r0 + 3 + (i - 1) / 3 ))';'$(( col + 12 + (i - 1) % 3 * 3 ))'H'$d"·"$z
3012
- done
3013
- out+=$'\e['$(( r0 + 4 ))';'$col'H '$d"Position"$z
3014
- out+=$'\e['$(( r0 + 7 ))';'$col'H '$d"Opacity"$'\e['$(( r0 + 7 ))';'$(( col + 12 ))'H'${(l:T::─:)}$z
3015
- return 0
3016
- }
3017
-
3018
- __tt_pv_te_panel() {
3019
- local z=$'\e[0m' d=$'\e[2m' b=$'\e[1m' tt st note REPLY
3020
- local -a held
3021
- local -i col=$1 end=$2 r0=$3 r1=$4 R W T I=3 V at i n y tfs=$tf lo=15
3022
- (( color )) || z= d= b=
3023
- R=$(( r1 - r0 + 1 )) W=$(( end - col + 1 ))
3024
- [[ $temode == list ]] || lo=21
3025
- [[ -n $tune ]] || __tt_pv_bg_findable $tename && I=17
3026
- T=$(( R - I - 3 ))
3027
- (( T > 26 )) && T=26
3028
- (( T < 21 )) && T=$lo
3029
- if [[ "$W $T" != "$tesz" ]]; then
3030
- tesz="$W $T"
3031
- __tt_te_ask "size $W $T"
3032
- fi
3033
- V=$(( I + T + 3 ))
3034
- if (( V <= R || tfocus == 1 )); then
3035
- tetop=0
3036
- elif (( tfocus == 2 )); then
3037
- tetop=$(( V - R ))
3038
- else
3039
- at=$(( I + 1 + ${teframe[9]:-2} ))
3040
- (( at - 2 < tetop )) && tetop=$(( at > 2 ? at - 2 : 0 ))
3041
- (( at > tetop + R )) && tetop=$(( at - R ))
3042
- (( tetop > V - R )) && tetop=$(( V - R ))
3043
- fi
3044
- if (( tetop == 0 && I <= R )); then
3045
- y=$r0
3046
- tt=$d
3047
- (( tfocus == 1 )) && tt=$b$ac
3048
- out+=$'\e['$y';'$(( col + 2 ))'H'$tt"Image"$z
3049
- if [[ -n $tune ]]; then
3050
- (( bgoff[$tpick] )) && st=off || st=on
3051
- __tt_pv_bg_title $(( W - 14 ))
3052
- out+=" "$d$REPLY$z$'\e['$y';'$(( end - ${#st} + 1 ))'H'$d$st$z
3053
- fi
3054
- if (( I == 17 )); then
3055
- held=() n=0 note="0/0"
3056
- if [[ -n $tune ]]; then
3057
- held=(${=bgpics[$tune]})
3058
- n=${held[(Ie)${${tpick#$tune}#:}]}
3059
- (( n )) || n=${held[(Ie)${bgact[$tune]}]}
3060
- (( n )) || n=1
3061
- note="$n/$(( ${#held} ? ${#held} : 1 ))"
3062
- fi
3063
- st=" " tt=$d
3064
- (( tfocus == 1 && tf == 5 )) && st=$ac"▶"$z" " tt=$b
3065
- out+=$'\e['$(( y + 2 ))';'$col'H'$st$tt"Images"$z$'\e['$(( y + 2 ))';'$(( end - ${#note} + 1 ))'H'$d$note$z
3066
- if [[ -n $tune ]]; then
3067
- bgstrip="$(( y + 2 )) $col $end"
3068
- (( tfocus == 1 )) || tf=0
3069
- __tt_pv_bg_panel $tpick $(( y + 9 )) $col $end
3070
- tf=$tfs
3071
- else
3072
- __tt_pv_te_tile $(( y + 3 )) $col
3073
- __tt_pv_te_ghost $(( y + 9 )) $col $end
3074
- fi
3075
- elif (( bgcw )); then
3076
- out+=$'\e['$(( y + 2 ))';'$(( col + 2 ))'H'$d"No picture yet"$z
3077
- else
3078
- out+=$'\e['$(( y + 2 ))';'$(( col + 2 ))'H'$d"This terminal shows no pictures"$z
3079
- fi
3080
- fi
3081
- for (( i = 1; i <= T; i++ )); do
3082
- y=$(( r0 + I + i - tetop ))
3083
- (( y >= r0 && y <= r1 )) || continue
3084
- out+=$'\e['$y';'$col'H'${teframe[9 + i]}$z
3085
- done
3086
- y=$(( r0 + V - 1 - tetop ))
3087
- (( y >= r0 && y <= r1 )) || return 0
3088
- if [[ $mode == pin ]]; then
3089
- note="saves, then asks how far it reaches"
3090
- elif (( canpick )); then
3091
- note="saves, then asks where"
3092
- else
3093
- note="saves and wears it in this tab"
3094
- fi
3095
- out+=$'\e['$y';'$col'H'
3096
- if (( tfocus == 2 )); then
3097
- (( color )) && out+=$ac"▶"$z" "$'\e[7;1m'$ac" Apply "$z || out+="▶ [Apply]"
3098
- else
3099
- (( color )) && out+=" "$b" Apply "$z || out+=" Apply "
3100
- fi
3101
- out+=" "$d$note$z
3102
- return 0
3103
- }
3104
-
3105
- __tt_pv_te_draw() {
3106
- local -i i end=$(( pw - 2 < 66 ? pw - 2 : 66 ))
3107
- for (( i = 1; i < ph; i++ )); do
3108
- out+=$'\e['$i$';1H\e[K'
3109
- done
3110
- __tt_pv_te_head 2 $end
3111
- __tt_pv_te_panel 2 $end 3 $(( ph - 1 ))
3112
- reach=()
3113
- if [[ -n $pick && $mode == pin ]]; then
3114
- __tt_pv_reach $se $(( ph - 13 ))
3115
- if (( ${#reach} )); then
3116
- __tt_pv_head $(( ph - 1 - ${#reach} )) 1 $se "$pick" "$rsub"
3117
- for (( i = 1; i <= ${#reach}; i++ )); do
3118
- out+=$'\e['$(( ph - 1 - ${#reach} + i ))$';1H\e[K'${reach[i]}
3119
- done
3120
- fi
3121
- fi
3122
- (( help )) && __tt_pv_help
3123
- out+=$'\e['$ph';1H'
3124
- __tt_pv_foot $pw
3125
- (( osdt > 0 )) && __tt_pv_osd
3126
- __tt_pv_flush
3127
- }
3128
-
3129
- __tt_pv_handle() {
3130
- local name
3131
- if (( help )); then
3132
- case $key in
3133
- $'\x03') return 1 ;;
3134
- '?'|esc) help=0 ;;
3135
- esac
3136
- return 0
3137
- fi
3138
- if [[ -n $pick ]]; then
3139
- __tt_pv_pick
3140
- return
3141
- fi
3142
- if (( te )); then
3143
- __tt_pv_te
3144
- return
3145
- fi
3146
- if [[ -n $tune ]]; then
3147
- __tt_pv_tune
3148
- return
3149
- fi
3150
- if (( conf )); then
3151
- __tt_pv_conf
3152
- return
3153
- fi
3154
- case $key in
3155
- $'\x03') return 1 ;;
3156
- esc|$'\x15')
3157
- if [[ -z $flt ]]; then
3158
- [[ $key == esc ]] && return 1
3159
- else
3160
- name=""
3161
- [[ ${rtype[cur]} == thm ]] && name=${rval[cur]}
3162
- flt=""
3163
- if [[ -n $name ]]; then
3164
- __tt_pv_goto "$name"
3165
- else
3166
- __tt_pv_rows
3167
- (( cur > ${#rval} )) && cur=${#rval}
3168
- (( cur < 1 )) && cur=1
3169
- fi
3170
- fi
3171
- ;;
3172
- $'\r'|$'\n'|senter)
3173
- if [[ ${rtype[cur]} == thm ]]; then
3174
- if (( canpick )); then
3175
- pick=${rval[cur]} pk=$pkdef
3176
- else
3177
- sel=${rval[cur]}
3178
- return 1
3179
- fi
3180
- elif [[ ${rtype[cur]} == (hdr|cat) ]]; then
3181
- __tt_pv_toggle
3182
- fi
3183
- ;;
3184
- up)
3185
- if (( cur > 1 )); then
3186
- cur=$(( cur - 1 ))
3187
- [[ ${rtype[cur]} == rule ]] && cur=$(( cur - 1 ))
3188
- elif (( ${#rval} )); then
3189
- cur=${#rval}
3190
- fi
3191
- ;;
3192
- down)
3193
- if (( cur < ${#rval} )); then
3194
- cur=$(( cur + 1 ))
3195
- [[ ${rtype[cur]} == rule ]] && cur=$(( cur + 1 ))
3196
- elif (( ${#rval} )); then
3197
- cur=1
3198
- fi
3199
- ;;
3200
- right)
3201
- if [[ ${rtype[cur]} == thm ]]; then
3202
- __tt_te_open ${rval[cur]}
3203
- elif [[ ${rtype[cur]} == (hdr|cat) && -z ${exp[${rval[cur]}]} ]]; then
3204
- __tt_pv_toggle
3205
- fi
3206
- ;;
3207
- $'\x05') [[ ${rtype[cur]} == thm ]] && __tt_te_open ${rval[cur]} ;;
3208
- left) __tt_pv_left ;;
3209
- home) cur=1 ;;
3210
- end) (( ${#rval} )) && cur=${#rval} ;;
3211
- pgup)
3212
- if (( cur <= 1 )); then
3213
- (( ${#rval} )) && cur=${#rval}
3214
- else
3215
- cur=$(( cur - ph + 5 ))
3216
- (( cur < 1 )) && cur=1
3217
- [[ ${rtype[cur]} == rule ]] && cur=$(( cur - 1 ))
3218
- fi
3219
- ;;
3220
- pgdn)
3221
- if (( cur >= ${#rval} )); then
3222
- cur=1
3223
- else
3224
- cur=$(( cur + ph - 5 ))
3225
- (( cur > ${#rval} )) && cur=${#rval}
3226
- [[ ${rtype[cur]} == rule ]] && cur=$(( cur + 1 ))
3227
- fi
3228
- ;;
3229
- ' ') [[ ${rtype[cur]} == (hdr|cat) ]] && __tt_pv_toggle ;;
3230
- $'\t')
3231
- if [[ ${rtype[cur]} == thm ]]; then
3232
- __tt_te_open ${rval[cur]}
3233
- elif (( hub )); then
3234
- __tt_pv_screen 1 || return 1
3235
- fi
3236
- ;;
3237
- stab) (( hub )) && { __tt_pv_screen -1 || return 1 } ;;
3238
- altc)
3239
- conf=1 cf=1 csnap=()
3240
- for name in $cvars; do
3241
- csnap+=("${(P)name}")
3242
- done
3243
- ;;
3244
- '?') help=1 ;;
3245
- sleft) (( --scene )) ;;
3246
- sright) (( ++scene )) ;;
3247
- $'\x7f'|$'\x08')
3248
- if [[ -n $flt ]]; then
3249
- name=""
3250
- [[ ${rtype[cur]} == thm ]] && name=${rval[cur]}
3251
- flt=${flt%?}
3252
- __tt_pv_rows
3253
- __tt_pv_first "$name"
3254
- fi
3255
- ;;
3256
- [[:print:]])
3257
- __tt_pv_lw
3258
- (( ${(m)#flt} + ${(m)#key} > reply[1] - 12 )) && return 0
3259
- name=""
3260
- [[ ${rtype[cur]} == thm ]] && name=${rval[cur]}
3261
- flt+=${(L)key}
3262
- __tt_pv_rows
3263
- __tt_pv_first "$name"
3264
- ;;
3265
- esac
3266
- return 0
3267
- }
3268
-
3269
- __tt_preview() {
3270
- emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
3271
- zmodload -F zsh/datetime p:EPOCHREALTIME 2>/dev/null
3272
- local mode=$1 pdir=${2:-$PWD} hubwas=""
3273
- local -i hub=0 hubleft=0
3274
- [[ $mode == hub ]] && hub=1
3275
- if [[ ! -t 0 || ! -t 1 ]]; then
3276
- print -u2 "ttheme ${mode:-preview}: needs a terminal"
3277
- return 1
3278
- fi
3279
- 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
3280
- local pick="" pk=1 pkdef=1 picked=0 canpick=0 bgcw=0 bgch=0 bgname="" bgshown="" bginc="" osd="" osdt=0
3281
- 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=""
3282
- local -i scene=0
3283
- local -a bgorder=()
3284
- local -A bgfrom=() bgurl=() bgby=() bgsent=() bgcost=() bgdim=() bgsrc=() bgfill=() bgfocus=() bgsize=() bgpos=() bgop=() bgdef=() bgoff=() bgbase=() bgload=() bgshot=() bgshotkey=() bgedit=() bgtunef=() bgofff=() bgimages=()
3285
- local -A bgpic=() bgpics=() bgact=() bgview=() bgswap=() bgthumb=() tsnaps=() pvseek=() bgcolors=() bgprep=()
3286
- local conf=0 cf=1
3287
- local -a plabel=(" Default " " This tab ") pkeys=() reach=() csnap=() teframe=()
3288
- local te=0 tfocus=0 tetop=0 tename="" tedirty=0 temode=list tespec="" tesz=""
3289
- local -i TE_IN=0 TE_OUT=0 TE_PID=0 pvgone=0 bgprepid=0
3290
- 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)
3291
- 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")
3292
- local -A cnote=(
3293
- TTHEME_TAB_PALETTE:seq "New tabs rotate through palettes" TTHEME_TAB_PALETTE:off "New tabs keep the terminal theme"
3294
- TTHEME_ANNOUNCE:1 "Shows the palette notice" TTHEME_ANNOUNCE:0 "Silences the palette notice"
3295
- TTHEME_FX:typewriter "The search hint types itself" TTHEME_FX:decode "The search hint decodes" TTHEME_FX:glitch "The search hint glitches in"
3296
- TTHEME_SORT:abc "Series and palettes by name" TTHEME_SORT:series "Series in the order added"
3297
- TTHEME_BG_BLUR:0 "Pictures stay sharp" TTHEME_BG_BLUR:1 "Pictures soften a little behind the text"
3298
- TTHEME_BG_BLUR:2 "Pictures soften behind the text" TTHEME_BG_BLUR:3 "Pictures blur behind the text"
3299
- TTHEME_BG_BLUR:4 "Pictures blur well behind the text"
3300
- TTHEME_BG_COLORS:tone "New pictures are tinted in one color of the palette"
3301
- TTHEME_BG_COLORS:original "New pictures keep their own colors"
3302
- )
3303
- __tt_pv_conf_rows
3304
- [[ $mode == pin ]] && __tt_pin_scopes "$pdir"
3305
- __tt_pv_canpick
3306
- __tt_pv_size
3307
- local -a groups=() rtype=() rval=() rcnt=() reply=()
3308
- local -A gthemes=() exp=() tstrip=()
3309
- __tt_color && color=1
3310
- __tt_pv_init
3311
- __tt_pv_roll
3312
- __tt_pv_rows
3313
- [[ -n ${TTHEME_PALETTE[$cn]} ]] && __tt_pv_goto "$cn"
3314
- local tty=""
3315
- local -i TTHEME_RAW=0
3316
- {
3317
- tty=$(stty -g 2>/dev/null) && stty -echo -icanon min 1 time 0 2>/dev/null || tty=""
3318
- TTHEME_RAW=$(( ${#tty} > 0 ))
3319
- __tt_pv_bg_open
3320
- printf '\e[?2026h\e[?1049h\e[?7l\e[?25l'
3321
- while :; do
3322
- printf '\e[?2026h'
3323
- if (( tick && ! te )); then
3324
- __tt_pv_draw hint
3325
- else
3326
- __tt_pv_focus
3327
- [[ ${rtype[cur]} == thm ]] && an=${rval[cur]}
3328
- __tt_pv_draw
3329
- fi
3330
- tick=0
3331
- if ! __tt_pv_read; then
3332
- (( pvgone )) && break
3333
- [[ -t 0 ]] && continue
3334
- break
3335
- fi
3336
- while :; do
3337
- __tt_pv_handle || break 2
3338
- __tt_pv_read drain || break
3339
- done
3340
- done
3341
- } always {
3342
- local spec=${sel:+${TTHEME_PALETTE[$sel]}}
3343
- [[ -n $spec && $mode != pin ]] && (( ! ${#bgedit} && ! ${#bgswap} )) && __tt_pv_claim "$sel"
3344
- printf '\e[?2026h'
3345
- __tt_pv_bg_close
3346
- if [[ -n $spec ]]; then
3347
- [[ $spec == "$painted" ]] || __tt_apply "$spec"
3348
- elif [[ $painted != "$orig" ]]; then
3349
- if [[ -z $orig ]]; then
3350
- __tt_osc_reset
3351
- else
3352
- __tt_apply "$orig"
3353
- fi
3354
- elif [[ $applied != "$orig" ]]; then
3355
- __tt_pv_paint "${TTHEME_PAINTED:+$orig}"
3356
- fi
3357
- printf '\e[?7h'
3358
- (( hubleft )) || printf '\e[?1049l'
3359
- printf '\e[?25h\e[?2026l'
3360
- [[ -n $tty ]] && stty "$tty" 2>/dev/null
3361
- TTHEME_RAW=0
3362
- [[ -n $tune ]] && __tt_pv_untune
3363
- (( TE_IN )) && __tt_te_stop
3364
- (( conf )) && __tt_pv_unconf
3365
- __tt_pv_bg_save
3366
- if [[ -n $spec ]]; then
3367
- TTHEME_SPEC=$spec
3368
- if [[ $mode == pin ]]; then
3369
- __tt_pin_save "$sel" "${pkeys[picked]}" "$orig"
3370
- [[ $TTHEME_SPEC == "$orig" ]] || __tt_announce
3371
- __tt_sync
3372
- elif (( picked == 1 )); then
3373
- __tt_announce
3374
- __tt_keep "$sel" force
3375
- else
3376
- __tt_announce
3377
- __tt_shown "$sel" force && __tt_reload
3378
- fi
3379
- else
3380
- (( ${#bgedit} + ${#bgswap} )) && [[ -n ${TTHEME_PALETTE[$cn]} ]] && { __tt_shown "$cn" && __tt_reload }
3381
- fi
3382
- (( hubleft )) && __tt_catalog_done "$hubwas"
3383
- }
3384
- return 0
3385
- }
3386
-
3387
- ttheme() {
3388
- emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
3389
- if (( $# > 1 && ${${argv[2,-1]}[(I)(-h|--help)]} )); then
3390
- __tt_verb_help $1
3391
- return
3392
- fi
3393
- case $1 in
3394
- -h|--help) __tt_help; return 0 ;;
3395
- -V|--version) __tt_cli --version; return ;;
3396
- help) __tt_verb_help $2; return 0 ;;
3397
- -*) print -u2 "ttheme: unknown option $1 — see \`ttheme help\`"; return 1 ;;
3398
- esac
3399
- if (( $# )) && [[ -z ${TTHEME_VERB_ABOUT[$1]} ]]; then
3400
- print -u2 "ttheme: unknown command '$1' — see \`ttheme help\`"
3401
- return 1
3402
- fi
3403
- __tt_fresh
3404
- (( $+functions[ttheme] )) || { print -u2 "ttheme: uninstalled — \`npx @kecan0406/ttheme@latest init\` sets it up again"; return 1 }
3405
- if ! __tt_paints && (( ! $# || ${TTHEME_TAB_VERBS[(Ie)$1]} )); then
3406
- __tt_unpainted
3407
- return 1
3408
- fi
3409
- if (( ! $# )); then
3410
- (( ${#TTHEME_PALETTE} )) || { __tt_empty; return }
3411
- if [[ -t 0 && -t 1 ]]; then
3412
- __tt_preview hub
3413
- else
3414
- __tt_menu
3415
- fi
3416
- return 0
3417
- fi
3418
-
3419
- case $1 in
3420
- browse|list|add|remove|update|market|new|edit|check|share) __tt_catalog "$@"; return ;;
3421
- on|off) __tt_switch "$@"; return ;;
3422
- info) TTHEME_ZSH=$ZSH_VERSION __tt_cli "$@"; return ;;
3423
- esac
3424
- __tt_arity "$@" || return
3425
- [[ $1 == config ]] && { __tt_config; return }
3426
- (( ${#TTHEME_PALETTE} )) || { __tt_empty; return }
3427
-
3428
- local REPLY
3429
- case $1 in
3430
- use)
3431
- __tt_resolve "$2" || return 1
3432
- __tt_wear "${TTHEME_PALETTE[$REPLY]}" "$REPLY" force
3433
- __tt_announce ;;
3434
- next) __tt_rotate ;;
3435
- default)
3436
- __tt_resolve "$2" || return 1
3437
- __tt_keep "$REPLY" ;;
3438
- preview) __tt_preview ;;
3439
- pin)
3440
- if [[ $2 == ssh:* ]]; then
3441
- REPLY=ssh:${(L)2#ssh:}
3442
- [[ $REPLY != ssh: ]] || { __tt_misuse pin "missing the host after ssh:"; return }
3443
- [[ $REPLY != *@* ]] || { print -u2 -r -- "ttheme pin: an ssh pin names the host alone — ssh:${REPLY##*@}"; return 1 }
3444
- __tt_ssh_ok $REPLY || { print -u2 -r -- "ttheme pin: not a host: ${2#ssh:} — letters, digits, . - : and the wildcards * ?"; return 1 }
3445
- elif [[ -n $2 ]]; then
3446
- REPLY=$2
3447
- [[ $REPLY == \~ || $REPLY == \~/* ]] && REPLY=$HOME${REPLY#\~}
3448
- [[ -d $REPLY ]] || { print -u2 -r -- "ttheme pin: no such directory: $2"; return 1 }
3449
- REPLY=${REPLY:a}
3450
- fi
3451
- __tt_preview pin ${REPLY:+$REPLY} ;;
3452
- unpin) __tt_unpin "${@:2}" ;;
3453
- pins) __tt_pins_map ;;
1501
+ use)
1502
+ __tt_resolve "$2" || return 1
1503
+ __tt_wear "${TTHEME_PALETTE[$REPLY]}" "$REPLY" force
1504
+ __tt_announce ;;
1505
+ next) __tt_rotate ;;
1506
+ default)
1507
+ __tt_resolve "$2" || return 1
1508
+ __tt_keep "$REPLY" ;;
1509
+ preview) __tt_preview ;;
1510
+ pin)
1511
+ if [[ $2 == ssh:* ]]; then
1512
+ REPLY=ssh:${(L)2#ssh:}
1513
+ [[ $REPLY != ssh: ]] || { __tt_misuse pin "missing the host after ssh:"; return }
1514
+ [[ $REPLY != *@* ]] || { print -u2 -r -- "ttheme pin: an ssh pin names the host alone — ssh:${REPLY##*@}"; return 1 }
1515
+ __tt_ssh_ok $REPLY || { print -u2 -r -- "ttheme pin: not a host: ${2#ssh:} — letters, digits, . - : and the wildcards * ?"; return 1 }
1516
+ elif [[ -n $2 ]]; then
1517
+ REPLY=$2
1518
+ [[ $REPLY == \~ || $REPLY == \~/* ]] && REPLY=$HOME${REPLY#\~}
1519
+ [[ -d $REPLY ]] || { print -u2 -r -- "ttheme pin: no such directory: $2"; return 1 }
1520
+ REPLY=${REPLY:a}
1521
+ fi
1522
+ __tt_preview pin ${REPLY:+$REPLY} ;;
1523
+ unpin) __tt_unpin "${@:2}" ;;
1524
+ pins) __tt_pins_map ;;
3454
1525
  esac
3455
1526
  }
3456
1527
 
@@ -3512,30 +1583,14 @@ fi
3512
1583
  fi
3513
1584
  __tt_dir_sync
3514
1585
  }
3515
- autoload -Uz add-zsh-hook add-zle-hook-widget
3516
- zle -N __tt_line_init
3517
- add-zle-hook-widget line-init __tt_line_init
3518
- add-zsh-hook chpwd __tt_chpwd
3519
- add-zsh-hook precmd __tt_prompt
3520
- if (( ! TTHEME_TMUX )); then
3521
- add-zsh-hook preexec __tt_ran
3522
- add-zsh-hook precmd __tt_unmux
3523
- fi
3524
- if __tt_follows_focus || (( TTHEME_TMUX )); then
3525
- add-zsh-hook precmd __tt_precmd
3526
- add-zsh-hook preexec __tt_preexec
3527
- __tt_bind_focus
3528
- else
3529
- __tt_sync
3530
- fi
3531
- __tt_follows_prompt && add-zsh-hook precmd __tt_prompted
1586
+ __tt_hook
3532
1587
  __tt_announce
3533
1588
  }
3534
1589
 
3535
1590
  () {
3536
1591
  emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
3537
1592
  local f
3538
- for f in $TTHEME_HOME/ttheme.zsh $TTHEME_HOME/palettes.zsh $TTHEME_HOME/adapters/_osc.zsh $TTHEME_HOME/adapters/_wired.zsh $TTHEME_HOME/adapters/_bg.zsh $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh; do
1593
+ for f in $TTHEME_HOME/ttheme.zsh $TTHEME_HOME/preview.zsh $TTHEME_HOME/palettes.zsh $TTHEME_HOME/adapters/_osc.zsh $TTHEME_HOME/adapters/_wired.zsh $TTHEME_HOME/adapters/_bg.zsh $TTHEME_HOME/adapters/$TTHEME_ADAPTER.zsh; do
3539
1594
  [[ -r $f && ! $f.zwc -nt $f ]] || continue
3540
1595
  zcompile -UR -- $f.$$.zwc $f 2>/dev/null && command mv -f -- $f.$$.zwc $f.zwc 2>/dev/null
3541
1596
  [[ ! -e $f.$$.zwc ]] || command rm -f -- $f.$$.zwc