@kecan0406/ttheme 1.0.33 → 1.0.34

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.33",
2
+ "version": "1.0.34",
3
3
  "gate": [
4
4
  {
5
5
  "rule": "foreground",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kecan0406/ttheme",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "ttheme": "bin/ttheme.js"
@@ -13,7 +13,7 @@
13
13
  "!shell/check.zsh",
14
14
  "ghostty/shaders"
15
15
  ],
16
- "description": "Character terminal palettes for ghostty, kitty, alacritty, wezterm and iTerm2",
16
+ "description": "Character terminal palettes for Ghostty, kitty, Alacritty, WezTerm, iTerm2, Windows Terminal and Warp",
17
17
  "license": "MIT",
18
18
  "author": "kecan0406",
19
19
  "repository": {
@@ -31,6 +31,8 @@ __tt_osc_reset() {
31
31
  return 0
32
32
  }
33
33
 
34
+ __tt_reset_reloaded() { __tt_osc_reset }
35
+
34
36
  __tt_repaint() {
35
37
  if [[ -n $TTHEME_SPEC ]]; then
36
38
  __tt_apply "$TTHEME_SPEC"
@@ -4,6 +4,19 @@ __tt_keepable() { return 0 }
4
4
 
5
5
  __tt_bg_shown() { __tt_ghostty_shown }
6
6
 
7
+ __tt_reset_reloaded() {
8
+ local REPLY
9
+ integer i
10
+ __tt_osc_reset
11
+ [[ -n $1 ]] && (( ${TTHEME_TERMINALS[(Ie)ghostty]} && ! TTHEME_TMUX )) || return 0
12
+ for (( i = 0; i < 20; i++ )); do
13
+ __tt_query_bg || return 0
14
+ [[ ${(L)REPLY} == ${(L)1} ]] || return 0
15
+ sleep 0.05
16
+ __tt_osc_reset
17
+ done
18
+ }
19
+
7
20
  __tt_shown() {
8
21
  local dir=${TTHEME_CONFIG:h}/backgrounds was REPLY
9
22
  __tt_bg_shown
package/shell/ttheme.zsh CHANGED
@@ -12,8 +12,21 @@ __tt_palettes_load() {
12
12
 
13
13
  __tt_fresh() {
14
14
  local -a at
15
+ local was=$TTHEME_STARTUP
15
16
  zstat -F %s.%N -A at +mtime -- $TTHEME_HOME/palettes.zsh 2>/dev/null || return 0
16
- [[ $at[1] == "$TTHEME_PALETTES_AT" ]] || { __tt_palettes_load && __tt_reloaded }
17
+ [[ $at[1] == "$TTHEME_PALETTES_AT" ]] && return 0
18
+ __tt_palettes_load && __tt_reloaded
19
+ [[ -n $was && -z $TTHEME_STARTUP && -n $TTHEME_SPEC ]] && __tt_active && __tt_off_here
20
+ }
21
+
22
+ __tt_off_here() {
23
+ local bg=${TTHEME_SPEC%% *}
24
+ TTHEME_SPEC=
25
+ if __tt_shown "" || [[ $1 == reload ]]; then
26
+ __tt_reload
27
+ fi
28
+ __tt_unshown force
29
+ __tt_reset_reloaded $bg
17
30
  }
18
31
 
19
32
  if [[ -r $TTHEME_HOME/palettes.zsh ]]; then
@@ -134,7 +147,7 @@ __tt_spec() {
134
147
 
135
148
  __tt_name_of() { REPLY=${${(k)TTHEME_PALETTE[(re)$1]}:-custom} }
136
149
 
137
- __tt_color() { [[ -t 1 && -z $NO_COLOR ]] }
150
+ __tt_color() { [[ -t 1 && -z $NO_COLOR && $TERM != dumb ]] }
138
151
 
139
152
  __tt_palette_line() {
140
153
  local name=$1 marker=$2
@@ -379,34 +392,60 @@ __tt_menu() {
379
392
  [[ $k == $cur ]] && mark=$gutter
380
393
  __tt_palette_line "$k" "$mark"
381
394
  done
382
- printf '\n\033[2mttheme <name> paints this tab · ttheme preview · ttheme help\033[0m\n'
395
+ printf '\n\033[2mttheme use <palette> paints this tab · ttheme preview · ttheme help\033[0m\n'
383
396
  }
384
397
 
385
398
  __tt_help() {
386
- print -r -- 'ttheme — character terminal palettes
399
+ local v
400
+ print -r -- $'ttheme — character terminal palettes\n'
401
+ print -r -- " ${(r:16:):-ttheme}list every palette, grouped, with previews"
402
+ for v in $TTHEME_VERBS; do
403
+ if [[ $v == - ]]; then
404
+ print
405
+ else
406
+ print -r -- " ${(r:16:)${:-ttheme $v}}$TTHEME_VERB_ABOUT[$v]"
407
+ fi
408
+ done
409
+ print -r -- $'\nttheme <command> --help describes one command · ttheme --version prints the version'
410
+ }
411
+
412
+ __tt_usage() {
413
+ print -r -- "Usage: ttheme ${${:-$1 $TTHEME_VERB_ARGS[$1]}% }"$'\n\n'"$TTHEME_VERB_ABOUT[$1]"
414
+ }
387
415
 
388
- ttheme list every palette, grouped, with previews
389
- ttheme homura paint this tab (a unique prefix works: ttheme ho)
390
- ttheme preview browse live — focus repaints, enter keeps (this tab or default), esc restores, ? lists keys
391
- ttheme next advance this tab to the next palette
392
- ttheme default make a palette the one new tabs open with
393
- ttheme off open new tabs in the terminal'"'"'s own colors — ttheme on wears the default again
394
- ttheme pin pick a palette for this directory — cd into it repaints, cd out restores
395
- ttheme unpin drop the palette pinned to this directory
396
- ttheme config edit settings in $EDITOR — they apply in new tabs
416
+ __tt_verb_help() {
417
+ if (( ${TTHEME_SHELL_VERBS[(Ie)$1]} )); then
418
+ __tt_usage $1
419
+ elif [[ -n $1 && -n ${TTHEME_VERB_ABOUT[$1]} ]]; then
420
+ __tt_cli $1 --help
421
+ else
422
+ __tt_help
423
+ fi
424
+ }
425
+
426
+ __tt_misuse() {
427
+ print -u2 -r -- "ttheme $1: $2"$'\n'
428
+ __tt_usage $1 >&2
429
+ return 1
430
+ }
397
431
 
398
- ttheme browse pick palettes from the catalog in a live picker
399
- ttheme list show the catalog, marking what is installed
400
- ttheme add install palettes from the catalog
401
- ttheme remove uninstall palettes
402
- ttheme update refresh the catalog from the registry'
432
+ __tt_arity() {
433
+ local verb=$1
434
+ shift
435
+ local -a want=(${=TTHEME_VERB_ARGS[$verb]})
436
+ local least=${#${(M)want:#\<*}} most=${#want}
437
+ (( ${#${(M)want:#*...*}} )) && most=$#
438
+ (( $# >= least )) || { __tt_misuse $verb "missing $want[$# + 1]"; return }
439
+ (( $# <= most )) || { __tt_misuse $verb "too many arguments: ${argv[most + 1, -1]}"; return }
403
440
  }
404
441
 
405
442
  __tt_cli() {
406
- TTHEME_FIND_RATING=$TTHEME_FIND_RATING TTHEME_FIND_BLOCK=$TTHEME_FIND_BLOCK \
407
- TTHEME_FIND_POSTS=$TTHEME_FIND_POSTS TTHEME_FIND_SOLO=$TTHEME_FIND_SOLO TTHEME_FIND_ORDER=$TTHEME_FIND_ORDER TTHEME_FIND_SETS=$TTHEME_FIND_SETS \
408
- TTHEME_FIND_HOSTS=$TTHEME_FIND_HOSTS TTHEME_FIND_UNBLOCK=$TTHEME_FIND_UNBLOCK TTHEME_FIND_CUTOUTS=$TTHEME_FIND_CUTOUTS TTHEME_FIND_REMOVE_BG=$TTHEME_FIND_REMOVE_BG \
409
- node $TTHEME_HOME/ttheme.js "$@"
443
+ local k
444
+ local -a pass=()
445
+ for k in $TTHEME_SETTINGS; do
446
+ (( $+parameters[$k] )) && pass+=("$k=${(P)k}")
447
+ done
448
+ env $pass node $TTHEME_HOME/ttheme.js "$@"
410
449
  }
411
450
 
412
451
  __tt_catalog() {
@@ -421,18 +460,20 @@ __tt_catalog() {
421
460
 
422
461
  __tt_switch() {
423
462
  local spec
424
- __tt_catalog $1 || return
425
- __tt_active || return 0
463
+ __tt_cli "$@" || return
464
+ [[ -r $TTHEME_HOME/palettes.zsh ]] && __tt_palettes_load && __tt_reloaded
465
+ if ! __tt_active; then
466
+ __tt_reload
467
+ return 0
468
+ fi
426
469
  if [[ $1 == off ]]; then
427
- __tt_osc_reset
428
- TTHEME_SPEC=
429
- __tt_shown "" && __tt_reload
430
- __tt_unshown force
470
+ __tt_off_here reload
431
471
  elif [[ -n $TTHEME_STARTUP ]]; then
432
472
  spec=${TTHEME_PALETTE[$TTHEME_STARTUP]}
433
473
  __tt_apply "$spec"
434
474
  TTHEME_SPEC=$spec
435
- __tt_shown "$TTHEME_STARTUP" force && __tt_reload
475
+ __tt_shown "$TTHEME_STARTUP" force
476
+ __tt_reload
436
477
  fi
437
478
  }
438
479
 
@@ -1559,7 +1600,21 @@ __tt_preview() {
1559
1600
  }
1560
1601
 
1561
1602
  ttheme() {
1562
- if [[ $TTHEME_ADAPTER == warp && $1 != (-h|--help|help|browse|list|add|remove|update|config|default|on|off) ]]; then
1603
+ if (( $# > 1 && ${${argv[2,-1]}[(I)(-h|--help)]} )); then
1604
+ __tt_verb_help $1
1605
+ return
1606
+ fi
1607
+ case $1 in
1608
+ -h|--help) __tt_help; return 0 ;;
1609
+ -V|--version) __tt_cli --version; return ;;
1610
+ help) __tt_verb_help $2; return 0 ;;
1611
+ -*) print -u2 "ttheme: unknown option $1 — see \`ttheme help\`"; return 1 ;;
1612
+ esac
1613
+ if (( $# )) && [[ -z ${TTHEME_VERB_ABOUT[$1]} ]]; then
1614
+ print -u2 "ttheme: unknown command '$1' — see \`ttheme help\`"
1615
+ return 1
1616
+ fi
1617
+ if [[ $TTHEME_ADAPTER == warp && $1 != (browse|list|add|remove|update|config|default|on|off) ]]; then
1563
1618
  print -u2 "ttheme: Warp wears one theme app-wide and paints no tab background of its own — \`ttheme default <palette>\` puts one on every Warp window"
1564
1619
  return 1
1565
1620
  fi
@@ -1570,41 +1625,43 @@ ttheme() {
1570
1625
  fi
1571
1626
 
1572
1627
  case $1 in
1573
- -h|--help|help) __tt_help; return 0 ;;
1574
1628
  browse|list|add|remove|update) __tt_catalog "$@"; return ;;
1575
- config) __tt_config; return ;;
1629
+ on|off) __tt_switch "$@"; return ;;
1576
1630
  esac
1577
-
1631
+ __tt_arity "$@" || return
1632
+ [[ $1 == config ]] && { __tt_config; return }
1578
1633
  (( ${#TTHEME_PALETTE} )) || { __tt_empty; return }
1579
1634
 
1635
+ local REPLY spec
1580
1636
  case $1 in
1581
- next) __tt_rotate; return ;;
1637
+ use)
1638
+ __tt_resolve "$2" || return 1
1639
+ spec=${TTHEME_PALETTE[$REPLY]}
1640
+ __tt_apply "$spec"
1641
+ TTHEME_SPEC=$spec
1642
+ __tt_shown "$REPLY" force && __tt_reload
1643
+ __tt_announce ;;
1644
+ next) __tt_rotate ;;
1582
1645
  default)
1583
- [[ -n $2 ]] || { print -u2 "ttheme default: name a palette — see \`ttheme help\`"; return 1 }
1584
- local REPLY
1585
1646
  __tt_resolve "$2" || return 1
1586
- __tt_keep "$REPLY"
1587
- return ;;
1588
- on|off) __tt_switch $1; return ;;
1589
- preview) __tt_preview; return ;;
1590
- pin) __tt_preview pin; return ;;
1591
- unpin) __tt_unpin; return ;;
1592
- -*) print -u2 "ttheme: unknown option $1 — see \`ttheme help\`"; return 1 ;;
1647
+ __tt_keep "$REPLY" ;;
1648
+ preview) __tt_preview ;;
1649
+ pin) __tt_preview pin ;;
1650
+ unpin) __tt_unpin ;;
1593
1651
  esac
1594
-
1595
- local REPLY
1596
- __tt_resolve "$1" || return 1
1597
- local spec=${TTHEME_PALETTE[$REPLY]}
1598
- __tt_apply "$spec"
1599
- TTHEME_SPEC=$spec
1600
- __tt_shown "$REPLY" force && __tt_reload
1601
- __tt_announce
1602
1652
  }
1603
1653
 
1604
1654
  if (( $+functions[compdef] )); then
1605
1655
  __tt_complete() {
1606
- (( CURRENT == 2 )) && compadd -- preview next default on off pin unpin config help browse list add remove update
1607
- compadd -- $TTHEME_ORDER
1656
+ local -a reply
1657
+ if (( CURRENT == 2 )); then
1658
+ compadd -- ${TTHEME_VERBS:#-} help
1659
+ elif [[ $words[2] == remove || ( $words[2] == (use|default) && CURRENT == 3 ) ]]; then
1660
+ compadd -- $TTHEME_ORDER
1661
+ elif [[ $words[2] == add ]]; then
1662
+ reply=(${${${(M)${(f)"$(__tt_cli list --json 2>/dev/null)"}:#*\"name\": *}#*\"name\": \"}%%\"*})
1663
+ compadd -- ${reply:|TTHEME_ORDER}
1664
+ fi
1608
1665
  }
1609
1666
  compdef __tt_complete ttheme
1610
1667
  fi