@kecan0406/ttheme 1.1.5 → 1.2.0

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.1.5",
2
+ "version": "1.2.0",
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.1.5",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "ttheme": "bin/ttheme.js"
@@ -11,7 +11,7 @@
11
11
  "shell",
12
12
  "!shell/check.zsh"
13
13
  ],
14
- "description": "Character terminal palettes for Ghostty, kitty, Alacritty, WezTerm, iTerm2, Windows Terminal and Warp",
14
+ "description": "Character terminal palettes for Ghostty, kitty, Alacritty, WezTerm, iTerm2, Windows Terminal, Warp and Konsole",
15
15
  "license": "MIT",
16
16
  "author": "kecan0406",
17
17
  "repository": {
@@ -27,7 +27,8 @@
27
27
  "kitty",
28
28
  "alacritty",
29
29
  "wezterm",
30
- "iterm2"
30
+ "iterm2",
31
+ "konsole"
31
32
  ],
32
33
  "devDependencies": {
33
34
  "@biomejs/biome": "^2.3.0",
@@ -1,33 +1,14 @@
1
1
  typeset -ga TTHEME_BG_POSITIONS=(top-left top-center top-right center-left center center-right bottom-left bottom-center bottom-right)
2
2
 
3
- __tt_ghostty_shown() {
4
- local f=${TTHEME_CONFIG:h}/backgrounds/shown.conf
5
- REPLY=""
6
- [[ -r $f ]] || return 1
7
- REPLY=${${"$(<$f)"}##*\?}
8
- REPLY=${REPLY%.conf}
9
- REPLY=${${REPLY/--/@}/--//}
10
- }
11
-
12
- __tt_put() {
13
- local f=$1
14
- shift
15
- print -rl -- "$@" > $f.$$ && mv -f -- $f.$$ $f && return 0
16
- rm -f -- $f.$$
17
- return 1
18
- }
19
-
20
3
  __tt_bg_saved() {
21
- local REPLY
22
- (( ${TTHEME_TERMINALS[(Ie)iterm2]} )) && __tt_cli image $1 tuned
4
+ __tt_pictured "$@"
23
5
  __tt_bg_refresh "$@"
24
- __tt_ghostty_shown && (( ${@[(Ie)$REPLY]} )) && __tt_reload
25
6
  return 0
26
7
  }
27
8
 
28
9
  __tt_bg_refresh() { : }
29
10
 
30
- __tt_bg_aligns() { (( ! ${TTHEME_TERMINALS[(Ie)iterm2]} )) }
11
+ __tt_bg_lasting() { : }
31
12
 
32
13
  __tt_bg_frame() {
33
14
  local -i iw=$1 ih=$2 W=$3 H=$4 s=$5 ax=$(( ($6 - 1) % 3 )) ay=$(( ($6 - 1) / 3 )) f=${8:--1} wide dw dh ox oy
@@ -668,7 +649,7 @@ __tt_pv_bg_strip() {
668
649
  __tt_bg_send $fill
669
650
  id=$REPLY
670
651
  want="$id $(( r0 + 2 )) $(( x + 1 )) $tc $tr"
671
- [[ ${bgthumb[$slot]} == "$want" ]] && continue
652
+ __tt_bg_lasting && [[ ${bgthumb[$slot]} == "$want" ]] && continue
672
653
  if [[ -n ${bgthumb[$slot]} ]]; then
673
654
  printf -v cmd '\e_Ga=d,d=i,i=%d,p=%d,q=2\e\\' ${${=bgthumb[$slot]}[1]} $(( 700000 + slot ))
674
655
  buf+=$cmd
@@ -57,6 +57,12 @@ __tt_worn() { : }
57
57
 
58
58
  __tt_keepable() { return 1 }
59
59
 
60
+ __tt_paints() { return 0 }
61
+
62
+ __tt_unpainted() { : }
63
+
64
+ __tt_follows_focus() { return 1 }
65
+
60
66
  __tt_pv_bg_open() { : }
61
67
 
62
68
  __tt_pv_bg_show() { : }
@@ -0,0 +1,55 @@
1
+ typeset -g TTHEME_GHOSTTY_PID=""
2
+
3
+ __tt_reload() {
4
+ local wired
5
+ for wired in $TTHEME_TERMINALS; do
6
+ (( $+functions[__tt_reload_$wired] )) && __tt_reload_$wired
7
+ done
8
+ return 0
9
+ }
10
+
11
+ __tt_pictured() {
12
+ local wired
13
+ for wired in $TTHEME_TERMINALS; do
14
+ (( $+functions[__tt_pictured_$wired] )) && __tt_pictured_$wired "$@"
15
+ done
16
+ return 0
17
+ }
18
+
19
+ __tt_reload_ghostty() {
20
+ local pid=$PPID ppid comm owner=$TTHEME_GHOSTTY_PID
21
+ (( TTHEME_TMUX )) && { pid=$(tmux display -p '#{client_pid}' 2>/dev/null) owner="" }
22
+ if [[ -z $owner ]]; then
23
+ owner=0
24
+ while (( pid > 1 )); do
25
+ read -r ppid comm <<< "$(ps -o ppid=,comm= -p $pid)"
26
+ if [[ ${comm:t} == ghostty ]]; then
27
+ owner=$pid
28
+ break
29
+ fi
30
+ pid=$ppid
31
+ done
32
+ (( TTHEME_TMUX )) || TTHEME_GHOSTTY_PID=$owner
33
+ fi
34
+ (( owner )) && kill -USR2 $owner 2>/dev/null && return
35
+ pkill -USR2 -x ghostty 2>/dev/null
36
+ }
37
+
38
+ __tt_ghostty_shown() {
39
+ local f=${TTHEME_CONFIG:h}/backgrounds/shown.conf
40
+ REPLY=""
41
+ [[ -r $f ]] || return 1
42
+ REPLY=${${"$(<$f)"}##*\?}
43
+ REPLY=${REPLY%.conf}
44
+ REPLY=${${REPLY/--/@}/--//}
45
+ }
46
+
47
+ __tt_pictured_ghostty() {
48
+ local REPLY
49
+ __tt_ghostty_shown && (( ${@[(Ie)$REPLY]} )) && __tt_reload_ghostty
50
+ return 0
51
+ }
52
+
53
+ __tt_pictured_iterm2() { __tt_cli image $1 tuned }
54
+
55
+ __tt_bg_aligns() { (( ! ${TTHEME_TERMINALS[(Ie)iterm2]} )) }
@@ -1,5 +1,7 @@
1
1
  source $TTHEME_HOME/adapters/_bg.zsh
2
2
 
3
+ __tt_follows_focus() { return 0 }
4
+
3
5
  __tt_keepable() { return 0 }
4
6
 
5
7
  __tt_bg_shown() { __tt_ghostty_shown }
@@ -1,5 +1,7 @@
1
1
  source $TTHEME_HOME/adapters/_bg.zsh
2
2
 
3
+ __tt_follows_focus() { return 0 }
4
+
3
5
  typeset -g TTHEME_KITTY_SHOWN=""
4
6
 
5
7
  __tt_keepable() { (( ${TTHEME_TERMINALS[(Ie)kitty]} )) }
@@ -0,0 +1,45 @@
1
+ __tt_paints() { (( ${TTHEME_TERMINALS[(Ie)konsole]} )) }
2
+
3
+ __tt_unpainted() {
4
+ print -u2 "ttheme: Konsole draws a palette's 16 colors only from the color schemes init writes — wire it with \`npx @kecan0406/ttheme@latest init\`"
5
+ }
6
+
7
+ __tt_keepable() { __tt_paints }
8
+
9
+ __tt_scheme() {
10
+ local -a p=(${=TTHEME_PALETTE[$1]})
11
+ REPLY="ColorScheme=ttheme-${${1/@/--}/\//--};UseCustomCursorColor=true;customCursorColor=$p[3]"
12
+ }
13
+
14
+ __tt_osc_apply() {
15
+ local -a p=(${=1})
16
+ (( ${#p} >= 20 )) || return 1
17
+ local REPLY
18
+ __tt_name_of "$1"
19
+ if __tt_paints && [[ -n ${TTHEME_PALETTE[$REPLY]} ]]; then
20
+ __tt_scheme $REPLY
21
+ __tt_out $'\e]50;'$REPLY$'\a'
22
+ elif [[ $p[1] == - ]]; then
23
+ __tt_out $'\e]10;'$p[2]$'\e\\'
24
+ else
25
+ __tt_out $'\e]11;'$p[1]$'\e\\\e]10;'$p[2]$'\e\\'
26
+ fi
27
+ export TTHEME_PAINTED=1
28
+ (( TTHEME_TMUX )) && tmux set -q @ttheme_bg "$p[1]" 2>/dev/null
29
+ __tt_worn "$1"
30
+ return 0
31
+ }
32
+
33
+ __tt_osc_reset() {
34
+ local REPLY=$TTHEME_KONSOLE_BASE
35
+ if __tt_paints; then
36
+ [[ -n $TTHEME_STARTUP && -n ${TTHEME_PALETTE[$TTHEME_STARTUP]} ]] && __tt_scheme $TTHEME_STARTUP
37
+ __tt_out $'\e]50;'$REPLY$'\a'
38
+ else
39
+ __tt_out $'\e]110;\e\\\e]111;\e\\'
40
+ fi
41
+ unset TTHEME_PAINTED
42
+ (( TTHEME_TMUX )) && tmux set -qu @ttheme_bg 2>/dev/null
43
+ __tt_worn ""
44
+ return 0
45
+ }
@@ -27,4 +27,7 @@ __tt_osc_reset() {
27
27
  return 0
28
28
  }
29
29
 
30
- [[ -o interactive && -t 1 ]] && __tt_listen
30
+ () {
31
+ emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
32
+ [[ -o interactive && -t 1 ]] && __tt_listen
33
+ }
@@ -0,0 +1,5 @@
1
+ __tt_paints() { return 1 }
2
+
3
+ __tt_unpainted() {
4
+ 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"
5
+ }
@@ -1,23 +1,73 @@
1
- typeset -g TTHEME_WEZTERM_SHOWN=""
1
+ source $TTHEME_HOME/adapters/_bg.zsh
2
+
3
+ typeset -g TTHEME_WEZTERM_SHOWN="" TTHEME_WEZTERM_VIEW=""
2
4
 
3
5
  __tt_keepable() { (( ${TTHEME_TERMINALS[(Ie)wezterm]} )) }
4
6
 
5
- __tt_wezterm_show() {
7
+ __tt_wezterm_var() {
6
8
  local REPLY
7
- __tt_b64s "$1"
8
- printf '\e]1337;SetUserVar=ttheme_shown=%s\a' "$REPLY"
9
+ __tt_b64s "$2"
10
+ __tt_out $'\e]1337;SetUserVar='$1'='$REPLY$'\a'
9
11
  }
10
12
 
11
13
  __tt_shown() {
12
14
  [[ $2 != force && $TTHEME_WEZTERM_SHOWN == $1 ]] && return 1
13
15
  TTHEME_WEZTERM_SHOWN=$1
14
- __tt_wezterm_show $1
16
+ __tt_wezterm_var ttheme_shown $1
15
17
  return 1
16
18
  }
17
19
 
20
+ __tt_bg_shown() { REPLY=$TTHEME_WEZTERM_SHOWN }
21
+
22
+ __tt_bg_refresh() { __tt_wezterm_var ttheme_shown $TTHEME_WEZTERM_SHOWN }
23
+
24
+ __tt_bg_lasting() { return 1 }
25
+
26
+ __tt_bg_cells() {
27
+ local REPLY resp
28
+ __tt_ask $'\e[16t' || return 0
29
+ resp=$REPLY
30
+ [[ $resp == *'[6;'<1->';'<1->t ]] || return 0
31
+ resp=${${resp##*\[6;}%t}
32
+ bgch=${resp%;*} bgcw=${resp#*;}
33
+ }
34
+
35
+ __tt_pv_bg_findable() { return 1 }
36
+
18
37
  __tt_pv_bg_show() {
19
- bgname=$1
20
- __tt_wezterm_show $1
38
+ (( bgcw )) || return 0
39
+ local name=$1 img="" size fit=contain view="" REPLY
40
+ local -i W=$(( pw * bgcw )) H=$(( ph * bgch )) focus=-1
41
+ local -a p=(${=TTHEME_PALETTE[${name%:*}]}) wh
42
+ (( ${#p} >= 20 )) || return 0
43
+ (( $2 )) && TTHEME_WEZTERM_VIEW=-
44
+ bgname=$name
45
+ __tt_bg_load $name
46
+ if [[ $name != "$bginc" || "${bgsize[$name]} ${bgpos[$name]} ${bgop[$name]} ${bgoff[$name]}" != "${bgload[$name]}" ]]; then
47
+ size=${bgsize[$name]}
48
+ if [[ $size == fill ]]; then
49
+ img=${bgfill[$name]} size=100 fit=cover
50
+ elif [[ "$size ${bgpos[$name]}" == "${bgshotkey[$name]}" && -r ${bgshot[$name]} ]]; then
51
+ img=${bgshot[$name]} size=100 fit=cover
52
+ else
53
+ img=${bgsrc[$name]} focus=${bgfocus[$name]}
54
+ fi
55
+ (( bgoff[$name] )) && img=""
56
+ view="$p[1]||1|$W|$H|0|0|0|0|5"
57
+ if [[ -n $img ]] && __tt_bg_dim "$img"; then
58
+ wh=(${=bgdim[$img]})
59
+ __tt_bg_frame $wh[1] $wh[2] $W $H $size ${bgpos[$name]} $fit $focus
60
+ view="$p[1]|$img|${bgop[$name]}|$W|$H|${REPLY// /|}|${bgpos[$name]}"
61
+ fi
62
+ fi
63
+ [[ $view == "$TTHEME_WEZTERM_VIEW" ]] && return 0
64
+ TTHEME_WEZTERM_VIEW=$view
65
+ __tt_wezterm_var ttheme_view "$view"
21
66
  }
22
67
 
23
- __tt_pv_bg_close() { [[ -z $TTHEME_WEZTERM_SHOWN ]] || __tt_wezterm_show $TTHEME_WEZTERM_SHOWN }
68
+ __tt_pv_bg_close() {
69
+ (( bgcw )) && { printf '\e_Ga=d,d=A,q=2\e\\'; __tt_bg_forget }
70
+ [[ -n $TTHEME_WEZTERM_VIEW ]] || return 0
71
+ TTHEME_WEZTERM_VIEW=""
72
+ __tt_wezterm_var ttheme_view ""
73
+ }
@@ -1,3 +1,5 @@
1
1
  __tt_keepable() { (( ${TTHEME_TERMINALS[(Ie)windows-terminal]} )) }
2
2
 
3
3
  __tt_reloaded() { __tt_repaint }
4
+
5
+ __tt_follows_focus() { return 0 }