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


Python readline.insert_text函数代码示例

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


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

示例1: _readline_getc

    def _readline_getc(self):
        do_comp = self.callbacks["get_var"]("input_do_completions")

        # Don't flush, because readline loses keys.
        r = self.get_key(False)

        if r == curses.KEY_BACKSPACE:
            r = ord("\b")

        if chr(r) == '\t' and do_comp:
            self.input_box.rotate_completions()
            return

        # Accept current completion
        if chr(r) in " \b\n" and do_comp:
            comp = self.input_box.break_completion()
            if comp:
                log.debug("inserting: %s" % comp)
                readline.insert_text(comp)

        # Discard current completion
        else:
            self.input_box.break_completion()

        log.debug("KEY: %s" % r)
        return r
开发者ID:dkasak,项目名称:canto-curses,代码行数:26,代码来源:screen.py

示例2: pre_input_hook

            def pre_input_hook():
                readline.insert_text(display.display(
                    thing, shortid=False, colored=False))
                readline.redisplay()

                # Unset the hook again
                readline.set_pre_input_hook(None)
开发者ID:thomasvs,项目名称:mushin,代码行数:7,代码来源:main.py

示例3: insert_text

 def insert_text ( self, line ):
     if util.isPlatformWindows ():
         import pyreadline
         Readline ().insert_text ( line )
     else:
         import readline
         readline.insert_text ( line )
开发者ID:Juniper,项目名称:OpenClos,代码行数:7,代码来源:cli.py

示例4: rl_autoindent

def rl_autoindent():
    """Auto-indent upon typing a new line according to the contents of the
    previous line.  This function will be used as Readline's
    pre-input-hook.

    """
    hist_len = readline.get_current_history_length()
    last_input = readline.get_history_item(hist_len)
    try:
        last_indent_index = last_input.rindex("    ")
    except:
        last_indent = 0
    else:
        last_indent = int(last_indent_index / 4) + 1
    if len(last_input.strip()) > 1:
        if last_input.count("(") > last_input.count(")"):
            indent = ''.join(["    " for n in range(last_indent + 2)])
        elif last_input.count(")") > last_input.count("("):
            indent = ''.join(["    " for n in range(last_indent - 1)])
        elif last_input.count("[") > last_input.count("]"):
            indent = ''.join(["    " for n in range(last_indent + 2)])
        elif last_input.count("]") > last_input.count("["):
            indent = ''.join(["    " for n in range(last_indent - 1)])
        elif last_input.count("{") > last_input.count("}"):
            indent = ''.join(["    " for n in range(last_indent + 2)])
        elif last_input.count("}") > last_input.count("{"):
            indent = ''.join(["    " for n in range(last_indent - 1)])
        elif last_input[-1] == ":":
            indent = ''.join(["    " for n in range(last_indent + 1)])
        else:
            indent = ''.join(["    " for n in range(last_indent)])
    readline.insert_text(indent)
开发者ID:bbinet,项目名称:dotfiles,代码行数:32,代码来源:pystartup.py

示例5: defaulter

 def defaulter():
     """define default behavior startup"""
     if _readline_available:
         readline.insert_text(default)
     readline.set_startup_hook(defaulter)
     readline.get_completer()
     readline.set_completer(completer)
开发者ID:gadeleon,项目名称:pwman3,代码行数:7,代码来源:tools.py

示例6: printf

 def printf(self, string):
     #readline.set_startup_hook(lambda: readline.insert_text("{0}".format(str)) or readline.redisplay())
     self.stdout.write(str("\n{0}\n".format(string))+"\n")
     self.stdout.flush()
     #readline.parse_and_bind('\C-M')
     readline.insert_text("oi\n")
     #readline.parse_and_bind('\\n')
     readline.redisplay()
开发者ID:iacchus,项目名称:vosh,代码行数:8,代码来源:Shell.py

示例7: pre_input_hook

 def pre_input_hook(self):
     """If a line buffer has been filled then inject it into the readline
     buffer for the user to edit."""
     if self.line_buffer:
         readline.insert_text(
             self.line_buffer.decode(ex_config.FILE_ENCODING).rstrip('\n'))
         readline.redisplay()
         self.line_buffer = None
开发者ID:DerekMarshall,项目名称:py-ex,代码行数:8,代码来源:ex.py

示例8: _fred_completer

def _fred_completer(text, state):
    """Custom completer function called when the user presses TAB."""
    s_current_cmd = readline.get_line_buffer()
    # Write partial command+\t to debuggerso it can do the completion.
    result = get_child_response(s_current_cmd + '\t')
    # Erase what text we already have:
    result = result.replace(s_current_cmd, "")
    readline.insert_text(result)
开发者ID:bbarker,项目名称:fred,代码行数:8,代码来源:fredio.py

示例9: getUserInWithDef

def getUserInWithDef(msg, default):
    readline.set_startup_hook(lambda: readline.insert_text(default))
    var = raw_input(colors.BOLDON + "%s: " % (msg) + colors.BOLDOFF)
    readline.set_startup_hook(lambda: readline.insert_text(''))
    if var == "":
        print("No input given, try again.")
        return getUserIn(msg)
    return var
开发者ID:chriswhitehat,项目名称:cirta,代码行数:8,代码来源:util.py

示例10: startup_hook

def startup_hook():
    """startup_hook() -- internal readline callback. Do not call.
    """
    if (Readline.interruption != None):
        readline.insert_text(Readline.interruption[0])
        readline.set_point(Readline.interruption[1])
        readline.set_mark(Readline.interruption[2])
        Readline.interruption = None
开发者ID:jmacdotorg,项目名称:volity,代码行数:8,代码来源:readlineagent.py

示例11: complete

    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,代码行数:58,代码来源:command.py

示例12: complete

 def complete(self, text, state):
     if not text:
         readline.insert_text('    ')
         if TabCompleter.uses_editline:
             # It won't move the cursor for us, apparently
             sys.stdout.write('\x1b[4C')
         readline.redisplay()
         sys.stdout.flush()
         return None
     else:
         return rlcompleter.Completer.complete(self, text, state)
开发者ID:tipabu,项目名称:dot-files,代码行数:11,代码来源:startup.py

示例13: autocompleter

    def autocompleter(self, txt, state):
        chopped = []
        try:
            r = []
            self._line = readline.get_line_buffer()
            self.cursorix(readline.get_endidx())
            last = self.lastword()
            if self.atendofcmd() or self.cmd() == "help":
                for c in command.allcmds():
                    if c.startswith(txt):
                        r.append(c + " ")
            else:
                # print "<%s, %s>" % (txt, state)
                curacct = self.currentaccount()

                if not last:
                    acct = curacct
                else:
                    if last.startswith("/"):
                        acct = accounts.getroot()
                        last = last.lstrip("/")
                    else:
                        acct = curacct

                    chopped = last.rsplit("/", 1)
                    tmpacct = acct.getsubaccount(chopped[0])

                    if tmpacct:
                        acct = tmpacct

                    if len(chopped) > 1:
                        txt = chopped[1]

                for a in acct.accounts():
                    if txt == "" or a.name().startswith(txt):
                        r.append(a.name() + "/")
                if len(r) == 1:
                    readline.insert_text("/")
            try:
                return r[state]
            except IndexError:
                return None

        except Exception, ex:
            print "%s:\n%s\n%s" % ("autocompleter exception", type(ex), str(ex))
            print "txt: %s; state: %s" % (txt, state)
            print "chopped: " + str(chopped)
            print "last: " + last
开发者ID:jhogan,项目名称:macc,代码行数:48,代码来源:macc.py

示例14: rlinput

def rlinput(prompt, prefill=''):
    """kind of like ras_input but with readline support and pre-filled answer"""
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    try:
        return raw_input(prompt)
    finally:
        readline.set_startup_hook()
开发者ID:Astroua,项目名称:CARTAvis,代码行数:7,代码来源:buildRelease.py

示例15: _rlinput

 def _rlinput(self, prompt, prefill):
     readline.set_startup_hook(lambda: readline.insert_text(prefill))
     try:
         return raw_input(prompt)
     finally:
         readline.set_startup_hook()
     return prefill
开发者ID:rgs1,项目名称:notes,代码行数:7,代码来源:notes_manager.py


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