MCPcopy Index your code
hub / github.com/kivy/python-for-android / shorten_string

Function shorten_string

pythonforandroid/logger.py:95–109  ·  view source on GitHub ↗

make limited length string in form: "the string is very lo...(and 15 more)"

(string, max_width)

Source from the content-addressed store, hash-verified

93
94
95def shorten_string(string, max_width):
96 ''' make limited length string in form:
97 "the string is very lo...(and 15 more)"
98 '''
99 string_len = len(string)
100 if string_len <= max_width:
101 return string
102 visible = max_width - 16 - int(log10(string_len))
103 # expected suffix len "...(and XXXXX more)"
104 if not isinstance(string, str):
105 visstring = str(string[:visible], errors='ignore')
106 else:
107 visstring = string[:visible]
108 return u''.join((visstring, u'...(and ',
109 str(string_len - visible), u' more)'))
110
111
112def get_console_width():

Callers 1

shprintFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected