scripts/generate-alt-random-writes: use TIOCGWINSZ instead of shutil

This commit is contained in:
Daniel Eklöf 2020-03-08 13:52:59 +01:00
parent 8cf3cec920
commit 3bc6db1e8c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -1,8 +1,10 @@
#!/usr/bin/env python3
import argparse
import enum
import shutil
import fcntl
import struct
import sys
import termios
class ColorVariant(enum.IntEnum):
@ -25,9 +27,11 @@ def main():
opts = parser.parse_args()
out = opts.out if opts.out is not None else sys.stdout
term_size = shutil.get_terminal_size()
lines = term_size.lines
cols = term_size.columns
lines, cols, _, _ = struct.unpack(
'HHHH',
fcntl.ioctl(sys.stdout.fileno(),
termios.TIOCGWINSZ,
struct.pack('HHHH', 0, 0, 0, 0)))
# Number of characters to write to screen
count = 256 * 1024**1