New Feature: Can now handle quotations
This commit is contained in:
parent
ee80fa42d3
commit
ffc48a6430
23
Rex.py
23
Rex.py
@ -1,5 +1,4 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import aiojobs
|
|
||||||
import inspect
|
import inspect
|
||||||
import traceback
|
import traceback
|
||||||
from prompt_toolkit import PromptSession
|
from prompt_toolkit import PromptSession
|
||||||
@ -8,6 +7,7 @@ from prompt_toolkit.completion import Completer
|
|||||||
from prompt_toolkit.completion import Completion
|
from prompt_toolkit.completion import Completion
|
||||||
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
||||||
from fuzzywuzzy import fuzz
|
from fuzzywuzzy import fuzz
|
||||||
|
from shlex import split
|
||||||
|
|
||||||
# @@@@
|
# @@@@
|
||||||
# &@((((((((@@&(@@@
|
# &@((((((((@@&(@@@
|
||||||
@ -109,7 +109,20 @@ class _CompletionLookup(Completer):
|
|||||||
|
|
||||||
# Dont touch it; it works...
|
# Dont touch it; it works...
|
||||||
def get_completions(self, document, complete_event):
|
def get_completions(self, document, complete_event):
|
||||||
words = document.text.split(" ")
|
try:
|
||||||
|
words = split(document.text)
|
||||||
|
except ValueError:
|
||||||
|
# Will happen, if the user opened a " or ' and hasn't closed it yet...
|
||||||
|
# Were just gonna pretend he did already close it and try again...
|
||||||
|
try:
|
||||||
|
if document.text.find('"')!=-1:
|
||||||
|
words = split(document.text+'"')
|
||||||
|
elif document.text.find("'")!=-1:
|
||||||
|
words = split(document.text+"'")
|
||||||
|
else:
|
||||||
|
raise ValueError("Unable to auto-close quotation")
|
||||||
|
except ValueError:
|
||||||
|
words = document.text.split(" ")
|
||||||
pos = self.cmds
|
pos = self.cmds
|
||||||
index = -1
|
index = -1
|
||||||
# For evere entered 'word'
|
# For evere entered 'word'
|
||||||
@ -160,7 +173,7 @@ class Rex():
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
words = inp.split(" ")
|
words = split(inp)
|
||||||
pos = self.cmds
|
pos = self.cmds
|
||||||
index = 0
|
index = 0
|
||||||
for i,word in enumerate(words):
|
for i,word in enumerate(words):
|
||||||
@ -202,3 +215,7 @@ class Rex():
|
|||||||
|
|
||||||
async def setToolbarMsg(self, msg: str, col: str = "bg:black"):
|
async def setToolbarMsg(self, msg: str, col: str = "bg:black"):
|
||||||
self.toolbar = [(col, " "+msg)]
|
self.toolbar = [(col, " "+msg)]
|
||||||
|
|
||||||
|
if __name__=="__main__":
|
||||||
|
rex = Rex()
|
||||||
|
rex.runFromSync()
|
||||||
|
3
TODO.txt
3
TODO.txt
@ -1,5 +1,2 @@
|
|||||||
- Refactor parsing logic
|
- Refactor parsing logic
|
||||||
- Understand quotes (and don't split at spaces within quotes)
|
|
||||||
- Syntax information in toolbar (configurable)
|
- Syntax information in toolbar (configurable)
|
||||||
- Colorful Exceptions?
|
|
||||||
- Support for other delimiter than " " e.g. "."
|
|
||||||
|
Loading…
Reference in New Issue
Block a user