Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add terminal size fallback #5623

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
23 changes: 18 additions & 5 deletions api_server/services/terminal_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from app.logger import on_flush
import os
import shutil


class TerminalService:
Expand All @@ -10,15 +11,27 @@ def __init__(self, server):
self.subscriptions = set()
on_flush(self.send_messages)

def get_terminal_size(self):
try:
size = os.get_terminal_size()
return (size.columns, size.lines)
except OSError:
try:
size = shutil.get_terminal_size()
return (size.columns, size.lines)
except OSError:
return (80, 24) # fallback to 80x24

def update_size(self):
sz = os.get_terminal_size()
columns, lines = self.get_terminal_size()
changed = False
if sz.columns != self.cols:
self.cols = sz.columns

if columns != self.cols:
self.cols = columns
changed = True

if sz.lines != self.rows:
self.rows = sz.lines
if lines != self.rows:
self.rows = lines
changed = True

if changed:
Expand Down
Loading