1
1
mirror of https://github.com/chubin/cheat.sh.git synced 2024-12-26 05:23:25 +03:00

added :learn special page support

This commit is contained in:
Igor Chubin 2017-05-28 21:46:35 +00:00
parent a2358aa8db
commit 18bf238d37

View File

@ -10,6 +10,7 @@ class LearnXYAdapter(object):
self._whole_cheatsheet = self._read_cheatsheet() self._whole_cheatsheet = self._read_cheatsheet()
self._blocks = self._extract_blocks() self._blocks = self._extract_blocks()
self._topics_list = [x for x,y in self._blocks] + [":learn"]
def _read_cheatsheet(self): def _read_cheatsheet(self):
filename = os.path.join(self._learn_xy_path, self._filename) filename = os.path.join(self._learn_xy_path, self._filename)
@ -32,7 +33,7 @@ class LearnXYAdapter(object):
answer = [] answer = []
block = [] block = []
block_name = None block_name = "Start"
for before, now, after in zip([""]+lines, lines, lines[1:]): for before, now, after in zip([""]+lines, lines, lines[1:]):
new_block_name = self._is_block_separator(before, now, after) new_block_name = self._is_block_separator(before, now, after)
if new_block_name: if new_block_name:
@ -49,18 +50,24 @@ class LearnXYAdapter(object):
return answer return answer
def is_valid(self, name): def is_valid(self, name):
for x, _ in self._blocks: for x in self._topics_list:
if x == name: if x == name:
return True return True
return False return False
def get_list(self, prefix=False): def get_list(self, prefix=False):
if prefix: if prefix:
return ["%s/%s" % (self._prefix, x) for x,y in self._blocks] return ["%s/%s" % (self._prefix, x) for x in self._topics_list]
else: else:
return [x for x,y in self._blocks] return self._topics_list
def get_cheat_sheet(self, name, partial=False): def get_cheat_sheet(self, name, partial=False):
if name == ":list":
return "\n".join(self.get_list()) + "\n"
if name == ":learn":
return "\n".join(self._whole_cheatsheet) + "\n"
if partial: if partial:
possible_names = [] possible_names = []
for x, y in self._blocks: for x, y in self._blocks: