merge changes from rlx
This commit is contained in:
commit
5bcc2af2fd
1 changed files with 28 additions and 28 deletions
|
@ -63,34 +63,34 @@ def wrap(text, width):
|
||||||
)
|
)
|
||||||
|
|
||||||
def wrapString(string, length, separator, balance):
|
def wrapString(string, length, separator, balance):
|
||||||
if balance:
|
if balance:
|
||||||
# balance lines: test if same number of lines
|
# balance lines: test if same number of lines
|
||||||
# can be achieved with a shorter line length
|
# can be achieved with a shorter line length
|
||||||
lines = wrapString(string, length, separator, False).split(separator)
|
lines = wrapString(string, length, separator, False).split(separator)
|
||||||
if len(lines) > 1:
|
if len(lines) > 1:
|
||||||
while length > max(map(lambda x : len(x), string.split(' '))):
|
while length > max(map(lambda x : len(x), string.split(' '))):
|
||||||
length -= 1
|
length -= 1
|
||||||
if len(wrapString(string, length, separator, False).split(separator)) > len(lines):
|
if len(wrapString(string, length, separator, False).split(separator)) > len(lines):
|
||||||
length += 1
|
length += 1
|
||||||
break
|
break
|
||||||
words = string.split(' ')
|
words = string.split(' ')
|
||||||
lines = ['']
|
lines = ['']
|
||||||
for word in words:
|
for word in words:
|
||||||
if len(lines[len(lines) - 1] + word + ' ') <= length + 1:
|
if len(lines[len(lines) - 1] + word + ' ') <= length + 1:
|
||||||
# word fits in current line
|
# word fits in current line
|
||||||
lines[len(lines) - 1] += word + ' ';
|
lines[len(lines) - 1] += word + ' ';
|
||||||
else:
|
else:
|
||||||
if len(word) <= length:
|
if len(word) <= length:
|
||||||
# word fits in next line
|
# word fits in next line
|
||||||
lines.append(word + ' ')
|
lines.append(word + ' ')
|
||||||
else:
|
else:
|
||||||
# word is longer than line
|
# word is longer than line
|
||||||
position = length - len(lines[len(lines) - 1]) + 1
|
position = length - len(lines[len(lines) - 1])
|
||||||
lines[len(lines) - 1] += word[0:position]
|
lines[len(lines) - 1] += word[0:position]
|
||||||
for i in range(position, len(word), length):
|
for i in range(position, len(word), length):
|
||||||
lines.append(word[i:i+length]);
|
lines.append(word[i:i+length]);
|
||||||
lines[len(lines) - 1] += ' '
|
lines[len(lines) - 1] += ' '
|
||||||
return separator.join(lines).strip()
|
return separator.join(lines).strip()
|
||||||
|
|
||||||
|
|
||||||
def truncateString(s, num):
|
def truncateString(s, num):
|
||||||
|
|
Loading…
Reference in a new issue