|
1 | | -import os |
| 1 | +import shutil |
2 | 2 | from typing import Any, Dict, List, Optional, Union |
3 | 3 |
|
4 | 4 | from rich.markup import escape |
@@ -95,11 +95,7 @@ def th(s: str) -> str: |
95 | 95 | props.add_row(th("Inactivity duration"), inactivity_duration) |
96 | 96 | props.add_row(th("Reservation"), run_spec.configuration.reservation or "-") |
97 | 97 |
|
98 | | - try: |
99 | | - width = os.get_terminal_size()[0] |
100 | | - except OSError: |
101 | | - width = 120 # Default width for non-TTY |
102 | | - offers = Table(box=None, expand=width <= 110) |
| 98 | + offers = Table(box=None, expand=shutil.get_terminal_size(fallback=(120, 40)).columns <= 110) |
103 | 99 | offers.add_column("#") |
104 | 100 | offers.add_column("BACKEND", style="grey58", ratio=2) |
105 | 101 | offers.add_column("RESOURCES", ratio=4) |
@@ -153,11 +149,7 @@ def th(s: str) -> str: |
153 | 149 | def get_runs_table( |
154 | 150 | runs: List[Run], verbose: bool = False, format_date: DateFormatter = pretty_date |
155 | 151 | ) -> Table: |
156 | | - try: |
157 | | - width = os.get_terminal_size()[0] |
158 | | - except OSError: |
159 | | - width = 120 # Default width for non-TTY |
160 | | - table = Table(box=None, expand=width <= 110) |
| 152 | + table = Table(box=None, expand=shutil.get_terminal_size(fallback=(120, 40)).columns <= 110) |
161 | 153 | table.add_column("NAME", style="bold", no_wrap=True, ratio=2) |
162 | 154 | table.add_column("BACKEND", style="grey58", ratio=2) |
163 | 155 | table.add_column("RESOURCES", ratio=3 if not verbose else 2) |
|
0 commit comments