diff --git a/CHANGELOG b/CHANGELOG index e3f3470e..48c4c36a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/manuals/ponysay.texinfo b/manuals/ponysay.texinfo index 9f1a6236..333dbb6f 100644 --- a/manuals/ponysay.texinfo +++ b/manuals/ponysay.texinfo @@ -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 diff --git a/ponysay.py b/ponysay.py index a7e50d68..7a566b92 100755 --- a/ponysay.py +++ b/ponysay.py @@ -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~' @@ -1837,11 +1843,11 @@ class Backend(): mm = 0 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 ? + if mm + x not in map: # Too much whitespace? cols = 0 break nbsp = b[map[mm + x]] == ' ' @@ -1879,7 +1885,8 @@ class Backend(): buf += line[:indent] w -= indentc for bb in b[:bi]: - buf += bb + if bb is not None: + buf += bb w -= cols cols = 0 bi = 0