diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-11-24 20:35:28 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-11-24 20:35:28 +0000 |
| commit | 519eb24282a671976e75a089b9ead0754a13d173 (patch) | |
| tree | 5729318da1510e02cf8e8b4ed6619dc676978aa7 | |
| parent | term: place frequently accessed members first in term struct (diff) | |
| parent | pkgbuild: add --sixel to generate-alt-random-writes (diff) | |
Merge branch 'sixel-pgo'
| -rw-r--r-- | INSTALL.md | 1 | ||||
| -rw-r--r-- | PKGBUILD | 2 | ||||
| -rwxr-xr-x | scripts/generate-alt-random-writes.py | 49 |
3 files changed, 50 insertions, 2 deletions
@@ -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} @@ -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()) |
