From 03ab06b8e1e63ef3eb8d26065389b4464e6e97f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= Date: Sun, 28 Oct 2012 04:09:53 +0100 Subject: [PATCH] environment variables PONYSAY_{TYPO_LIMIT,WRAP_HYPHEN} --- CHANGELOG | 4 ++++ manuals/ponysay.texinfo | 27 +++++++++++++++++++++++++++ ponysay.py | 13 ++++++++++--- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 436b8219..e3f3470e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,10 @@ Version 3.0 Renamed option -F to +f and option --F to ++f. + Environment variable 'PONYSAY_TYPO_LIMIT' has been added. + + Environment variable 'PONYSAY_WRAP_HYPHEN' has been added. + Version 2.9 diff --git a/manuals/ponysay.texinfo b/manuals/ponysay.texinfo index ed8fdf50..9f1a6236 100644 --- a/manuals/ponysay.texinfo +++ b/manuals/ponysay.texinfo @@ -610,6 +610,29 @@ ponysay how your TTY palette looks, this feature lets you get the best images in TTY if you have Kernel Mode Setting (KMS) support. See @ref{KMS ponies} for information on how to use this. + +@item @env{PONYSAY_TYPO_LIMIT} +@vindex @env{PONYSAY_TYPO_LIMIT} +@cindex auto correction +@cindex typo correction +@cindex spello correction + +ponysay is able to auto correct misspelled pony names and balloon style name. +Without consideration for transpositioning, the distance between two words are +measured in the number of edits needed to get from one word to the other, with +weighting on some character changes used to favour spellos over typos. + +By default if the weighted distance is greater than 5 for the closest words, +auto correction ignored. This limit can be changed by exporting the limit to +@env{PONYSAY_TYPO_LIMIT}; setting the limit to zero will disable auto correction. + +@item @env{PONYSAY_WRAP_HYPHEN} +@vindex @env{PONYSAY_WRAP_HYPHEN} +@cindex wrapping + +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}). @end table @@ -2050,6 +2073,10 @@ sequences. @itemize @bullet @item Renamed option @option{-F} to @option{+f} and option @option{--F} to @option{++f}. +@item +Environment variable @env{PONYSAY_TYPO_LIMIT} has been added. +@item +Environment variable @env{PONYSAY_WRAP_HYPHEN} has been added. @end itemize diff --git a/ponysay.py b/ponysay.py index 8a8a10c9..a7e50d68 100755 --- a/ponysay.py +++ b/ponysay.py @@ -334,7 +334,9 @@ class Ponysay(): if not alt: autocorrect = SpelloCorrecter(ponydirs, '.pony') (alternatives, dist) = autocorrect.correct(pony) - if (len(alternatives) > 0) and (dist <= 5): # TODO the limit `dist` should be configureable + limit = os.environ['PONYSAY_TYPO_LIMIT'] if 'PONYSAY_TYPO_LIMIT' in os.environ else '' + limit = 5 if len(limit) == 0 else int(dist) + if (len(alternatives) > 0) and (dist <= limit): return self.__getponypath(alternatives, True) sys.stderr.write('I have never heard of anypony named %s\n' % (pony)); exit(1) @@ -691,7 +693,9 @@ class Ponysay(): if not alt: autocorrect = SpelloCorrecter(balloondirs, '.think' if isthink else '.say') (alternatives, dist) = autocorrect.correct(balloon) - if (len(alternatives) > 0) and (dist <= 5): # TODO the limit `dist` should be configureable + limit = os.environ['PONYSAY_TYPO_LIMIT'] if 'PONYSAY_TYPO_LIMIT' in os.environ else '' + limit = 5 if len(limit) == 0 else int(dist) + if (len(alternatives) > 0) and (dist <= limit): return self.__getballoonpath(alternatives, True) sys.stderr.write('That balloon style %s does not exist\n' % (balloon)); exit(1) @@ -826,10 +830,13 @@ class Ponysay(): balloon = self.__getballoon(balloonfile) if args.opts['-o'] is None else None ## Get hyphen style + hyphen = environ['PONYSAY_BOTTOM'] if 'PONYSAY_BOTTOM' in os.environ else None + if (hyphen is None) or (len(hyphen) == 0): + hyphen = '-' hyphencolour = '' if args.opts['--colour-wrap'] is not None: hyphencolour = '\033[' + ';'.join(args.opts['--colour-wrap']) + 'm' - hyphen = '\033[31m' + hyphencolour + '-' # TODO make configurable + hyphen = '\033[31m' + hyphencolour + hyphen ## Link and balloon colouring linkcolour = ''