Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 938a3ab

Browse files
committed
fix for Bug #183 (--threads dot output)
1 parent 1aeaa5d commit 938a3ab

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/core/common.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import urlparse
3333
import ntpath
3434
import posixpath
35+
import subprocess
3536

3637
from tempfile import NamedTemporaryFile
3738
from tempfile import mkstemp
@@ -1062,3 +1063,25 @@ def isBase64EncodedString(subject):
10621063

10631064
def isHexEncodedString(subject):
10641065
return re.match(r"\A[0-9a-fA-F]+\Z", subject) is not None
1066+
1067+
def getConsoleWidth(default=80):
1068+
width = None
1069+
1070+
if 'COLUMNS' in os.environ and os.environ['COLUMNS'].isdigit():
1071+
width = int(os.environ['COLUMNS'])
1072+
else:
1073+
output=subprocess.Popen('stty size', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.read()
1074+
items = output.split()
1075+
if len(items) == 2 and items[1].isdigit():
1076+
width = int(items[1])
1077+
1078+
if width is None:
1079+
try:
1080+
import curses
1081+
stdscr = curses.initscr()
1082+
_, width = stdscr.getmaxyx()
1083+
curses.endwin()
1084+
except:
1085+
pass
1086+
1087+
return width if width else default

lib/core/option.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
from ConfigParser import ConfigParser
3636

37+
from lib.core.common import getConsoleWidth
3738
from lib.core.common import getFileType
3839
from lib.core.common import normalizePath
3940
from lib.core.common import ntToPosixSlashes
@@ -904,10 +905,12 @@ def __setConfAttributes():
904905
conf.threadException = False
905906
conf.wFileType = None
906907

908+
width = getConsoleWidth()
909+
907910
if conf.eta:
908-
conf.progressWidth = 54
911+
conf.progressWidth = width-26
909912
else:
910-
conf.progressWidth = 34
913+
conf.progressWidth = width-46
911914

912915
def __setKnowledgeBaseAttributes():
913916
"""

0 commit comments

Comments
 (0)