show "you can use tabs" reminder if code was input without completion
refs #15
This commit is contained in:
parent
62b069dea6
commit
b3763f9e78
|
@ -19,12 +19,14 @@ def extract_channel_id(code):
|
||||||
return channel_id
|
return channel_id
|
||||||
|
|
||||||
class CodeInputter:
|
class CodeInputter:
|
||||||
def __init__(self, initial_channelids, get_channel_ids, code_length):
|
def __init__(self, initial_channelids, get_channel_ids, code_length,
|
||||||
|
used_completion_f):
|
||||||
self._initial_channelids = initial_channelids
|
self._initial_channelids = initial_channelids
|
||||||
self._get_channel_ids = get_channel_ids
|
self._get_channel_ids = get_channel_ids
|
||||||
self.code_length = code_length
|
self.code_length = code_length
|
||||||
self.last_text = None # memoize for a speedup
|
self.last_text = None # memoize for a speedup
|
||||||
self.last_matches = None
|
self.last_matches = None
|
||||||
|
self._used_completion_f = used_completion_f
|
||||||
|
|
||||||
def get_current_channel_ids(self):
|
def get_current_channel_ids(self):
|
||||||
if self._initial_channelids is not None:
|
if self._initial_channelids is not None:
|
||||||
|
@ -43,6 +45,7 @@ class CodeInputter:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def completer(self, text, state):
|
def completer(self, text, state):
|
||||||
|
self._used_completion_f()
|
||||||
#if state == 0:
|
#if state == 0:
|
||||||
# print("", file=sys.stderr)
|
# print("", file=sys.stderr)
|
||||||
#print("completer: '%s' %d '%d'" % (text, state,
|
#print("completer: '%s' %d '%d'" % (text, state,
|
||||||
|
@ -84,9 +87,13 @@ class CodeInputter:
|
||||||
|
|
||||||
def input_code_with_completion(prompt, initial_channelids, get_channel_ids,
|
def input_code_with_completion(prompt, initial_channelids, get_channel_ids,
|
||||||
code_length):
|
code_length):
|
||||||
|
used_completion = []
|
||||||
|
def used_completion_f():
|
||||||
|
used_completion.append(True)
|
||||||
try:
|
try:
|
||||||
import readline
|
import readline
|
||||||
c = CodeInputter(initial_channelids, get_channel_ids, code_length)
|
c = CodeInputter(initial_channelids, get_channel_ids, code_length,
|
||||||
|
used_completion_f)
|
||||||
if "libedit" in readline.__doc__:
|
if "libedit" in readline.__doc__:
|
||||||
readline.parse_and_bind("bind ^I rl_complete")
|
readline.parse_and_bind("bind ^I rl_complete")
|
||||||
else:
|
else:
|
||||||
|
@ -99,7 +106,7 @@ def input_code_with_completion(prompt, initial_channelids, get_channel_ids,
|
||||||
# Code is str(bytes) on py2, and str(unicode) on py3. We want unicode.
|
# Code is str(bytes) on py2, and str(unicode) on py3. We want unicode.
|
||||||
if isinstance(code, bytes):
|
if isinstance(code, bytes):
|
||||||
code = code.decode("utf-8")
|
code = code.decode("utf-8")
|
||||||
return code
|
return (code, bool(used_completion))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
code = input_code_with_completion("Enter wormhole code: ",
|
code = input_code_with_completion("Enter wormhole code: ",
|
||||||
|
|
|
@ -123,12 +123,15 @@ class _InputCode:
|
||||||
with self._timing.add("input code", waiting="user"):
|
with self._timing.add("input code", waiting="user"):
|
||||||
t = self._reactor.addSystemEventTrigger("before", "shutdown",
|
t = self._reactor.addSystemEventTrigger("before", "shutdown",
|
||||||
self._warn_readline)
|
self._warn_readline)
|
||||||
code = yield deferToThread(codes.input_code_with_completion,
|
res = yield deferToThread(codes.input_code_with_completion,
|
||||||
self._prompt,
|
self._prompt,
|
||||||
initial_nameplate_ids,
|
initial_nameplate_ids,
|
||||||
self._list_blocking,
|
self._list_blocking,
|
||||||
self._code_length)
|
self._code_length)
|
||||||
|
(code, used_completion) = res
|
||||||
self._reactor.removeSystemEventTrigger(t)
|
self._reactor.removeSystemEventTrigger(t)
|
||||||
|
if not used_completion:
|
||||||
|
self._remind_about_tab()
|
||||||
returnValue(code)
|
returnValue(code)
|
||||||
|
|
||||||
def _response_handle_nameplates(self, msg):
|
def _response_handle_nameplates(self, msg):
|
||||||
|
@ -176,6 +179,9 @@ class _InputCode:
|
||||||
# doesn't see the signal, and we must still wait for stdin to make
|
# doesn't see the signal, and we must still wait for stdin to make
|
||||||
# readline finish.
|
# readline finish.
|
||||||
|
|
||||||
|
def _remind_about_tab(self):
|
||||||
|
print(" (note: you can use <Tab> to complete words)", file=self._stderr)
|
||||||
|
|
||||||
class _WelcomeHandler:
|
class _WelcomeHandler:
|
||||||
def __init__(self, url, current_version, signal_error):
|
def __init__(self, url, current_version, signal_error):
|
||||||
self._ws_url = url
|
self._ws_url = url
|
||||||
|
|
Loading…
Reference in New Issue
Block a user