|
30 | 30 | from datetime import datetime
|
31 | 31 | from distutils.spawn import find_executable
|
32 | 32 | from tempfile import mkdtemp
|
| 33 | +from math import log10 |
33 | 34 | try:
|
34 | 35 | from urllib.request import FancyURLopener
|
35 | 36 | except ImportError:
|
@@ -105,11 +106,15 @@ def pretty_log_dists(dists, log_func=info):
|
105 | 106 | for line in infos:
|
106 | 107 | log_func('\t' + line)
|
107 | 108 |
|
108 |
| -def shorten_string(string, width): |
109 |
| - if len(string) <= width: |
| 109 | +def shorten_string(string, max_width): |
| 110 | + ''' make limited length string in form: |
| 111 | + "the string is very lo...(and 15 more)" |
| 112 | + ''' |
| 113 | + string_len = len(string) |
| 114 | + if string_len <= max_width: |
110 | 115 | return string
|
111 |
| - visible = width - 20 #expected suffix len |
112 |
| - return '{:<{width}}...(and {} more)'.format(string, len(string) - visible, width = visible) |
| 116 | + visible = max_width - 16 - int(log10(string_len)) #expected suffix len "...(and XXXXX more)" |
| 117 | + return ''.join(string[:visible], '...(and ', string_len - visible, ' more)') |
113 | 118 |
|
114 | 119 | def shprint(command, *args, **kwargs):
|
115 | 120 | '''Runs the command (which should be an sh.Command instance), while
|
@@ -146,7 +151,7 @@ def shprint(command, *args, **kwargs):
|
146 | 151 | msg = line.replace('\n', ' ').replace('\t', ' ').rstrip()
|
147 | 152 | if msg:
|
148 | 153 | # if len(msg) > msg_width: msg = msg[:(msg_width - 3)] + '...'
|
149 |
| - sys.stdout.write('{}\r{}{:<{width}.{width}}'.format(Style.RESET_ALL, msg_hdr, msg, width=msg_width)) |
| 154 | + sys.stdout.write('{}\r{}{:<{width}}'.format(Style.RESET_ALL, msg_hdr, shorten_string(msg, msg_width), width=msg_width)) |
150 | 155 | sys.stdout.flush()
|
151 | 156 | need_closing_newline = True
|
152 | 157 | else:
|
|
0 commit comments