瀏覽代碼

Disable truncation when stdout is not a terminal

master
JustAnotherArchivist 4 年之前
父節點
當前提交
171ca4252b
共有 1 個文件被更改,包括 9 次插入1 次删除
  1. +9
    -1
      archivebot-jobs

+ 9
- 1
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:


Loading…
取消
儲存