mirror of
https://github.com/erkin/ponysay.git
synced 2025-01-31 18:36:43 +01:00
print metadata with --info and ++info
This commit is contained in:
parent
1fdb1085d1
commit
62d61d84c1
1 changed files with 54 additions and 17 deletions
43
ponysay.py
43
ponysay.py
|
@ -1740,14 +1740,18 @@ class Backend():
|
||||||
Process all data
|
Process all data
|
||||||
'''
|
'''
|
||||||
def parse(self):
|
def parse(self):
|
||||||
self.__expandMessage()
|
|
||||||
self.__unpadMessage()
|
|
||||||
self.__loadFile()
|
self.__loadFile()
|
||||||
|
|
||||||
if self.pony.startswith('$$$\n'):
|
if self.pony.startswith('$$$\n'):
|
||||||
self.pony = self.pony[4:]
|
self.pony = self.pony[4:]
|
||||||
infoend = self.pony.index('\n$$$\n')
|
infoend = self.pony.index('\n$$$\n')
|
||||||
info = self.pony[:infoend].split('\n')
|
info = self.pony[:infoend]
|
||||||
|
if self.infolevel == 2:
|
||||||
|
self.message = Backend.formatInfo(info)
|
||||||
|
elif self.infolevel == 1:
|
||||||
|
self.pony = Backend.formatInfo(info).replace('$'), ('$$')
|
||||||
|
else:
|
||||||
|
info = info.split('\n')
|
||||||
for line in info:
|
for line in info:
|
||||||
sep = line.find(':')
|
sep = line.find(':')
|
||||||
if sep > 0:
|
if sep > 0:
|
||||||
|
@ -1762,12 +1766,45 @@ class Backend():
|
||||||
self.balloonbottom = int(value)
|
self.balloonbottom = int(value)
|
||||||
printinfo(info)
|
printinfo(info)
|
||||||
self.pony = self.pony[infoend + 5:]
|
self.pony = self.pony[infoend + 5:]
|
||||||
|
elif self.infolevel == 2:
|
||||||
|
self.message = '\033[1;31mI am the mysterious mare...\033[21;3m'
|
||||||
|
elif self.infolevel == 1:
|
||||||
|
self.pony = 'There is not metadata for this pony file'
|
||||||
self.pony = self.mode + self.pony
|
self.pony = self.mode + self.pony
|
||||||
|
|
||||||
|
self.__expandMessage()
|
||||||
|
self.__unpadMessage()
|
||||||
self.__processPony()
|
self.__processPony()
|
||||||
self.__truncate()
|
self.__truncate()
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
Format metadata to be nicely printed, this include bold keys
|
||||||
|
|
||||||
|
@param info:str The metadata
|
||||||
|
@return :str The metadata nicely formated
|
||||||
|
'''
|
||||||
|
@staticmethod
|
||||||
|
def formatInfo(info):
|
||||||
|
info = info.split('\n')
|
||||||
|
tags = ''
|
||||||
|
comment = ''
|
||||||
|
for line in info:
|
||||||
|
sep = line.find(':')
|
||||||
|
if sep > 0:
|
||||||
|
key = line[:sep].strip()
|
||||||
|
value = line[sep + 1:].strip()
|
||||||
|
if key == key.upper():
|
||||||
|
line = '\033[1m%s\033[21m: %s\n' % (key, value)
|
||||||
|
tags += line
|
||||||
|
continue
|
||||||
|
comment += '\n' + line
|
||||||
|
comment = comment.lstrip('\n')
|
||||||
|
if len(comment) > 0:
|
||||||
|
comment = '\n' + comment
|
||||||
|
return tags + comment
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Remove padding spaces fortune cookies are padded with whitespace (damn featherbrains)
|
Remove padding spaces fortune cookies are padded with whitespace (damn featherbrains)
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue