Skip to content

Commit

Permalink
Fix bugs. Add paste feature. Improve searching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneyaoo committed Jul 9, 2019
1 parent a5d24ff commit 720d81f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cheat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def main(workflow):
parser=Parser(config.getPath())
options=Options(parser, workflow)

tokens=query.strip().split(" ",2)
tokens=query.strip().split(" ",1)
tokens=[i.strip() for i in tokens if i!=""]

if len(tokens)!=2:
if len(tokens)<2:
sheetName="" if len(tokens)==0 else tokens[0]
handler=options.showAvailable if sheetName not in parser.availableSheets() else options.list
handler(sheetName)
Expand Down
13 changes: 11 additions & 2 deletions lib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ def __init__(self, parser, workflow):
return None

def search(self, sheetName, keyword):
if sheetName not in self._parser.availableSheets():
Options.warning("Cheat sheet not found.","", self._workflow)
return None
if sheetName==None:
ret=self._parser.searchAcrossAll(keyword, self._workflow)
else:
ret=self._parser.searchInSheet(keyword, sheetName, self._workflow)
if ret==[]:
Options.warning("Not found", "No match found for search {}".format(keyword), self._workflow)
return None
for item in ret:
self._workflow.add_item(
title=item["command"],
subtitle=item["comment"]
subtitle=item["comment"],
copytext=item.get("command"),
valid=True,
arg=item.get("command")
)
return None

Expand All @@ -28,7 +35,9 @@ def list(self, sheetName):
self._workflow.add_item(
title=item.get("command"),
subtitle=item.get("comment"),
valid=False
valid=True,
copytext=item.get("command"),
arg=item.get("command")
)
return None

Expand Down
3 changes: 2 additions & 1 deletion lib/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python
import os
from workflow import MATCH_ALL, MATCH_ALLCHARS

class Parser:
def __init__(self,path):
Expand Down Expand Up @@ -47,4 +48,4 @@ def __parseSheet(self, filename):
def filter(self, content, keyword, workflow):
def searchIndex(item):
return u" ".join([item["comment"],item["command"]])
return workflow.filter(keyword, content,key=searchIndex, match_on=33, min_score=40)
return workflow.filter(keyword, content,key=searchIndex, match_on=MATCH_ALL ^ MATCH_ALLCHARS, min_score=50)

0 comments on commit 720d81f

Please sign in to comment.