mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-22 04:27:58 +01:00
word wrapping bug fixed + word wrapper supports soft hythens and non-breaking space + word wrapper colour inserted hyphens red
This commit is contained in:
parent
1ca607912a
commit
e6bdf2e5ba
3 changed files with 67 additions and 19 deletions
10
CHANGELOG
10
CHANGELOG
|
@ -1,4 +1,14 @@
|
||||||
|
Version 2.8
|
||||||
|
|
||||||
|
Support for explicit hypthenation using soft hyphens had been added to the word wrapper.
|
||||||
|
|
||||||
|
Support for explicit non-word wrapping using non-breaking space had been added to the word wrapper.
|
||||||
|
|
||||||
|
The word wrapper colours the inserted hyphens in red.
|
||||||
|
|
||||||
|
|
||||||
Version 2.7
|
Version 2.7
|
||||||
|
|
||||||
New ponies: basil, cloudkicker, cerberus, cow, derpysad, flowertrio, frederickhorseshoepin,
|
New ponies: basil, cloudkicker, cerberus, cow, derpysad, flowertrio, frederickhorseshoepin,
|
||||||
horsemd, jeffletroski, jesuspezuna, joe, joetuxedo, manticore, meadowsong,
|
horsemd, jeffletroski, jesuspezuna, joe, joetuxedo, manticore, meadowsong,
|
||||||
meliot, pinkiegummydisguise, seaswirl, theodoredonaldkerabatsos, turf,
|
meliot, pinkiegummydisguise, seaswirl, theodoredonaldkerabatsos, turf,
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
@documentlanguage en
|
@documentlanguage en
|
||||||
@finalout
|
@finalout
|
||||||
@c %**end of header
|
@c %**end of header
|
||||||
@set VERSION 2.7
|
@set VERSION 2.8
|
||||||
|
|
||||||
@defindex op
|
@defindex op
|
||||||
@synindex op vr
|
@synindex op vr
|
||||||
|
@ -1848,6 +1848,18 @@ sequences.
|
||||||
@cindex versions
|
@cindex versions
|
||||||
@cindex previous releases
|
@cindex previous releases
|
||||||
|
|
||||||
|
|
||||||
|
@heading Version 2.8
|
||||||
|
@itemize @bullet
|
||||||
|
@item
|
||||||
|
Support for explicit hypthenation using soft hyphens had been added to the word wrapper.
|
||||||
|
@item
|
||||||
|
Support for explicit non-word wrapping using non-breaking space had been added to the word wrapper.
|
||||||
|
@item
|
||||||
|
The word wrapper colours the inserted hyphens in red.
|
||||||
|
@end itemize
|
||||||
|
|
||||||
|
|
||||||
@heading Version 2.7
|
@heading Version 2.7
|
||||||
@itemize @bullet
|
@itemize @bullet
|
||||||
@item
|
@item
|
||||||
|
|
62
ponysay.py
62
ponysay.py
|
@ -1473,6 +1473,8 @@ class Backend():
|
||||||
Wraps the message
|
Wraps the message
|
||||||
'''
|
'''
|
||||||
def __wrapMessage(self, message, wrap):
|
def __wrapMessage(self, message, wrap):
|
||||||
|
AUTO_PUSH = '\033[01010~'
|
||||||
|
AUTO_POP = '\033[10101~'
|
||||||
lines = message.split('\n')
|
lines = message.split('\n')
|
||||||
buf = ''
|
buf = ''
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
@ -1484,10 +1486,11 @@ class Backend():
|
||||||
(i, n) = (0, len(line))
|
(i, n) = (0, len(line))
|
||||||
while i <= n:
|
while i <= n:
|
||||||
d = None
|
d = None
|
||||||
if i != n:
|
if i < n:
|
||||||
d = line[i]
|
d = line[i]
|
||||||
i += 1
|
i += 1
|
||||||
if d == '\033': # TODO this should use self.__getcolour()
|
if d == '\033': # TODO this should use self.__getcolour()
|
||||||
|
## Invisible stuff
|
||||||
b[bi] = d
|
b[bi] = d
|
||||||
bi += 1
|
bi += 1
|
||||||
b[bi] = line[i]
|
b[bi] = line[i]
|
||||||
|
@ -1513,6 +1516,7 @@ class Backend():
|
||||||
bi += 1
|
bi += 1
|
||||||
i += 1
|
i += 1
|
||||||
elif (d is not None) and (d != ' '):
|
elif (d is not None) and (d != ' '):
|
||||||
|
## Fetch word
|
||||||
if indent == -1:
|
if indent == -1:
|
||||||
indent = i - 1
|
indent = i - 1
|
||||||
for j in range(0, indent):
|
for j in range(0, indent):
|
||||||
|
@ -1520,27 +1524,46 @@ class Backend():
|
||||||
indentc += 1
|
indentc += 1
|
||||||
b[bi] = d
|
b[bi] = d
|
||||||
bi += 1
|
bi += 1
|
||||||
if not UCS.isCombining(d):
|
if (not UCS.isCombining(d)) and (d != ''):
|
||||||
cols += 1
|
cols += 1
|
||||||
map[cols] = bi
|
map[cols] = bi
|
||||||
else:
|
else:
|
||||||
|
## Wrap?
|
||||||
mm = 0
|
mm = 0
|
||||||
while (w > 8) and (cols > w + 3):
|
bisub = 0
|
||||||
mm += w - 1
|
iwrap = wrap - (0 if indent == 1 else indentc)
|
||||||
m = map[mm]
|
|
||||||
for bb in b[:m]:
|
while ((w > 8) and (cols > w + 5)) or (cols > iwrap): # TODO make configurable
|
||||||
|
## wrap
|
||||||
|
x = w;
|
||||||
|
nbsp = b[map[mm + x]] == ' '
|
||||||
|
m = map[mm + x]
|
||||||
|
|
||||||
|
if ('' in b[bisub : m]) and not nbsp:
|
||||||
|
hyphen = m - 1
|
||||||
|
while b[hyphen] != '':
|
||||||
|
hyphen -= 1
|
||||||
|
while map[mm + x] > hyphen: ## Only looking backward, if foreward is required the word is probabily not hythenated correctly
|
||||||
|
x -= 1
|
||||||
|
x += 1
|
||||||
|
m = map[mm + x]
|
||||||
|
|
||||||
|
mm += x - (0 if nbsp else 1) ## − 1 so we have space for a hythen
|
||||||
|
|
||||||
|
for bb in b[bisub : m]:
|
||||||
buf += bb
|
buf += bb
|
||||||
buf += '-\n'
|
buf += '\n' if nbsp else '\0\n'
|
||||||
cols -= w - 1
|
cols -= x - (0 if nbsp else 1)
|
||||||
m += w -1
|
bisub = m
|
||||||
bi -= m
|
|
||||||
bb = b[m:]
|
w = iwrap
|
||||||
for j in range(0, bi):
|
|
||||||
b[j] = bb[j]
|
|
||||||
w = wrap
|
|
||||||
if indent != -1:
|
if indent != -1:
|
||||||
buf += line[:indent]
|
buf += line[:indent]
|
||||||
w -= indentc
|
|
||||||
|
for j in range(bisub, bi):
|
||||||
|
b[j - bisub] = b[j]
|
||||||
|
bi -= bisub
|
||||||
|
|
||||||
if cols > w:
|
if cols > w:
|
||||||
buf += '\n'
|
buf += '\n'
|
||||||
w = wrap
|
w = wrap
|
||||||
|
@ -1552,7 +1575,7 @@ class Backend():
|
||||||
w -= cols
|
w -= cols
|
||||||
cols = 0
|
cols = 0
|
||||||
bi = 0
|
bi = 0
|
||||||
if d == -1:
|
if d is None:
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
if w > 0:
|
if w > 0:
|
||||||
|
@ -1564,9 +1587,12 @@ class Backend():
|
||||||
if indent != -1:
|
if indent != -1:
|
||||||
buf + line[:indent]
|
buf + line[:indent]
|
||||||
w -= indentc
|
w -= indentc
|
||||||
|
|
||||||
buf += '\n'
|
buf += '\n'
|
||||||
return '\n'.join(line.rstrip() for line in buf[:-1].split('\n'))
|
|
||||||
|
rc = '\n'.join(line.rstrip() for line in buf[:-1].split('\n'));
|
||||||
|
rc = rc.replace('', ''); # remove soft hyphens
|
||||||
|
rc = rc.replace('\0', '%s%s%s' % (AUTO_PUSH, '\033[31m-', AUTO_POP)) # TODO make configurable
|
||||||
|
return rc
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue