Skip to content

Commit

Permalink
attempt to set ncols from terminal environs
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jun 19, 2015
1 parent 4c53793 commit 2b4d735
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tqdm/_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ def tqdm(iterable, desc=None, total=None, leave=False, file=sys.stderr,
except (TypeError, AttributeError):
total = None

if (ncols is None) and (file in (sys.stderr, sys.stdout)):
try:
from termios import TIOCGWINSZ
from fcntl import ioctl
from array import array
except ImportError:
pass
else:
try:
ncols = array('h', ioctl(file, TIOCGWINSZ, '\0' * 8))[1]
except SystemExit:
raise
except:
try:
from os import environ
except ImportError:
pass
else:
ncols = int(environ.get('COLUMNS', 1)) - 1

if miniters is None:
miniters = 0
dynamic_miniters = True
Expand Down

0 comments on commit 2b4d735

Please sign in to comment.