generate-alt-random: don’t run TIOCGWINSZ ioctl if --cols and --rows were used

This commit is contained in:
Daniel Eklöf 2021-04-22 11:20:55 +02:00
parent 10e512f14f
commit a9236129f6
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -38,35 +38,36 @@ def main():
opts = parser.parse_args()
out = opts.out if opts.out is not None else sys.stdout
try:
def dummy(*args):
"""Need a handler installed for sigwait() to trigger."""
pass
signal.signal(signal.SIGWINCH, dummy)
if opts.rows is None or opts.cols is None:
try:
def dummy(*args):
"""Need a handler installed for sigwait() to trigger."""
pass
signal.signal(signal.SIGWINCH, dummy)
while True:
with open('/dev/tty', 'rb') as pty:
lines, cols, height, width = struct.unpack(
'HHHH',
fcntl.ioctl(pty,
termios.TIOCGWINSZ,
struct.pack('HHHH', 0, 0, 0, 0)))
while True:
with open('/dev/tty', 'rb') as pty:
lines, cols, height, width = struct.unpack(
'HHHH',
fcntl.ioctl(pty,
termios.TIOCGWINSZ,
struct.pack('HHHH', 0, 0, 0, 0)))
if width > 0 and height > 0:
break
if width > 0 and height > 0:
break
# Were early; the foot window hasnt been mapped yet. Or,
# to be more precise, fonts havent yet been loaded,
# meaning it doesnt have any cell geometry yet.
signal.sigwait([signal.SIGWINCH])
# Were early; the foot window hasnt been mapped yet. Or,
# to be more precise, fonts havent yet been loaded,
# meaning it doesnt have any cell geometry yet.
signal.sigwait([signal.SIGWINCH])
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
except OSError:
lines = None
cols = None
height = None
width = None
except OSError:
lines = None
cols = None
height = None
width = None
if opts.rows is not None:
lines = opts.rows