aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xponysay.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/ponysay.py b/ponysay.py
index 49ae08c..8de7541 100755
--- a/ponysay.py
+++ b/ponysay.py
@@ -54,12 +54,39 @@ class ponysay():
'''
+ 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
'''
def list(self):
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();