chore: improved fix for terminal error

This commit is contained in:
Matthias 2024-08-29 20:38:25 +02:00
parent ca3dee7b37
commit 1c5ca0f022

View File

@ -59,17 +59,21 @@ class HyperoptOutput:
max_rows: Optional[int] = None max_rows: Optional[int] = None
if self._streaming and "pytest" not in sys.modules: if self._streaming:
ts = get_terminal_size() try:
# Get terminal size. ts = get_terminal_size()
# Account for header, borders, and for the progress bar. # Get terminal size.
# This assumes that lines don't wrap. # Account for header, borders, and for the progress bar.
if ts.columns < 148: # This assumes that lines don't wrap.
# If the terminal is too small, we can't display the table properly. if ts.columns < 148:
# We will halve the number of rows to display. # If the terminal is too small, we can't display the table properly.
max_rows = -(int(ts.lines / 2) - 6) # We will halve the number of rows to display.
else: max_rows = -(int(ts.lines / 2) - 6)
max_rows = -(ts.lines - 6) else:
max_rows = -(ts.lines - 6)
except OSError:
# If we can't get the terminal size, we will just display the last 10 rows.
pass
self.__init_table() self.__init_table()
for r in self._results[max_rows:]: for r in self._results[max_rows:]: