Python readline 模块,redisplay() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用readline.redisplay()

项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
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
项目:pymotw3    作者:reingart    | 项目源码 | 文件源码
def pre_input_hook():
    readline.insert_text(' from pre_input_hook')
    readline.redisplay()
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def pre_input_hook(self):
        #readline.redisplay()
        pass
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def display(self, msg, modifier=None):
        if not type(msg) is unicode:
            # force output unicode string to output
            # Python will hopefully handle output printing
            msg=obj2utf8(msg)
        if msg:
            if modifier=="error":
                self.stdout.write(PupyCmd.format_error(msg))
            elif modifier=="success":
                self.stdout.write(PupyCmd.format_success(msg))
            elif modifier=="info":
                self.stdout.write(PupyCmd.format_info(msg))
            elif modifier=="srvinfo":
                buf_bkp=readline.get_line_buffer()
                #nG move cursor to column n
                #nE move cursor ro the beginning of n lines down
                #nK Erases part of the line. If n is zero (or missing), clear from cursor to the end of the line. If n is one, clear from cursor to beginning of the line. If n is two, clear entire line. Cursor position does not change. 
                self.stdout.write("\x1b[0G"+PupyCmd.format_srvinfo(msg)+"\x1b[0E")
                self.stdout.write("\x1b[2K")#clear line
                self.stdout.write(self.raw_prompt+buf_bkp)#"\x1b[2K")
                try:
                    readline.redisplay()
                except Exception:
                    pass
            elif modifier=="warning":
                self.stdout.write(PupyCmd.format_warning(msg))
            else:
                self.stdout.write(PupyCmd.format_log(msg))
项目:ivaochdoc    作者:ivaoch    | 项目源码 | 文件源码
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
项目:pythonrc    作者:lonetwin    | 项目源码 | 文件源码
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()
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def pre_input_hook(self):
        #readline.redisplay()
        pass
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def display(self, msg, modifier=None):
        if not type(msg) is unicode:
            # force output unicode string to output
            # Python will hopefully handle output printing
            msg=obj2utf8(msg)
        if msg:
            if modifier=="error":
                self.stdout.write(PupyCmd.format_error(msg))
            elif modifier=="success":
                self.stdout.write(PupyCmd.format_success(msg))
            elif modifier=="info":
                self.stdout.write(PupyCmd.format_info(msg))
            elif modifier=="srvinfo":
                buf_bkp=readline.get_line_buffer()
                #nG move cursor to column n
                #nE move cursor ro the beginning of n lines down
                #nK Erases part of the line. If n is zero (or missing), clear from cursor to the end of the line. If n is one, clear from cursor to beginning of the line. If n is two, clear entire line. Cursor position does not change. 
                self.stdout.write("\x1b[0G"+PupyCmd.format_srvinfo(msg)+"\x1b[0E")
                self.stdout.write("\x1b[2K")#clear line
                self.stdout.write(self.raw_prompt+buf_bkp)#"\x1b[2K")
                try:
                    readline.redisplay()
                except Exception:
                    pass
            elif modifier=="warning":
                self.stdout.write(PupyCmd.format_warning(msg))
            else:
                self.stdout.write(PupyCmd.format_log(msg))
项目:news-for-good    作者:thecodinghub    | 项目源码 | 文件源码
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
项目:Tencent_Cartoon_Download    作者:Fretice    | 项目源码 | 文件源码
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
项目:fieldsight-kobocat    作者:awemulya    | 项目源码 | 文件源码
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
项目:HOTBot    作者:adammhaile    | 项目源码 | 文件源码
def default_input(prompt, default=None):
    # https://chistera.yi.org/~dato/blog/entries/2008/02/14/python_raw_input_with_an_editable_default_value_using_readline.html
    if not default:
        default = ""

    def pre_input_hook():
        readline.insert_text(default)
        readline.redisplay()

    prompt += ": "
    readline.set_pre_input_hook(pre_input_hook)
    try:
        return raw_input(prompt)
    finally:
        readline.set_pre_input_hook(None)
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
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
项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
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
项目:gitsome    作者:donnemartin    | 项目源码 | 文件源码
def _insert_text_func(s, readline):
    """Creates a function to insert text via readline."""
    def inserter():
        readline.insert_text(s)
        readline.redisplay()
    return inserter
项目:blog_flask    作者:momantai    | 项目源码 | 文件源码
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
项目:MyFriend-Rob    作者:lcheniv    | 项目源码 | 文件源码
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