Skip to content

Commit 4275955

Browse files
committed
toolchain log output cosmetic
1 parent 1a36bc0 commit 4275955

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pythonforandroid/toolchain.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from datetime import datetime
3131
from distutils.spawn import find_executable
3232
from tempfile import mkdtemp
33+
from math import log10
3334
try:
3435
from urllib.request import FancyURLopener
3536
except ImportError:
@@ -105,11 +106,15 @@ def pretty_log_dists(dists, log_func=info):
105106
for line in infos:
106107
log_func('\t' + line)
107108

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:
110115
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)')
113118

114119
def shprint(command, *args, **kwargs):
115120
'''Runs the command (which should be an sh.Command instance), while
@@ -146,7 +151,7 @@ def shprint(command, *args, **kwargs):
146151
msg = line.replace('\n', ' ').replace('\t', ' ').rstrip()
147152
if msg:
148153
# 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))
150155
sys.stdout.flush()
151156
need_closing_newline = True
152157
else:

0 commit comments

Comments
 (0)