當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。