Skip to content

Commit e420791

Browse files
vuyelwadrDavid Ruwodo
and
David Ruwodo
authored
Fix: handle OSError from os.get_terminal_size() in CLI table rendering for non-TTY environments (#2599)
* Fix: handle OSError from os.get_terminal_size() in CLI table rendering * Refactor: use shutil.get_terminal_size(fallback=(120, 40)) for safer terminal width detection --------- Co-authored-by: David Ruwodo <[email protected]>
1 parent 1d15bfb commit e420791

File tree

1 file changed

+3
-3
lines changed
  • src/dstack/_internal/cli/utils

1 file changed

+3
-3
lines changed

src/dstack/_internal/cli/utils/run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
import shutil
22
from typing import Any, Dict, List, Optional, Union
33

44
from rich.markup import escape
@@ -95,7 +95,7 @@ def th(s: str) -> str:
9595
props.add_row(th("Inactivity duration"), inactivity_duration)
9696
props.add_row(th("Reservation"), run_spec.configuration.reservation or "-")
9797

98-
offers = Table(box=None, expand=os.get_terminal_size()[0] <= 110)
98+
offers = Table(box=None, expand=shutil.get_terminal_size(fallback=(120, 40)).columns <= 110)
9999
offers.add_column("#")
100100
offers.add_column("BACKEND", style="grey58", ratio=2)
101101
offers.add_column("RESOURCES", ratio=4)
@@ -149,7 +149,7 @@ def th(s: str) -> str:
149149
def get_runs_table(
150150
runs: List[Run], verbose: bool = False, format_date: DateFormatter = pretty_date
151151
) -> Table:
152-
table = Table(box=None, expand=os.get_terminal_size()[0] <= 110)
152+
table = Table(box=None, expand=shutil.get_terminal_size(fallback=(120, 40)).columns <= 110)
153153
table.add_column("NAME", style="bold", no_wrap=True, ratio=2)
154154
table.add_column("BACKEND", style="grey58", ratio=2)
155155
table.add_column("RESOURCES", ratio=3 if not verbose else 2)

0 commit comments

Comments
 (0)