Disable truncating in prettytable if terminal size cannot be determined
This commit is contained in:
@@ -55,6 +55,12 @@ def prettytable(field_names, rows, truncate=False):
|
||||
for field in t.field_names:
|
||||
t.align[field] = 'l'
|
||||
|
||||
if truncate:
|
||||
try:
|
||||
terminal_width = os.get_terminal_size().columns
|
||||
except OSError:
|
||||
truncate = False
|
||||
|
||||
if truncate and rows:
|
||||
n_cols = len(rows[0])
|
||||
max_col_lengths = [0] * n_cols
|
||||
@@ -66,7 +72,6 @@ def prettytable(field_names, rows, truncate=False):
|
||||
max_total_len = sum(max_col_lengths) + 2
|
||||
max_pre_len = sum(max_col_lengths[0:-1]) + 2
|
||||
|
||||
terminal_width = os.get_terminal_size().columns
|
||||
if max_total_len >= terminal_width:
|
||||
max_value_len = terminal_width - max_pre_len - 3
|
||||
if max_value_len < 5:
|
||||
|
||||
Reference in New Issue
Block a user