mirror of
https://github.com/cheat/cheat.git
synced 2024-11-16 08:58:28 +01:00
Some minor modification (open inside the generator for better readability) + one bug fixe (the last block wasnt yiel by the generator)
This commit is contained in:
parent
d85fab763b
commit
69428a7279
1 changed files with 20 additions and 17 deletions
19
cheat
19
cheat
|
@ -179,24 +179,27 @@ class CheatSheets(object):
|
||||||
return ('\n'.join(sorted(['%s [%s]' % (key.ljust(max_command), value)
|
return ('\n'.join(sorted(['%s [%s]' % (key.ljust(max_command), value)
|
||||||
for key, value in self.sheets.items()])))
|
for key, value in self.sheets.items()])))
|
||||||
|
|
||||||
def __parse_cheat_command_block(self, cheat_fp):
|
def __parse_cheat_command_block(self, cheat):
|
||||||
|
"""Parse text blocks inside specified sheet file"""
|
||||||
block = ""
|
block = ""
|
||||||
for line in cheat_fp.readlines():
|
path = os.path.join(self.sheets[cheat], cheat)
|
||||||
if line == '\n' or line == '':
|
with open(path) as fp:
|
||||||
|
for line in fp.readlines():
|
||||||
|
if line == '\n':
|
||||||
yield block
|
yield block
|
||||||
block = ""
|
block = ""
|
||||||
else:
|
else:
|
||||||
block += line
|
block += line
|
||||||
|
yield block
|
||||||
|
|
||||||
def search(self, term):
|
def search(self, term):
|
||||||
for sheet, sheet_dir in self.sheets.iteritems():
|
"""Search for a term in sheetcheats"""
|
||||||
path = os.path.join(sheet_dir, sheet)
|
for cheat in self.sheets.keys():
|
||||||
with open(path) as f:
|
|
||||||
output = ''
|
output = ''
|
||||||
for block in self.__parse_cheat_command_block(f):
|
for block in self.__parse_cheat_command_block(cheat):
|
||||||
if term in block:
|
if term in block:
|
||||||
if not output:
|
if not output:
|
||||||
output = sheet + ":\n"
|
output = cheat + ":\n"
|
||||||
output += ''.join([" " + line + '\n' for line
|
output += ''.join([" " + line + '\n' for line
|
||||||
in block.split('\n')])
|
in block.split('\n')])
|
||||||
if output:
|
if output:
|
||||||
|
|
Loading…
Reference in a new issue