mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-26 06:07:59 +01:00
bold outpont in --list on ponies with quotes
This commit is contained in:
parent
f14e7b6c06
commit
feeaa47ad8
1 changed files with 29 additions and 1 deletions
30
ponysay.py
30
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();
|
||||
|
|
Loading…
Reference in a new issue