aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--INSTALL.md1
-rw-r--r--PKGBUILD2
-rwxr-xr-xscripts/generate-alt-random-writes.py49
3 files changed, 50 insertions, 2 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 189ae192..40e167a2 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -241,6 +241,7 @@ tmp_file=$(mktemp)
--attr-bold \
--attr-italic \
--attr-underline \
+ --sixel \
${tmp_file}
./pgo ${tmp_file} ${tmp_file} ${tmp_file}
rm ${tmp_file}
diff --git a/PKGBUILD b/PKGBUILD
index 9fea5bd6..76f1de6a 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -24,7 +24,7 @@ build() {
meson configure -Db_pgo=generate
ninja
- script_options="--scroll --scroll-region --colors-regular --colors-bright --colors-256 --colors-rgb --attr-bold --attr-italic --attr-underline"
+ script_options="--scroll --scroll-region --colors-regular --colors-bright --colors-256 --colors-rgb --attr-bold --attr-italic --attr-underline --sixel"
tmp_file=$(mktemp)
diff --git a/scripts/generate-alt-random-writes.py b/scripts/generate-alt-random-writes.py
index f9601595..2436b6ff 100755
--- a/scripts/generate-alt-random-writes.py
+++ b/scripts/generate-alt-random-writes.py
@@ -30,11 +30,12 @@ def main():
parser.add_argument('--attr-bold', action='store_true')
parser.add_argument('--attr-italic', action='store_true')
parser.add_argument('--attr-underline', action='store_true')
+ parser.add_argument('--sixel', action='store_true')
opts = parser.parse_args()
out = opts.out if opts.out is not None else sys.stdout
- lines, cols, _, _ = struct.unpack(
+ lines, cols, height, width = struct.unpack(
'HHHH',
fcntl.ioctl(sys.stdout.fileno(),
termios.TIOCGWINSZ,
@@ -142,6 +143,52 @@ def main():
# Leave alt screen
out.write('\033[m\033[r\033[?1049l')
+ with open('/dev/urandom', 'rb') as rand:
+ if opts.sixel:
+ # The sixel 'alphabet'
+ sixels = '?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
+
+ for _ in range(200):
+ # Offset image
+ out.write(' ' * (rand.read(1)[0] % (cols // 2)))
+
+ # Begin sixel
+ out.write('\033Pq')
+
+ # Set up 256 random colors
+ for idx in range(256):
+ # param 2: 1=HLS, 2=RGB.
+ # param 3/4/5: HLS/RGB values in range 0-100
+ # (except 'hue' which is 0..360)
+ out.write(f'#{idx};2;{rand.read(1)[0] % 101};{rand.read(1)[0] % 101};{rand.read(1)[0] % 101}')
+
+ # Randomize image width/height
+ six_height = struct.unpack('@H', rand.read(2))[0] % (height // 2)
+ six_width = struct.unpack('@H', rand.read(2))[0] % (width // 2)
+
+ # Sixel size. Without this, sixels will be
+ # auto-resized on cell-boundaries. We expect programs
+ # to emit this sequence since otherwise you cannot get
+ # correctly sized images.
+ out.write(f'"0;0;{six_width};{six_height}')
+
+ for row in range(six_height // 6): # Each sixel is 6 pixels
+ # Choose a random color
+ out.write(f'#{rand.read(1)[0] % 256}')
+
+ if rand.read(1)[0] == 999999999999:
+ assert False
+ out.write(f'!{six_width}{sixels[rand.read(1)[0] % len(sixels)]}')
+ else:
+ for col in range(six_width):
+ out.write(f'{sixels[rand.read(1)[0] % len(sixels)]}')
+
+ # Next line
+ out.write('-')
+
+ # End sixel
+ out.write('\033\\')
+
if __name__ == '__main__':
sys.exit(main())