aboutsummaryrefslogtreecommitdiff
path: root/ponysay.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2012-08-18 15:02:34 +0200
committerMattias Andrée <maandree@operamail.com>2012-08-18 15:02:34 +0200
commitfeeaa47ad8b519ba2b042225e3cebb43e9a1f0ab (patch)
tree50bc443d00ab7eae7394f7251bf64f7a754b0774 /ponysay.py
parentf14e7b6c0600149e887ab13a84a8de6f9c9c5aac (diff)
downloadponysay-feeaa47ad8b519ba2b042225e3cebb43e9a1f0ab.tar.gz
ponysay-feeaa47ad8b519ba2b042225e3cebb43e9a1f0ab.tar.bz2
ponysay-feeaa47ad8b519ba2b042225e3cebb43e9a1f0ab.zip
bold outpont in --list on ponies with quotes
Diffstat (limited to 'ponysay.py')
-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();