wrapping settings

This commit is contained in:
Mattias Andrée 2012-10-28 04:46:51 +01:00
parent 03ab06b8e1
commit 90990ba099
3 changed files with 35 additions and 4 deletions

View file

@ -6,6 +6,10 @@ Version 3.0
Environment variable 'PONYSAY_WRAP_HYPHEN' has been added.
Environment variable 'PONYSAY_WRAP_LIMIT' has been added.
Environment variable 'PONYSAY_WRAP_EXCEED' has been added.
Version 2.9

View file

@ -633,6 +633,22 @@ auto correction ignored. This limit can be changed by exporting the limit to
You can export what ponysay should use instead of a hyphen when wrapping messages.
The hythen is red by default, if you want to change the colour or other formating,
should should do so using the option @option{--colour-hyphen} (@option{--colour-wrap}).
@item @env{PONYSAY_WRAP_LIMIT}
@vindex @env{PONYSAY_WRAP_LIMIT}
@cindex wrapping
Defines how long a word mush be to be hyphenated. This is used for to wrap words that
are long so the output gets as pretty as possible. This s not the only condition under
which a word can be hyphenated, it can also be hyphenated if the word cannot fit
otherwise. The default value is 8.
@item @env{PONYSAY_WRAP_EXCEED}
@vindex @env{PONYSAY_WRAP_EXCEED}
@cindex wrapping
Defines how much a word must exceed the wrapping point to be hyphenated. This setting
is used togather with @env{PONYSAY_WRAP_LIMIT}. The default value is 5.
@end table
@ -2077,6 +2093,10 @@ Renamed option @option{-F} to @option{+f} and option @option{--F} to @option{++f
Environment variable @env{PONYSAY_TYPO_LIMIT} has been added.
@item
Environment variable @env{PONYSAY_WRAP_HYPHEN} has been added.
@item
Environment variable @env{PONYSAY_WRAP_LIMIT} has been added.
@item
Environment variable @env{PONYSAY_WRAP_EXCEED} has been added.
@end itemize

View file

@ -1771,6 +1771,12 @@ class Backend():
@return :str The message wrapped
'''
def __wrapMessage(self, message, wrap):
wraplimit = os.environ['PONYSAY_WRAP_LIMIT'] if 'PONYSAY_WRAP_LIMIT' in os.environ else ''
wraplimit = 8 if len(wraplimit) == 0 else int(wraplimit)
wrapexceed = os.environ['PONYSAY_WRAP_EXCEED'] if 'PONYSAY_WRAP_EXCEED' in os.environ else ''
wrapexceed = 5 if len(wrapexceed) == 0 else int(wrapexceed)
buf = ''
try:
AUTO_PUSH = '\033[01010~'
@ -1838,7 +1844,7 @@ class Backend():
bisub = 0
iwrap = wrap - (0 if indent == 1 else indentc)
while ((w > 8) and (cols > w + 5)) or (cols > iwrap): # TODO make configurable
while ((w > wraplimit) and (cols > w + wrapexceed)) or (cols > iwrap):
## wrap
x = w;
if mm + x not in map: # Too much whitespace?
@ -1879,6 +1885,7 @@ class Backend():
buf += line[:indent]
w -= indentc
for bb in b[:bi]:
if bb is not None:
buf += bb
w -= cols
cols = 0