From feeaa47ad8b519ba2b042225e3cebb43e9a1f0ab Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Aug 2012 15:02:34 +0200 Subject: bold outpont in --list on ponies with quotes --- ponysay.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ponysay.py b/ponysay.py index 49ae08c..8de7541 100755 --- a/ponysay.py +++ b/ponysay.py @@ -53,6 +53,31 @@ class ponysay(): else: self.print_pony(args) + ''' + Returns a set with all ponies that have quotes and is displayable + ''' + def __quoters(self): + quotes = [] + quoteshash = set() + _quotes = [item[:item.index('.')] for item in os.listdir(INSTALLDIR + '/share/ponysay/quotes/')] + for quote in _quotes: + if not quote[0] == '.': + if not quote in quoteshash: + quoteshash.add(quote) + quotes.append(quote) + + ponies = set() + for ponydir in ponydirs: + for pony in os.listdir(ponydir): + if not pony[0] == '.': + p = pony[:-5] # remove .pony + for quote in quotes: + if ('+' + p + '+') in ('+' + quote + '+'): + if not p in ponies: + ponies.add(p) + + return ponies + ''' Lists the available ponies ''' @@ -60,6 +85,8 @@ class ponysay(): termsize = Popen(['stty', 'size'], stdout=PIPE).communicate()[0].decode('utf8', 'replace')[:-1].split(" ") termsize = [int(item) for item in termsize] + quoters = self.__quoters() + for ponydir in ponydirs: # Loop ponydirs print('\033[1mponyfiles located in ' + ponydir + '\033[21m') @@ -71,7 +98,8 @@ class ponysay(): x = 0 for pony in ponies: - print(pony + (" " * (width - len(pony))), end="") # Print ponyfilename + spacing = ' ' * (width - len(pony)) + print(('\033[1m' + pony + '\033[21m' if (pony in quoters) else pony) + spacing, end="") # Print ponyfilename x += width if x > (termsize[1] - width): # If too wide, make new line print(); -- cgit