Python readline.set_pre_input_hook() Examples

The following are 8 code examples of readline.set_pre_input_hook(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module readline , or try the search function .
Example #1
Source File: pythonrc.py    From pythonrc with MIT License 5 votes vote down vote up
def toggle_auto_indent(self, _):
        """{TOGGLE_AUTO_INDENT_CMD} - Toggles the auto-indentation behavior
        """
        hook = None if config['AUTO_INDENT'] else self.auto_indent_hook
        msg = '# Auto-Indent has been {}abled\n'.format('en' if hook else 'dis')
        config['AUTO_INDENT'] = bool(hook)

        if hook is None:
            msg += ('# End of blocks will be detected after 3 empty lines\n'
                    '# Re-type {TOGGLE_AUTO_INDENT_CMD} on a line by itself to enable')

        readline.set_pre_input_hook(hook)
        print(grey(msg.format(**config), bold=False))
        return '' 
Example #2
Source File: PupyCmd.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def init_completer(self):
		readline.set_pre_input_hook(self.pre_input_hook)
		readline.set_completer_delims(" \t") 
Example #3
Source File: PupyCmd.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def init_completer(self):
		readline.set_pre_input_hook(self.pre_input_hook)
		readline.set_completer_delims(" \t") 
Example #4
Source File: passhole.py    From passhole with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #5
Source File: sshmenu.py    From sshmenu with MIT License 5 votes vote down vote up
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 
Example #6
Source File: pam.py    From python-pam with MIT License 5 votes vote down vote up
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 
Example #7
Source File: PupyCmd.py    From backdoorme with MIT License 5 votes vote down vote up
def init_completer(self):
		readline.set_pre_input_hook(self.pre_input_hook)
		readline.set_completer_delims(" \t") 
Example #8
Source File: pythonrc.py    From pythonrc with MIT License 4 votes vote down vote up
def init_readline(self):
        """Activates history and tab completion
        """
        # - mainly borrowed from site.enablerlcompleter() from py3.4+

        # Reading the initialization (config) file may not be enough to set a
        # completion key, so we set one first and then read the file.
        readline_doc = getattr(readline, '__doc__', '')
        if readline_doc is not None and 'libedit' in readline_doc:
            readline.parse_and_bind('bind ^I rl_complete')
        else:
            readline.parse_and_bind('tab: complete')

        try:
            readline.read_init_file()
        except OSError:
            # An OSError here could have many causes, but the most likely one
            # is that there's no .inputrc file (or .editrc file in the case of
            # Mac OS X + libedit) in the expected location.  In that case, we
            # want to ignore the exception.
            pass

        if readline.get_current_history_length() == 0:
            # If no history was loaded, default to .python_history.
            # The guard is necessary to avoid doubling history size at
            # each interpreter exit when readline was already configured
            # see: http://bugs.python.org/issue5845#msg198636
            try:
                readline.read_history_file(config['HISTFILE'])
            except IOError:
                pass
            atexit.register(readline.write_history_file,
                            config['HISTFILE'])
        readline.set_history_length(config['HISTSIZE'])

        # - replace default completer
        readline.set_completer(self.improved_rlcompleter())

        # - enable auto-indenting
        if config['AUTO_INDENT']:
            readline.set_pre_input_hook(self.auto_indent_hook)

        # - remove '/' and '~' from delimiters to help with path completion
        completer_delims = readline.get_completer_delims()
        completer_delims = completer_delims.replace('/', '')
        if config.get('COMPLETION_EXPANDS_TILDE'):
            completer_delims = completer_delims.replace('~', '')
        readline.set_completer_delims(completer_delims)