Skip to content
Merged
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions src/dstack/_internal/cli/utils/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def th(s: str) -> str:
props.add_row(th("Inactivity duration"), inactivity_duration)
props.add_row(th("Reservation"), run_spec.configuration.reservation or "-")

offers = Table(box=None, expand=os.get_terminal_size()[0] <= 110)
try:
width = os.get_terminal_size()[0]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it's better to use something like this:

import shutil
table = Table(box=None, expand=shutil.get_terminal_size(fallback=(120, 40)).columns <= 110)

except OSError:
width = 120 # Default width for non-TTY
offers = Table(box=None, expand=width <= 110)
offers.add_column("#")
offers.add_column("BACKEND", style="grey58", ratio=2)
offers.add_column("RESOURCES", ratio=4)
Expand Down Expand Up @@ -149,7 +153,11 @@ def th(s: str) -> str:
def get_runs_table(
runs: List[Run], verbose: bool = False, format_date: DateFormatter = pretty_date
) -> Table:
table = Table(box=None, expand=os.get_terminal_size()[0] <= 110)
try:
width = os.get_terminal_size()[0]
except OSError:
width = 120 # Default width for non-TTY
table = Table(box=None, expand=width <= 110)
table.add_column("NAME", style="bold", no_wrap=True, ratio=2)
table.add_column("BACKEND", style="grey58", ratio=2)
table.add_column("RESOURCES", ratio=3 if not verbose else 2)
Expand Down