##// END OF EJS Templates
Use term width to determine header length
Vincent Woo -
Show More
@@ -124,6 +124,7 b' from IPython.utils import path as util_path'
124 124 from IPython.utils import py3compat
125 125 from IPython.utils import ulinecache
126 126 from IPython.utils.data import uniq_stable
127 from IPython.utils.terminal import get_terminal_size
127 128 from logging import info, error
128 129
129 130 import IPython.utils.colorable as colorable
@@ -1029,20 +1030,21 b' class VerboseTB(TBTools):'
1029 1030 colors = self.Colors # just a shorthand + quicker name lookup
1030 1031 colorsnormal = colors.Normal # used a lot
1031 1032 exc = '%s%s%s' % (colors.excName, etype, colorsnormal)
1033 width = min(75, get_terminal_size()[0])
1032 1034 if long_version:
1033 1035 # Header with the exception type, python version, and date
1034 1036 pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
1035 1037 date = time.ctime(time.time())
1036 1038
1037 head = '%s%s%s\n%s%s%s\n%s' % (colors.topline, '-' * 75, colorsnormal,
1038 exc, ' ' * (75 - len(str(etype)) - len(pyver)),
1039 pyver, date.rjust(75) )
1039 head = '%s%s%s\n%s%s%s\n%s' % (colors.topline, '-' * width, colorsnormal,
1040 exc, ' ' * (width - len(str(etype)) - len(pyver)),
1041 pyver, date.rjust(width) )
1040 1042 head += "\nA problem occurred executing Python code. Here is the sequence of function" \
1041 1043 "\ncalls leading up to the error, with the most recent (innermost) call last."
1042 1044 else:
1043 1045 # Simplified header
1044 1046 head = '%s%s' % (exc, 'Traceback (most recent call last)'. \
1045 rjust(75 - len(str(etype))) )
1047 rjust(width - len(str(etype))) )
1046 1048
1047 1049 return head
1048 1050
@@ -1155,7 +1157,7 b' class VerboseTB(TBTools):'
1155 1157
1156 1158 colors = self.Colors # just a shorthand + quicker name lookup
1157 1159 colorsnormal = colors.Normal # used a lot
1158 head = '%s%s%s' % (colors.topline, '-' * 75, colorsnormal)
1160 head = '%s%s%s' % (colors.topline, '-' * min(75, get_terminal_size()[0]), colorsnormal)
1159 1161 structured_traceback_parts = [head]
1160 1162 if py3compat.PY3:
1161 1163 chained_exceptions_tb_offset = 0
@@ -24,6 +24,7 b' import os'
24 24 import struct
25 25 import sys
26 26 import warnings
27 import backports.shutil_get_terminal_size
27 28
28 29 from . import py3compat
29 30
@@ -120,37 +121,5 b' def freeze_term_title():'
120 121 ignore_termtitle = True
121 122
122 123
123 if sys.platform == 'win32':
124 124 def get_terminal_size(defaultx=80, defaulty=25):
125 """Return size of current terminal console.
126
127 This function try to determine actual size of current working
128 console window and return tuple (sizex, sizey) if success,
129 or default size (defaultx, defaulty) otherwise.
130
131 Dependencies: ctypes should be installed.
132
133 Author: Alexander Belchenko (e-mail: bialix AT ukr.net)
134 """
135 try:
136 import ctypes
137 except ImportError:
138 return defaultx, defaulty
139
140 h = ctypes.windll.kernel32.GetStdHandle(-11)
141 csbi = ctypes.create_string_buffer(22)
142 res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
143
144 if res:
145 (bufx, bufy, curx, cury, wattr,
146 left, top, right, bottom, maxx, maxy) = struct.unpack(
147 "hhhhHhhhhhh", csbi.raw)
148 sizex = right - left + 1
149 sizey = bottom - top + 1
150 return (sizex, sizey)
151 else:
152 return (defaultx, defaulty)
153 else:
154 def get_terminal_size(defaultx=80, defaulty=25):
155 return defaultx, defaulty
156
125 return backports.shutil_get_terminal_size.get_terminal_size((defaultx, defaulty))
@@ -197,6 +197,7 b' install_requires = ['
197 197 'traitlets',
198 198 'prompt_toolkit>=0.58',
199 199 'pygments',
200 'backports.shutil_get_terminal_size',
200 201 ]
201 202
202 203 # Platform-specific dependencies:
General Comments 0
You need to be logged in to leave comments. Login now