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


Python readline.set_pre_input_hook函数代码示例

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


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

示例1: lookupCb

        def lookupCb(thing):
            if not thing:
                self.stdout.write('No thing found for %s\n' %
                    shortid.encode('utf-8'))
                return

            self.getRootCommand()._stdio.teardown()

            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)

            readline.set_pre_input_hook(pre_input_hook)

            line = raw_input("GTD edit> ").decode('utf-8')
            # Remove edited line from history:
            #   oddly, get_history_item is 1-based,
            #   but remove_history_item is 0-based
            readline.remove_history_item(readline.get_current_history_length() - 1)
            self.getRootCommand()._stdio.setup()
            try:
                d = parse.parse(line)
            except ValueError, e:
                self.stderr.write('Could not parse line: %s\n' %
                    log.getExceptionMessage(e))
                return 3
开发者ID:thomasvs,项目名称:mushin,代码行数:30,代码来源:main.py

示例2: cmdloop

    def cmdloop(self, intro=None):
        self.old_completer = readline.get_completer()
        self.old_completer_delims = readline.get_completer_delims()
        readline.set_completer(self.complete)
        readline.parse_and_bind(self.completekey+": complete")
        readline.parse_and_bind("set bell-style none")
        readline.parse_and_bind("set show-all-if-ambiguous")
        readline.parse_and_bind("set completion-query-items -1")

        # If press help key, add the character and accept the line
        readline.parse_and_bind('"?": "\C-q?\C-j"')
        # Register a function for execute before read user
        # input. We can use it for insert text at command line
        readline.set_pre_input_hook(self.pre_input_hook)
        readline.set_completer_delims(' \t\n')

        try:
            stop = None
            while not stop:
                try:
                    line = raw_input(self.prompt)
                except EOFError:
                    line = 'EOF'

                stop = self.onecmd(line)
                stop = self.postcmd(stop, line)
        finally:
            readline.set_completer(self.old_completer)
            readline.set_completer_delims(self.old_completer_delims)
开发者ID:aleasoluciones,项目名称:boscli-oss-core,代码行数:29,代码来源:boscli.py

示例3: update

def update(phenotype):
    """Update the metadata for a given phenotype.

    :param phenotype: The phenotype for which the metadata will be updated.
    :type phenotype: str

    This will display a JSON string that the user can edit to update the
    database.

    Note that it is not possible to rename phenotypes using this function as
    it is used as the database key to access the data.

    TODO. Make this better for the new client/server architecture.

    """
    data, meta = _get_data_meta(phenotype)
    meta.pop("name")

    def hook():
        readline.insert_text(json.dumps(meta))
        readline.redisplay()

    readline.set_pre_input_hook(hook)
    new_data = input("(json)>>> ")
    readline.set_pre_input_hook()

    new_data = json.loads(new_data)
    meta.update(new_data)

    # Update in db.
    _get_manager().update_phenotype(phenotype, **meta)

    return {"success": True, "message": "Phenotype updated in database."}
开发者ID:legaultmarc,项目名称:cohort-manager,代码行数:33,代码来源:cohort_repl.py

示例4: main

def main():
    """
    interactive move of a file. Instead of calling mv with two
    arguments, source and destination, call imv with just the source,
    and edit the destination in a GNU readline buffer.

    Once the line editor is started, it is possible to cancel with
    Ctrl-C without harming the filesystem.
    """
    if (sys.argv[1] == '-h' or sys.argv[1] == '--help'):
        help(main)
        sys.exit(0)
    else:
        for src in sys.argv[1:]:
            if os.path.exists(src):
                def pre_input_hook():
                    readline.insert_text(src)
                    readline.redisplay()
                readline.set_pre_input_hook(pre_input_hook)
                try:
                    dst = raw_input('imv$ ')
                except KeyboardInterrupt:   # die silently if user hits Ctrl-C
                    pass
                else:
                    shutil.move(src, dst)
            else:
                print 'ERROR: %s: no such file or directory' % src
                sys.exit(-1)
开发者ID:bhramoss,项目名称:code,代码行数:28,代码来源:recipe-523005.py

示例5: operate_and_get_next

 def operate_and_get_next(count, char):
     current_line = readline.where_history()
     offset = readline.get_current_history_length() - current_line
     # Accept the current line and set the hook to rewind history
     result = readline.accept_line(1, char)
     readline.set_pre_input_hook(pre_input_hook_factory(offset, char))
     return result
开发者ID:0xf4,项目名称:pythonrc,代码行数:7,代码来源:pythonrc.py

示例6: fix_entry

def fix_entry(entry):
    """
    Allow user to change name of an entry. It is called 'fix' because the only
    plausible reason to do so in this context is to correct a typo or other
    error.

    Returns True if the fix was successful, False if user chose an invalid new
    name (i.e., one that already exists).
    """

    print ""
    readline.set_pre_input_hook(readline_prefiller(entry))
    new_entry = raw_input(tc.RED+"Change to: "+tc.YELLOW)
    print tc.ENDC
    readline.set_pre_input_hook()

    if db.entries.get_eid(new_entry):
        print "That entry already exists! Try a different one, or use coalesce."
        print "~ Press any key to continue ~",
        termdisplay.getch()
        return False
    else:
        db.entries.correct_entry(entry, new_entry)
        screen(new_entry)
        return True
开发者ID:sobjornstad,项目名称:rppas,代码行数:25,代码来源:editing.py

示例7: postcmd

 def postcmd(self, stop, line):
     """Called just before execution of line. For readline, this handles the
     automatic indentation of code blocks.
     """
     try:
         import readline
     except ImportError:
         return stop
     if self.need_more_lines:
         if len(line.strip()) == 0:
             readline.set_pre_input_hook(None)
             self._current_indent = ''
         elif line.rstrip()[-1] == ':':
             ind = line[:len(line) - len(line.lstrip())]
             ind += builtins.__xonsh_env__.get('INDENT')
             readline.set_pre_input_hook(_insert_text_func(ind, readline))
             self._current_indent = ind
         elif line.split(maxsplit=1)[0] in DEDENT_TOKENS:
             env = builtins.__xonsh_env__
             ind = self._current_indent[:-len(env.get('INDENT'))]
             readline.set_pre_input_hook(_insert_text_func(ind, readline))
             self._current_indent = ind
         else:
             ind = line[:len(line) - len(line.lstrip())]
             if ind != self._current_indent:
                 insert_func = _insert_text_func(ind, readline)
                 readline.set_pre_input_hook(insert_func)
                 self._current_indent = ind
     else:
         readline.set_pre_input_hook(None)
     return stop
开发者ID:PaulReiber,项目名称:xonsh,代码行数:31,代码来源:readline_shell.py

示例8: edit

        def edit(self, entry=None):
            """Edits the specified `entry`. If `entry` is None, a new entry
            is created. This method supports the readline module for editing

            :returns: The entry with the new values as entered by the
            user"""
            if entry is None:
                entry = Entry()
                print _('Creating a new entry...\n'
                        'Please fill the following fields. To leave a '
                        'field empty, just press ENTER without entering '
                        'something.')    
            else:
                self.edited_entry = entry
                print _('Editing entry %s\n'
                        'Please fill the following fields...') % repr(entry)
                # set input hook to show the current value
                readline.set_pre_input_hook(self._input_hook)
            print
            for field in self.fields:
                self.current_field = field[0]
                resp = raw_input(field[1]).strip()
                while not self.verify_field(field[0], resp):
                    print field[2]
                    resp = raw_input(field[1]).strip()
                setattr(entry, field[0], resp)
            # remove input hook
            readline.set_pre_input_hook(None)
            return entry
开发者ID:BackupTheBerlios,项目名称:tel-svn,代码行数:29,代码来源:tel.py

示例9: 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

示例10: input_prefill

def input_prefill(prompt, text):
  """Prefills user input with 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:btcrooks,项目名称:MDdb,代码行数:9,代码来源:input_prefill.py

示例11: raw_input_with_default

def raw_input_with_default(prompt, default):
    def pre_input_hook():
        readline.insert_text(default)
        readline.redisplay()
    readline.set_pre_input_hook(pre_input_hook)
    try:
        return raw_input(prompt)
    finally:
        readline.set_pre_input_hook(None)
开发者ID:fphammerle,项目名称:ioex,代码行数:9,代码来源:__init__.py

示例12: prepopulate

def prepopulate(default):
    """Prepopluates the input with the default text for the user to edit"""
    def hook():
        readline.insert_text(str(default))
        readline.redisplay()
    if default is not None:
        readline.set_pre_input_hook(hook)
    yield
    readline.set_pre_input_hook(None)
开发者ID:ashwinaj,项目名称:paasta,代码行数:9,代码来源:prompt.py

示例13: input_with_prefill

def input_with_prefill(prompt, text):
	if not interactive:
		return 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:anlutro,项目名称:dotfiles,代码行数:11,代码来源:init-project.py

示例14: preinput

    def preinput(self, label='', preinput=''):
        """ Pre-insert a text on a input function """
        def hook():
            readline.insert_text(preinput)
            readline.redisplay()

        readline.set_pre_input_hook(hook)
        print(label, end='')
        value = input(' ')
        readline.set_pre_input_hook()
        return value
开发者ID:lowks,项目名称:linkmanager,代码行数:11,代码来源:tty.py

示例15: my_input

def my_input(prompt, default=None, completer=None):
    if default is not None:
        def pre_input_hook():
            readline.insert_text(default)
            readline.redisplay()
        readline.set_pre_input_hook(pre_input_hook)
    # completer
    if completer:
        readline.set_completer(completer)
        readline.parse_and_bind('tab: complete')
    return input(prompt)
开发者ID:liweitianux,项目名称:dotfiles,代码行数:11,代码来源:mutt-xlabel.py


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