• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python readline.insert_text函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: export_gcal

def export_gcal(v, y, m, d, tid, sid):	
	cmd = []
	cmd.append("gcalcli")
	cmd.append("--calendar")
	readline.set_startup_hook(lambda: readline.insert_text(""))
	t = tabCompleter()
	t.createListCompleter(["calender", "NSC absences", "NSC shared calender"])
	readline.set_completer_delims('\t')
	readline.parse_and_bind("tab: complete")
	readline.set_completer(t.listCompleter)
	calender = raw_input("Name of calender: ").strip()
	cmd.append(calender)
	cmd.append("--title")
	v[y][m][d][tid][sid]["subtask title"]
	cmd.append(v[y][m][d][tid][sid]["subtask title"])
	cmd.append("--where")
	cmd.append("''")
	cmd.append("--when")
	dt = str(m)+ "/" + str(d) + "/" + str(y) + " " + v[y][m][d][tid][sid]["start"]
	cmd.append(dt)
	cmd.append("--duration")
	(h1, m1) = tuple(v[y][m][d][tid][sid]["start"].split(':'))
	(h2, m2) = tuple(v[y][m][d][tid][sid]["end"].split(':'))
	dur = str((int(h2) - int(h1)) * 60 + (int(m2) -int(m1)))
	cmd.append(dur)
	cmd.append("--description")
	cmd.append("''")
	cmd.append("--reminder")
	cmd.append("0")
	cmd.append("add")
	job = subprocess.Popen(cmd)
	job.wait()
	raw_input("Press enter to continue")
开发者ID:cbasu,项目名称:tasks,代码行数:33,代码来源:support.py


示例17: do_history

 def do_history(self, args):
     """
     Prints cloudmonkey history
     """
     if self.pipe_runner("history " + args):
         return
     startIdx = 1
     endIdx = readline.get_current_history_length()
     numLen = len(str(endIdx))
     historyArg = args.split(' ')[0]
     if historyArg.isdigit():
         startIdx = endIdx - long(historyArg)
         if startIdx < 1:
             startIdx = 1
     elif historyArg == "clear" or historyArg == "c":
         readline.clear_history()
         print "CloudMonkey history cleared"
         return
     elif len(historyArg) > 1 and historyArg[0] == "!" and historyArg[1:].isdigit():
         command = readline.get_history_item(long(historyArg[1:]))
         readline.set_startup_hook(lambda: readline.insert_text(command))
         self.hook_count = 1
         return
     for idx in xrange(startIdx, endIdx):
         self.monkeyprint("%s %s" % (str(idx).rjust(numLen),
                                     readline.get_history_item(idx)))
开发者ID:waegemae,项目名称:cloudstack-cloudmonkey,代码行数:26,代码来源:cloudmonkey.py


示例18: get_user_input

def get_user_input(obj, attr, opts, no_prefill=False):
    if attr == 'collection' and not getattr(obj, attr) and obj.project:
        setattr(obj, attr, obj.project.collection)

    if opts:
        optlist = ', '.join(['%s=%s' % (k, v) for k, v in opts.items()])
        prompt = '%s [Options: %s]: ' % (attr, optlist)
    else:
        prompt = '%s: ' % attr
    if no_prefill or not getattr(obj, attr):
        prefill = ''
    else:
        if (hasattr(obj, 'relations') and attr in obj.relations) \
                or (getattr(obj, attr) and hasattr(getattr(obj, attr), 'id')):
            prefill = getattr(obj, attr).id
        else:
            prefill = getattr(obj, attr)
    readline.set_startup_hook(lambda: readline.insert_text(prefill))
    readline.set_completer_delims(' \t\n;')
    readline.parse_and_bind("tab: complete")
    readline.set_completer(complete)
    try:
        return raw_input(prompt)
    finally:
        readline.set_startup_hook()
开发者ID:frost-nzcr4,项目名称:clint,代码行数:25,代码来源:clint.py


示例19: silent_invariant_raw_input

def silent_invariant_raw_input(prompt,comp=None,wipe=False, echo = True,color = Colors.NONE,completion=None):
    prompt = color+prompt+Colors.ENDC
    if not Control.silent:
        readline.set_startup_hook(lambda: readline.insert_text(comp))
    if completion=="Files":
        readline.set_completer_delims(' \t\n;')
        readline.parse_and_bind("tab: complete")
        readline.set_completer(fileCompleter)
    elif not completion is None:
        readline.set_completer_delims(' \t\n;')
        readline.parse_and_bind("tab: complete")
        readline.set_completer(lambda a,b:listCompleter(a,b,completion))
    try:
        if Control.silent:
            prompt = ""
        if echo:
            ret = raw_input(prompt)
        else:
            ret = getpass.getpass(prompt)
            wipe = False
        if wipe:
            l = readline.get_current_history_length()
            if l > 0:
                readline.remove_history_item(l-1)
        return ret
    finally:
        if not Control.silent:
            readline.set_startup_hook()
        if not completion is None:
            readline.parse_and_bind("set disable-completion On")
            readline.set_completer(None)
            #readline.parse_and_bind("tab: \t")
            readline.set_completer_delims("")
开发者ID:bentheiii,项目名称:SecretService,代码行数:33,代码来源:ControlService.py


示例20: read_input

def read_input(prompt, prefill = ''):
    """
    Function to read input from stdin
    
    Args:
        prompt: Prompt for the input
        prefill: A default value for the input
    """
    
    try:
        if not prefill:
            raise Exception
            
        #if readline is present, use to prefill the input
        import readline as c_readline
        value, prefill = prefill, ''  #in this case we are resetting the prefill so as to not return the prefill
        c_readline.set_startup_hook(lambda: c_readline.insert_text(value))
    except ImportError:
        #otherwise modify the prompt to show the prefill
        c_readline = None
        prompt = '%s[%s] ' % (prompt, prefill)
    except:
        c_readline = None

    #Python 2.x vs 3.x
    try:
        c_input = raw_input
    except:
        c_input = input
    
    try:
        #read the input or return any prefill values
        return c_input(prompt) or prefill
    finally:
        c_readline and c_readline.set_startup_hook()  #unbind startup hook
开发者ID:webyog,项目名称:sealion-agent,代码行数:35,代码来源:constructs.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python readline.parse_and_bind函数代码示例发布时间:2022-05-26
下一篇:
Python readline.get_line_buffer函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap