Skip to content
Snippets Groups Projects
Commit 76b5df66 authored by Zuul's avatar Zuul Committed by Gerrit Code Review
Browse files

Merge "Autofit table output if stdout is a tty"

parents a3920dd0 e02f89cd
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@
"""Output formatters using prettytable."""
import os
import sys
import prettytable
......@@ -32,6 +33,14 @@ def _format_row(row):
return new_row
def _do_fit(fit_width):
if os.name == 'nt':
# NOTE(pas-ha) the isatty is not reliable enough on Windows,
# so do not try to auto-fit
return fit_width
return sys.stdout.isatty() or fit_width
class TableFormatter(base.ListFormatter, base.SingleFormatter):
ALIGNMENTS = {
......@@ -177,7 +186,7 @@ class TableFormatter(base.ListFormatter, base.SingleFormatter):
"""
if max_width > 0:
term_width = max_width
elif not fit_width:
elif not _do_fit(fit_width):
# Fitting is disabled
return
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment