Skip to content

Commit

Permalink
Add alternative path to retrieve terminal size if available
Browse files Browse the repository at this point in the history
Use `os.get_terminal_size` if it is available
Maintain original path if not

related to pfalcon#48
  • Loading branch information
arcivanov committed Jan 30, 2021
1 parent 7a26e62 commit 23090fc
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions picotui/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,22 @@ def disable_mouse(cls):
# Mouse reporting - X10 compatibility mode
cls.wr(b"\x1b[?9l")

@classmethod
def screen_size(cls):
import select
cls.wr(b"\x1b[18t")
res = select.select([0], [], [], 0.2)[0]
if not res:
return (80, 24)
resp = os.read(0, 32)
assert resp.startswith(b"\x1b[8;") and resp[-1:] == b"t"
vals = resp[:-1].split(b";")
return (int(vals[2]), int(vals[1]))
if hasattr(os, "get_terminal_size"):
@classmethod
def screen_size(cls):
return os.get_terminal_size(0)
else:
@classmethod
def screen_size(cls):
import select
cls.wr(b"\x1b[18t")
res = select.select([0], [], [], 0.2)[0]
if not res:
return (80, 24)
resp = os.read(0, 32)
assert resp.startswith(b"\x1b[8;") and resp[-1:] == b"t"
vals = resp[:-1].split(b";")
return (int(vals[2]), int(vals[1]))

# Set function to redraw an entire (client) screen
# This is called to restore original screen, as we don't save it.
Expand Down

0 comments on commit 23090fc

Please sign in to comment.