From 7586505f2b40b8a8d6f3a2aa7d6356bfdc22ba93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= Date: Sat, 17 Aug 2013 07:10:30 +0200 Subject: [PATCH] split out logic for the getting the truncation column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/ponysay.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ponysay.py b/src/ponysay.py index 3bb62b17..5985f35e 100755 --- a/src/ponysay.py +++ b/src/ponysay.py @@ -915,9 +915,7 @@ class Ponysay(): print('\033[H\033[2J', end='') ## Get width truncation and wrapping - env_width = os.environ['PONYSAY_FULL_WIDTH'] if 'PONYSAY_FULL_WIDTH' in os.environ else None - if env_width is None: env_width = '' - widthtruncation = gettermsize()[1] if env_width not in ('yes', 'y', '1') else None + widthtruncation = self.__getWidthTruncation() messagewrap = 60 if (args.opts['-W'] is not None) and (len(args.opts['-W'][0]) > 0): messagewrap = args.opts['-W'][0] @@ -1060,4 +1058,15 @@ class Ponysay(): Popen(pngcmd, stdout=os.fdopen(pngpipe[1], 'w'), shell=True).wait() pony = '/proc/' + str(os.getpid()) + '/fd/' + str(pngpipe[0]) return pony + + + def __getWidthTruncation(self): + ''' + Gets the width trunction setting + + @return :int? The column the truncate the output at, or `None` to not truncate it + ''' + env_width = os.environ['PONYSAY_FULL_WIDTH'] if 'PONYSAY_FULL_WIDTH' in os.environ else None + if env_width is None: env_width = 'auto' + return gettermsize()[1] if env_width not in ('yes', 'y', '1') else None