summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 22:45:44 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 22:45:44 -0600
commit1e98f74f58f130c98b3da5becbab491961100a04 (patch)
tree1d1dec261fc9c352a9b5fcef6972933335056e5a
parent64b721f58e1f70bee91e4c0992388b81820cee16 (diff)
downloadztop-1e98f74f58f130c98b3da5becbab491961100a04.tar.gz
tests: a pty painter that prints the screen ztop thinks it drew
Checking the layout by eye over ssh is slow and lossy; this applies the output to a 100x30 grid and prints each frame after a key.
-rw-r--r--Makefile2
-rw-r--r--tests/__pycache__/screen.cpython-315-pytest-9.1.1.pycbin0 -> 4249 bytes
-rw-r--r--tests/screen.py78
3 files changed, 79 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 5bd07a0..96ab36c 100644
--- a/Makefile
+++ b/Makefile
@@ -58,7 +58,7 @@ TESTFLAGS = -std=c17 -g -O1 -Wall -Wextra -Wshadow -Wpedantic \
# ASCII through the EBCDIC converter: make spins on the Makefile, sh
# rejects the script, awk reads garbage. Run this once after a checkout.
tag:
- @-chtag -t -c ISO8859-1 Makefile README.md DESIGN.md tests/leakcheck.sh
+ @-chtag -t -c ISO8859-1 Makefile README.md DESIGN.md tests/*.sh tests/*.py
@-chtag -t -c ISO8859-1 src/*.c src/*.h src/*.S tui/*.c tui/*.h
@-chtag -t -c ISO8859-1 tui/Makefile tui/test_tui.c tui/demo.c
diff --git a/tests/__pycache__/screen.cpython-315-pytest-9.1.1.pyc b/tests/__pycache__/screen.cpython-315-pytest-9.1.1.pyc
new file mode 100644
index 0000000..d01c573
--- /dev/null
+++ b/tests/__pycache__/screen.cpython-315-pytest-9.1.1.pyc
Binary files differ
diff --git a/tests/screen.py b/tests/screen.py
new file mode 100644
index 0000000..adc4914
--- /dev/null
+++ b/tests/screen.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python3
+"""Paint ztop into a grid and print it, to check the layout without an eye.
+
+ python3 tests/screen.py ./ztop
+
+The pty is 100x30; every key is followed by a snapshot of the screen as
+the escapes would leave it. No termios is touched, so the program sees a
+plain pty and uses its own raw mode.
+"""
+import fcntl, os, pty, select, struct, termios, time
+
+W, H = 100, 30
+grid = [[' '] * W for _ in range(H)]
+row = col = 0
+
+def feed(data):
+ global row, col
+ i = 0
+ while i < len(data):
+ b = data[i]
+ if b == 0x1b and i + 1 < len(data) and data[i + 1] == ord('['):
+ j = i + 2
+ while j < len(data) and not (0x40 <= data[j] <= 0x7e):
+ j += 1
+ if j >= len(data):
+ return
+ params = data[i + 2:j].decode('latin1')
+ final = chr(data[j])
+ if final == 'H':
+ parts = (params.split(';') + ['1', '1'])[:2]
+ row = max(0, int(parts[0] or 1) - 1)
+ col = max(0, int(parts[1] or 1) - 1)
+ elif final == 'J':
+ for r in range(H):
+ grid[r] = [' '] * W
+ elif final == 'K':
+ for c in range(col, W):
+ grid[row][c] = ' '
+ i = j + 1
+ continue
+ if b == 0x0d:
+ col = 0
+ elif b == 0x0a:
+ row = min(H - 1, row + 1)
+ elif b >= 0x20:
+ if row < H and col < W:
+ grid[row][col] = chr(b)
+ col += 1
+ i += 1
+
+pid, fd = pty.fork()
+if pid == 0:
+ os.environ['TERM'] = 'xterm'
+ os.execv('./ztop', ['./ztop', '-d', '60'])
+
+fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack('HHHH', H, W, 0, 0))
+
+def pump(t):
+ end = time.time() + t
+ while time.time() < end:
+ r, _, _ = select.select([fd], [], [], 0.05)
+ if not r:
+ continue
+ try:
+ d = os.read(fd, 65536)
+ except OSError:
+ return
+ if not d:
+ return
+ feed(d)
+
+pump(2.0)
+for k in [b'1', b'2', b'4', b'\t', b'?', b'?', b'q']:
+ os.write(fd, k)
+ pump(1.0)
+ print('=== after', k)
+ for line in grid:
+ print(''.join(line).rstrip())