Skip to content

Commit

Permalink
Call ioctl more defensively
Browse files Browse the repository at this point in the history
  • Loading branch information
ayorgo committed Sep 8, 2023
1 parent c52b17b commit 919f6ff
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions matplotlib-backend-kitty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import termios
import tty
from base64 import standard_b64encode
from contextlib import suppress
from subprocess import run

from matplotlib import interactive, is_interactive
Expand All @@ -23,10 +24,14 @@
interactive(True)

def term_size_px():
width_px = height_px = 0

# try to get terminal size from ioctl
buf = array.array("H", [0, 0, 0, 0])
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
_, _, width_px, height_px = buf
with suppress(OSError):
buf = array.array('H', [0, 0, 0, 0])
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
_, _, width_px, height_px = buf

if width_px != 0 and height_px != 0:
return height_px, width_px

Expand Down

0 comments on commit 919f6ff

Please sign in to comment.