about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-07-06 21:55:44 +0200
committerSören Tempel <soeren+git@soeren-tempel.net>2021-07-15 13:28:33 +0200
commit5ae3c1e07c3722149ec06b779474b97163692f32 (patch)
treea11668dd4483385937be9969fde173dd86dd1c1a
parente3849012cb9c564dd13b929fe9fcca94d1ba85bf (diff)
example_escs.py: add script to test SGR escape sequences
This script emits most of the SGR escape sequences supported by
saneterm, so rendering of them can easily be tested. It is not a
perfect test case since it only emits nested sequences in a limited
fashion.

Similar test tools:

* sgr-test.sh from vte:
  https://gitlab.gnome.org/GNOME/vte/-/blob/c17e6d12da00a94c3768be6671182a6a039ec0c0/perf/sgr-test.sh

* 256test.sh from vte:
  https://gitlab.gnome.org/GNOME/vte/-/blob/c17e6d12da00a94c3768be6671182a6a039ec0c0/perf/256test.sh

* msgcat --color=test from gettext (only uses 16 colors, sequences for
  some text styles are broken like italic and underline sometimes)

* lolcat -t [-i] is useful for testing true color support
-rwxr-xr-xexample_escs.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/example_escs.py b/example_escs.py
new file mode 100755
index 0000000..1d8ced6
--- /dev/null
+++ b/example_escs.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python3
+
+def sgr(*args):
+    return '\033[' + ';'.join(map(str,args)) + 'm'
+
+def sgr_extended(*args):
+    return '\033[' + ':'.join(map(str,args)) + 'm'
+
+def print_heading(t):
+    print('\n{}{}{}\n'.format(sgr(1,4), t, sgr()))
+
+print_heading('text style')
+
+print('{}bold{}'.format(sgr(1), sgr(22)))
+print('{}faint{}'.format(sgr(2), sgr(22)))
+print('{}italic{}'.format(sgr(3), sgr(23)))
+print('{}underline{}'.format(sgr(4), sgr(24)))
+print('the following is concealed: {}invisible{}'.format(sgr(8), sgr(28)))
+print('{}strikethrough{}'.format(sgr(9), sgr(29)))
+print('{}double underline{}'.format(sgr(21), sgr(24)))
+
+for s in [30,90,40,100]:
+    print_heading(
+        '16 color {}{}'.format(
+            'bright ' if s > 50 else '',
+            'foreground' if s % 3 == 0 else 'background',
+        )
+    )
+
+    for c in range(8):
+        print(
+            '{}|{:2}{}'.format(
+                sgr(s + c),
+                c,
+                sgr()
+            ),
+            end=''
+        )
+
+    print('')
+
+for s in [38, 48]:
+    section = 'foreground' if s == 38 else 'background'
+
+    print_heading(
+        '16 color {}'.format(section)
+    )
+
+    for y in range(2):
+        for x in range(8):
+            c = x + y * 8
+            print(
+                '{}|{:>2}{}'.format(
+                    sgr_extended(s, 5, c),
+                    c,
+                    sgr(s + 1)
+                ),
+                end=''
+            )
+
+        print('')
+
+    print_heading('6 * 6 * 6 cube color {}'.format(section))
+
+    for y in range(6):
+        for x in range(36):
+            c = 16 + x + y * 36
+            print(
+                '{}|{:>3}{}'.format(
+                    sgr_extended(s, 5, c),
+                    c,
+                    sgr(s + 1)
+                ),
+                end=''
+            )
+        print('')
+
+    print_heading('grayscale {}'.format(section))
+
+    for c in range(232, 256):
+        print(
+            '{}|{:>3}{}'.format(
+                sgr_extended(s, 5, c),
+                c,
+                sgr(s + 1)
+            ),
+            end=''
+        )
+    print('')
+
+
+print_heading('16 color combinations')
+
+print('  |' + '|'.join(map(lambda x: '{:<4}'.format(x), range(16))))
+for f in range(16):
+    print(f'{f:>2}', end='')
+
+    for b in range(16):
+        print(
+            '{}{}|test{}'.format(
+                sgr_extended(38, 5, f),
+                sgr_extended(48, 5, b),
+                sgr(39, 49)
+            ),
+            end=''
+        )
+    print('')