-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathautocomplete.py
More file actions
45 lines (35 loc) · 1.5 KB
/
autocomplete.py
File metadata and controls
45 lines (35 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import imp
from prompt_toolkit import prompt
from prompt_toolkit.completion import Completer, Completion
from dynamic.validation import Arg0_Validator
command_dict = {
'dynamic':{
'-s': '--search for a question',
'-v': '--current version',
'-no': '--notion-login',
'-c': '--custom API Key',
'-p': '--access playbook',
'-st': '--start info',
'-h': '--help',
'-GET': '--API GET',
'-POST': '--API POST',
'-DELETE': 'API DELETE'
}
}
class CustomCompleter(Completer):
def __init__(self, command_dict):
self.command_dict = command_dict
def get_completions(self, document, complete_event):
matches = [name for name in self.command_dict.keys() if document.text in name]
for m in matches:
yield Completion(m, start_position=-len(document.text_before_cursor),
display = m)
if(document.text[0:7] == 'dynamic'):
matches = [name for name in self.command_dict['dynamic'].keys() if document.get_word_before_cursor() in name]
for m in matches:
yield Completion(m, start_position=-len(document.get_word_under_cursor()),
display = m, display_meta = self.command_dict['dynamic'][m])
completer = CustomCompleter(command_dict)
def take_input():
answer = prompt('>>> ', completer = completer, validator=Arg0_Validator())
return answer