From 938a3ab0b9f49ad6f025e39329a76fc20d87eced Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 16 Apr 2010 13:40:02 +0000 Subject: [PATCH] fix for Bug #183 (--threads dot output) --- lib/core/common.py | 23 +++++++++++++++++++++++ lib/core/option.py | 7 +++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 97a7c994f..1affd5411 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -32,6 +32,7 @@ import time import urlparse import ntpath import posixpath +import subprocess from tempfile import NamedTemporaryFile from tempfile import mkstemp @@ -1062,3 +1063,25 @@ def isBase64EncodedString(subject): def isHexEncodedString(subject): return re.match(r"\A[0-9a-fA-F]+\Z", subject) is not None + +def getConsoleWidth(default=80): + width = None + + if 'COLUMNS' in os.environ and os.environ['COLUMNS'].isdigit(): + width = int(os.environ['COLUMNS']) + else: + output=subprocess.Popen('stty size', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.read() + items = output.split() + if len(items) == 2 and items[1].isdigit(): + width = int(items[1]) + + if width is None: + try: + import curses + stdscr = curses.initscr() + _, width = stdscr.getmaxyx() + curses.endwin() + except: + pass + + return width if width else default \ No newline at end of file diff --git a/lib/core/option.py b/lib/core/option.py index 1f4d81d5e..ddfe2b8f4 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -34,6 +34,7 @@ import urlparse from ConfigParser import ConfigParser +from lib.core.common import getConsoleWidth from lib.core.common import getFileType from lib.core.common import normalizePath from lib.core.common import ntToPosixSlashes @@ -904,10 +905,12 @@ def __setConfAttributes(): conf.threadException = False conf.wFileType = None + width = getConsoleWidth() + if conf.eta: - conf.progressWidth = 54 + conf.progressWidth = width-26 else: - conf.progressWidth = 34 + conf.progressWidth = width-46 def __setKnowledgeBaseAttributes(): """