mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-04 07:15:29 -04:00
generate-alt-random: don’t run TIOCGWINSZ ioctl if --cols and --rows were used
This commit is contained in:
parent
10e512f14f
commit
a9236129f6
1 changed files with 25 additions and 24 deletions
|
|
@ -38,35 +38,36 @@ def main():
|
||||||
opts = parser.parse_args()
|
opts = parser.parse_args()
|
||||||
out = opts.out if opts.out is not None else sys.stdout
|
out = opts.out if opts.out is not None else sys.stdout
|
||||||
|
|
||||||
try:
|
if opts.rows is None or opts.cols is None:
|
||||||
def dummy(*args):
|
try:
|
||||||
"""Need a handler installed for sigwait() to trigger."""
|
def dummy(*args):
|
||||||
pass
|
"""Need a handler installed for sigwait() to trigger."""
|
||||||
signal.signal(signal.SIGWINCH, dummy)
|
pass
|
||||||
|
signal.signal(signal.SIGWINCH, dummy)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
with open('/dev/tty', 'rb') as pty:
|
with open('/dev/tty', 'rb') as pty:
|
||||||
lines, cols, height, width = struct.unpack(
|
lines, cols, height, width = struct.unpack(
|
||||||
'HHHH',
|
'HHHH',
|
||||||
fcntl.ioctl(pty,
|
fcntl.ioctl(pty,
|
||||||
termios.TIOCGWINSZ,
|
termios.TIOCGWINSZ,
|
||||||
struct.pack('HHHH', 0, 0, 0, 0)))
|
struct.pack('HHHH', 0, 0, 0, 0)))
|
||||||
|
|
||||||
if width > 0 and height > 0:
|
if width > 0 and height > 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
# We’re early; the foot window hasn’t been mapped yet. Or,
|
# We’re early; the foot window hasn’t been mapped yet. Or,
|
||||||
# to be more precise, fonts haven’t yet been loaded,
|
# to be more precise, fonts haven’t yet been loaded,
|
||||||
# meaning it doesn’t have any cell geometry yet.
|
# meaning it doesn’t have any cell geometry yet.
|
||||||
signal.sigwait([signal.SIGWINCH])
|
signal.sigwait([signal.SIGWINCH])
|
||||||
|
|
||||||
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
|
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
|
||||||
|
|
||||||
except OSError:
|
except OSError:
|
||||||
lines = None
|
lines = None
|
||||||
cols = None
|
cols = None
|
||||||
height = None
|
height = None
|
||||||
width = None
|
width = None
|
||||||
|
|
||||||
if opts.rows is not None:
|
if opts.rows is not None:
|
||||||
lines = opts.rows
|
lines = opts.rows
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue