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


Python readline.insert_text方法代码示例

本文整理汇总了Python中readline.insert_text方法的典型用法代码示例。如果您正苦于以下问题:Python readline.insert_text方法的具体用法?Python readline.insert_text怎么用?Python readline.insert_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在readline的用法示例。


在下文中一共展示了readline.insert_text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ask

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [as 别名]
def ask(string, valid_values, default=-1, case_sensitive=False):
    """ Asks for a keyborad answer """

    v = None
    if not case_sensitive:
        valid_values = [value.lower() for value in valid_values]
    while v not in valid_values:
        readline.set_startup_hook(lambda: readline.insert_text(default))
        try:
            v = raw_input("%s [%s] " % (string, ', '.join(valid_values))).strip()
            if v == '' and default>=0:
                v = valid_values[default]
            if not case_sensitive:
                v = v.lower()
        finally:
            readline.set_startup_hook()
    return v 
开发者ID:eggnogdb,项目名称:eggnog-mapper,代码行数:19,代码来源:release.py

示例2: edit_option

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [as 别名]
def edit_option(self, idx):
        # Go up
        sys.stdout.write('\033[1A' * (len(self.options) - idx))
        # Go left to the beginning of the line
        sys.stdout.write('\033[1D' * (max([len(x) for x in self.options]) + 3))
        sys.stdout.flush()
        prev_value = self.options[idx]
        readline.set_startup_hook(lambda: readline.insert_text(prev_value))
        try:
            new_value = input('E: ')
        finally:
            readline.set_startup_hook()

        self.options[idx] = new_value
        sys.stdout.write('\033[1A' * (idx + 1))
        sys.stdout.write('\033[1D' * (max([len(x) for x in self.options]) + 3))
        sys.stdout.flush()
        self.print_options()
        return prev_value, new_value 
开发者ID:antlarr,项目名称:bard,代码行数:21,代码来源:terminalkeyboard.py

示例3: rlinput

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [as 别名]
def rlinput(prompt, prefill = ''):
   readline.set_startup_hook(lambda: readline.insert_text(prefill))
   try:
      return input(prompt)
   finally:
      readline.set_startup_hook() 
开发者ID:xypnox,项目名称:todxpy,代码行数:8,代码来源:parse_functions.py

示例4: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [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

示例5: auto_indent_hook

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [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

示例6: user_input

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [as 别名]
def user_input(msg, initial=''):
    # Function to capture raw_input w/ key buffer flush
    tcflush(sys.stdin, TCIOFLUSH)
    readline.set_startup_hook(lambda: readline.insert_text(initial))
    keyin = raw_input(msg)
    return keyin 
开发者ID:gluster,项目名称:gluster-one,代码行数:8,代码来源:g1modules.py

示例7: editable_input

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [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

示例8: rlinput

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [as 别名]
def rlinput(prompt, prefill=''):
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return input(prompt)
    finally:
        readline.set_startup_hook() 
开发者ID:IBM,项目名称:power-up,代码行数:8,代码来源:switch_cfg.py

示例9: rlinput

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [as 别名]
def rlinput(prompt, prefill=''):
    log = logger.getlogger()
    log.debug(f"prompt='{repr(prompt)}' prefill='{prefill}'")
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        user_input = input(prompt)
        log.debug(f"user_input='{user_input}'")
        return user_input
    finally:
        readline.set_startup_hook() 
开发者ID:IBM,项目名称:power-up,代码行数:12,代码来源:utilities.py

示例10: input_prefill

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [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

示例11: rlinput

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [as 别名]
def rlinput(prompt, prefill=''):
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return raw_input(prompt)
    finally:
        readline.set_startup_hook() 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:8,代码来源:smgr_add.py

示例12: input_with_prefill

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [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

示例13: getInput

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [as 别名]
def getInput( self, prompt, prefill='' ):

		readline.set_startup_hook(lambda: readline.insert_text('\n' + prefill))
		try:
			return input(prompt).replace('\n','')
		finally:
			readline.set_startup_hook() 
开发者ID:mholgatem,项目名称:GPIOnext,代码行数:9,代码来源:config_manager.py

示例14: complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [as 别名]
def complete(self, line, buf, state, run=False, full_line=None):
        logger.debug('Walked to: %s' % self.name)
        if line and self.dynamic_args and len(line) > 1:
            logger.debug("Dynamic arg '%s' found" % line[0])
            has_arg_completed = True
            # Dynamic arg already filled, jump to next word
            next_command = line[1]
            line.pop(0)
        elif line:
            next_command = line[0]
            has_arg_completed = False

            candidates = self.get_candidates(next_command)
            if candidates and len(candidates) > 1 and buf:
                logger.debug("More than one candidate, not walking in %s" % buf)
                return self._next_command(state, buf)
            elif candidates and next_command in candidates:
                logger.debug("Found %s in childs, walking." % next_command)
                cmd = candidates.pop(next_command)
                return cmd.complete(line[1:], buf, state, run, full_line)
            else:
                logger.debug('Not walking because %s was not found in childs' % next_command)
                if has_arg_completed:
                    return self._next_command(state, next_command)

        logger.debug('Line=>%s, Buf=>%s, state=>%s' % (line, buf, state))

        if run:
            logger.debug('Executing %s' % self.name)
            return self.run(full_line.rstrip())

        logger.debug('Starting arg complete')

        # Checking if user already typed a valid arg without space at end
        if self.dynamic_args:
            if len(line) and buf and line[0] in self.args():
                readline.insert_text(" ")
                logger.debug("Inserted blank space")
            elif len(line) and not buf and line[0] not in self.args():
                logger.debug("Found an unknown arg, suggesting next command.")
                return self._next_command(state, buf)

        if buf == self.name:
            readline.insert_text(" ")
            logger.debug("Inserted blank space")

        if not self.dynamic_args:
            return self._next_command(state, buf)

        if self.dynamic_args:
            if (buf.strip() in self.args()):
                return self._next_command(state, buf)
            elif line and line[0] in self.args():
                return self._next_command(state, buf)
            else:
                return self._dynamic_args(state, buf)
        else:
            return self._next_command(state, buf) 
开发者ID:italorossi,项目名称:ishell,代码行数:60,代码来源:command.py

示例15: tab_complete

# 需要导入模块: import readline [as 别名]
# 或者: from readline import insert_text [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.insert_text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。