当前位置: 首页>>代码示例>>Python>>正文


Python readline.redisplay方法代码示例

本文整理汇总了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 
开发者ID:luckydonald,项目名称:pytgbot,代码行数:25,代码来源:cli.py

示例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)) 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:21,代码来源:PupyCmd.py

示例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 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:32,代码来源:rlcompleter.py

示例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() 
开发者ID:lonetwin,项目名称:pythonrc,代码行数:8,代码来源:pythonrc.py

示例5: pre_input_hook

# 需要导入模块: import readline [as 别名]
# 或者: from readline import redisplay [as 别名]
def pre_input_hook(self):
		#readline.redisplay()
		pass 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:5,代码来源:PupyCmd.py

示例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 
开发者ID:Evidlo,项目名称:passhole,代码行数:10,代码来源:passhole.py

示例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 
开发者ID:mmeyer724,项目名称:sshmenu,代码行数:11,代码来源:sshmenu.py

示例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. 
开发者ID:nccgroup,项目名称:thetick,代码行数:34,代码来源:tick.py

示例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 
开发者ID:FirefighterBlu3,项目名称:python-pam,代码行数:15,代码来源:pam.py

示例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)) 
开发者ID:entynetproject,项目名称:mouse,代码行数:62,代码来源:session.py


注:本文中的readline.redisplay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。