From 171ca4252bb455cb433c3fb3ddf53fb9be9b6f06 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Sun, 29 Mar 2020 01:52:40 +0000 Subject: [PATCH] Disable truncation when stdout is not a terminal --- archivebot-jobs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/archivebot-jobs b/archivebot-jobs index 8f79adf..c3ba882 100755 --- a/archivebot-jobs +++ b/archivebot-jobs @@ -215,7 +215,15 @@ printableColumns = {column: colDef for column, colDef in columns.items() if 'hid if not args.no_table and not args.no_truncate: widthsD = {column: max(itertools.chain((len(column),), (len(job[column]) if isinstance(job[column], str) else len(job[column][1]) for job in jobs))) for column in printableColumns} minWidthsD = {column: len(column) for column in printableColumns} - termWidth = os.get_terminal_size().columns + try: + termWidth = os.get_terminal_size().columns + except OSError as e: + if e.errno == 25: + # Inappropriate ioctl for device (stdout not a terminal, happens e.g. when redirecting or piping) + # Silently ignore this and don't truncate + termWidth = float('Inf') + else: + raise overage = sum(x + 2 for x in widthsD.values()) - 2 - termWidth if overage > 0: if sum((widthsD[column] if 'truncatable' not in colDef[1] else minWidthsD[column]) + 2 for column, colDef in printableColumns.items()) - 2 > termWidth: