本文整理匯總了Python中readline.redisplay方法的典型用法代碼示例。如果您正苦於以下問題:Python readline.redisplay方法的具體用法?Python readline.redisplay怎麽用?Python readline.redisplay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類readline
的用法示例。
在下文中一共展示了readline.redisplay方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: print
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def print(self, text):
current_input = readline.get_line_buffer()
delete_chars = len(self.query) + len(current_input)
# remove the input:
sys.stdout.flush()
for i in range(delete_chars):
sys.stdout.write("\b \b")
# end for
sys.stdout.write("\033[K")
sys.stdout.flush()
# actual output
sys.stdout.write(str(text))
sys.stdout.write("\n")
sys.stdout.flush()
# load back the input
sys.stdout.write(self.query)
sys.stdout.flush()
sys.stdout.write(current_input)
sys.stdout.flush()
readline.redisplay()
# end def
示例2: display
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def display(self, msg, modifier=None):
if not type(msg) is unicode:
# force output unicode string to output
# Python will hopefully handle output printing
msg=str(msg).decode('utf8')
if msg:
if modifier=="error":
self.stdout.write(PupyCmd.format_error(msg))
elif modifier=="success":
self.stdout.write(PupyCmd.format_success(msg))
elif modifier=="info":
self.stdout.write(PupyCmd.format_info(msg))
elif modifier=="srvinfo":
self.stdout.write(PupyCmd.format_srvinfo(msg))
#readline.redisplay()
elif modifier=="warning":
self.stdout.write(PupyCmd.format_warning(msg))
else:
self.stdout.write(PupyCmd.format_log(msg))
示例3: complete
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def complete(self, text, state):
"""Return the next possible completion for 'text'.
This is called successively with state == 0, 1, 2, ... until it
returns None. The completion should begin with 'text'.
"""
if self.use_main_ns:
self.namespace = __main__.__dict__
if not text.strip():
if state == 0:
if _readline_available:
readline.insert_text('\t')
readline.redisplay()
return ''
else:
return '\t'
else:
return None
if state == 0:
if "." in text:
self.matches = self.attr_matches(text)
else:
self.matches = self.global_matches(text)
try:
return self.matches[state]
except IndexError:
return None
示例4: auto_indent_hook
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def auto_indent_hook(self):
"""Hook called by readline between printing the prompt and
starting to read input.
"""
readline.insert_text(self._indent)
readline.redisplay()
示例5: pre_input_hook
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def pre_input_hook(self):
#readline.redisplay()
pass
示例6: editable_input
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def editable_input(prompt, prefill=None):
def hook():
readline.insert_text(prefill)
readline.redisplay()
readline.set_pre_input_hook(hook)
result = input(green(prompt + ': '))
readline.set_pre_input_hook()
return result
示例7: input_prefill
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def input_prefill(prompt, text):
def hook():
readline.insert_text(text)
readline.redisplay()
readline.set_pre_input_hook(hook)
result = input(prompt)
readline.set_pre_input_hook()
return result
示例8: notify_new_bot
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def notify_new_bot(self, listener, bot):
# Notifications for reconnecting bots are skipped because they're
# not very useful except for debugging.
if bot.uuid not in self.known_bots:
# Prepare the notification text.
index = listener.bots.keys().index(bot.uuid)
text = "Bot %d [%s] connected from %s" % (index, bot.uuid, bot.from_addr[0])
text = Fore.BLUE + Style.BRIGHT + text + Style.RESET_ALL
# If the main thread is blocked waiting at the prompt,
# do some ANSI escape codes magic to insert the notification text on screen.
# Note that we cannot use this trick if --no-color was specified.
# (I mean, we could, but what if the reason the colors were turned off
# was that the C&C was not being run in a console with a proper tty?)
if self.inside_prompt and ANSI_ENABLED:
buf_bkp = readline.get_line_buffer()
sys.stdout.write("\033[s\033[0G\033[2K" + text + "\n")
sys.stdout.write(self.prompt.replace("\x01", "").replace("\x02", "") + buf_bkp + "\033[u\033[1B")
readline.redisplay()
# If we are not blocked at the prompt, better not write now!
# We would be messing up the output of some command.
# We'll queue the notification instead to be shown later.
else:
self.notifications.append(text)
# Remember we've seen this bot so we don't notify again.
self.known_bots.add(bot.uuid)
# Hook the precmd event to know when we're out of the command prompt.
示例9: input_with_prefill
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def input_with_prefill(prompt, text):
def hook():
readline.insert_text(text)
readline.redisplay()
readline.set_pre_input_hook(hook)
if sys.version_info >= (3,):
result = input(prompt)
else:
result = raw_input(prompt)
readline.set_pre_input_hook()
return result
示例10: tab_complete
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import redisplay [as 別名]
def tab_complete(self, text, state):
try:
is_double_tab = False
current_text = readline.get_line_buffer()
if self.last_tab and self.last_tab == current_text:
is_double_tab = True
self.last_tab = current_text
# if no input do nothing
if not current_text:
return
# get last input
split_input = current_text.split()[-1]
search_path = os.path.split(split_input)[0]
search_text = os.path.split(split_input)[1]
data = self.send_command({"cmd":"tab_complete","args":search_path if search_path else "."})
results = json.loads(data)
matched_keys = []
if results:
keys = results.keys()
keys.sort()
# append / if it is a directory
for k in keys:
# continue if no match
if k.startswith(search_text):
matched_keys.append(k)
# edge cases
if not matched_keys:
# don't do anything if we have no matches
return
elif len(matched_keys) == 1:
# if there is only 1 match and that match is a directory, append a '/'
readline.insert_text(matched_keys[0][len(search_text):])
if matched_keys[0] in results:
if results[matched_keys[0]] == 4 or results[matched_keys[0]] == 10:
readline.insert_text("/")
readline.redisplay()
return
elif not is_double_tab:
# lcp of multiple matched
find = h.find_longest_common_prefix(matched_keys)
readline.insert_text(find[len(search_text):])
readline.redisplay()
return
print("")
for k in matched_keys:
if results[k] == 4:
print(h.COLOR_INFO + k + h.ENDC)
elif results[k] == 10:
print(h.COLOR_INFO + k + h.ENDC)
else:
print(k)
# back to where we are
sys.stdout.write(self.get_handle() + current_text)
except Exception as e:
print("\n error - " + str(e))