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_HYPHEN' has been added.
Environment variable 'PONYSAY_WRAP_LIMIT' has been added.
Environment variable 'PONYSAY_WRAP_EXCEED' has been added.
Version 2.9 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. 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, 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}). 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 @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. Environment variable @env{PONYSAY_TYPO_LIMIT} has been added.
@item @item
Environment variable @env{PONYSAY_WRAP_HYPHEN} has been added. 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 @end itemize

View file

@ -1771,6 +1771,12 @@ class Backend():
@return :str The message wrapped @return :str The message wrapped
''' '''
def __wrapMessage(self, message, wrap): 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 = '' buf = ''
try: try:
AUTO_PUSH = '\033[01010~' AUTO_PUSH = '\033[01010~'
@ -1837,11 +1843,11 @@ class Backend():
mm = 0 mm = 0
bisub = 0 bisub = 0
iwrap = wrap - (0 if indent == 1 else indentc) 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 ## wrap
x = w; x = w;
if mm + x not in map: # Too much whitespace ? if mm + x not in map: # Too much whitespace?
cols = 0 cols = 0
break break
nbsp = b[map[mm + x]] == ' ' nbsp = b[map[mm + x]] == ' '
@ -1879,7 +1885,8 @@ class Backend():
buf += line[:indent] buf += line[:indent]
w -= indentc w -= indentc
for bb in b[:bi]: for bb in b[:bi]:
buf += bb if bb is not None:
buf += bb
w -= cols w -= cols
cols = 0 cols = 0
bi = 0 bi = 0