Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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