Skip to content

Commit 10a4b30

Browse files
committed
256/true colors: use shorter escape sequences
Most terminals limit the number of values in an SGR sequence, and the limit can vary between terminals. The 256 colors mode previously used one sequence with at least 6 values (foreground and background of 256 colors), which is beyond the limit of the Haiku terminal, and as a result it did not display the colors. This is not a regression - we always produced such sequences. Now we use one sequence for foreground, and one for background (and one for additional global values, if given) - which does work in Haiku. Similarly, the true color output was also split into two sequences. There could be other places remaining which produce long escape sequences, but for now all the default modes work out of the box also on Haiku.
1 parent 3fdd723 commit 10a4b30

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sgrtab

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ case $mode in
106106
i=$1 out=
107107
while [ $i -lt $(($1+$2)) ]; do
108108
case ${#i} in 1) pad=" ";; 2) pad=" ";; 3) pad=; esac
109-
out=$out"$ESC[$3;48;5;${i}${G:+;$G}m $pad$i$ESC[m"
109+
out=$out"$ESC[$3m$ESC[48;5;${i}m${G:+$ESC[${G}m} $pad$i$ESC[m"
110110
i=$((i+1))
111111
done; echo "$out"
112112
}
@@ -130,7 +130,7 @@ true) ESC=$(printf \\033)
130130
x=1 out=
131131
while [ $x -le 64 ]; do
132132
top=$((256-y*16)); left=$((256-x*4)); bottomright=$((x*2+y*8-1))
133-
out=$out"$ESC[48;2;${top};${left};${bottomright}${G:+;$G}m$T$ESC[m"
133+
out=$out"$ESC[48;2;${top};${left};${bottomright}m${G:+$ESC[${G}m}$T$ESC[m"
134134
x=$((x+1))
135135
done; echo "$out"
136136
y=$((y+1))

0 commit comments

Comments
 (0)