uobikiemukot / yaft

yet another framebuffer terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sixel has debris

hackerb9 opened this issue · comments

When showing sixel images, often the right side of the image will have extra data copied from other parts of the screen. This happens particularly when the terminal is scrolling.

Also, the left most column gets written with sixel data, but it does not scroll up. This may be a separate bug.

You can duplicate the problem by running the following script which draws some sixel lines.After the triangle should be a single vertical line six pixels high. On my yaft, I get a weird glyph, but I think it is random. Run the program a few times until it scrolls. Also try ls to put more text on the screen and watch how some of the letters get duplicated up after the sixel images.

#!/bin/bash

DCS=$'\eP'
P1="9"
P2=""
P3=""
ST=$'\e\\'
CR='$'
NL='-'

# Sixel data is character from ? (0x3F) to ~ (0x7E).
# Subtract 0x3F to get six-bit binary of six pixels in a vertical line.
# Least significant bit is at the top.

# For example,

#  • ? (hex 3F) represents the binary value 000000.
#  • T (hex 54) represents the binary value 010101.
#  • i (hex A2) represents the binary value 010101.
#  • t (hex 74) represents the binary value 110101.
#  • ~ (hex 7E) represents the binary value 111111.


printsixel() {
    # Given a sixel data string, send it to the terminal to show it.
    sixeldata="$1"
    echo -n "$DCS$P1;$P2;$P3;q$sixeldata$NL$ST"
}

binarytochar() {
    # Given six bits as 010101, return the sixel character to print them.
    y=$(echo "obase=16; ibase=2; $1+111111" | bc)
    x="$'\x"
    z="'"
    eval echo $x$y$z
}

# Print a checkerboard
odd=$(binarytochar 010101)
even=$(binarytochar 101010)

for ((i=10; i>0; i--)); do
    for ((j=0; j<i; j++)); do
	str=$str$odd$even
    done
    str=$str$NL
done

# A checkered triangle. This writes to left column of pixels in YAFT, which are buggy and don't scroll. 
printsixel $str

# A single vertical line; this repeats on the left side when scrolling.
printsixel '~'