Python readline.get_completer_delims() Examples
The following are 7
code examples of readline.get_completer_delims().
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: cli.py From clonedigger with GNU General Public License v3.0 | 6 votes |
def init_readline(complete_method, histfile=None): """init the readline library if available""" try: import readline readline.parse_and_bind("tab: complete") readline.set_completer(complete_method) string = readline.get_completer_delims().replace(':', '') readline.set_completer_delims(string) if histfile is not None: try: readline.read_history_file(histfile) except IOError: pass import atexit atexit.register(readline.write_history_file, histfile) except: print('readline si not available :-(')
Example #2
Source File: __init__.py From cauldron with MIT License | 6 votes |
def autocomplete(command: str): """...""" # On Linux/OSX the completer delims are retrieved from the readline module, # but the delims are different on Windows. So for testing consistency we # supply the Linux/OSX delims explicitly here in place of: # readline.get_completer_delims() completer_delims = ' \t\n`~!@#$%^&*()-=+[{]}\\|;:\'",<>/?' with patch('readline.get_line_buffer', return_value=command): cs = CauldronShell() line = command.lstrip() splits = re.split('[{}]{{1}}'.format( re.escape(completer_delims)), line ) return cs.completedefault( text=splits[-1], line=line, begin_index=len(line) - len(splits[-1]), end_index=len(line) - 1 )
Example #3
Source File: SharPyShellPrompt.py From SharPyShell with GNU General Public License v3.0 | 5 votes |
def complete(self, text, state): """Return the next possible completion for 'text'. If a command has not been entered, then complete against command list. Otherwise try to call complete_<command> to get list of completions. """ if state == 0: import readline old_delims = readline.get_completer_delims() readline.set_completer_delims(old_delims.replace('#', '')) origline = readline.get_line_buffer() line = origline.lstrip() stripped = len(origline) - len(line) begidx = readline.get_begidx() - stripped endidx = readline.get_endidx() - stripped if begidx > 0: cmd, args, foo = self.parseline(line) if cmd == '': compfunc = self.completedefault else: try: compfunc = getattr(self, 'complete_' + cmd) except AttributeError: compfunc = self.completedefault else: compfunc = self.completenames self.completion_matches = compfunc(text, line, begidx, endidx) try: return self.completion_matches[state] except IndexError: return None
Example #4
Source File: shell.py From kitty with GNU General Public License v3.0 | 5 votes |
def __enter__(self) -> 'Completer': with suppress(Exception): readline.read_history_file(self.history_path) readline.set_completer(self.complete) delims = readline.get_completer_delims() readline.set_completer_delims(delims.replace('-', '')) return self
Example #5
Source File: shell.py From RSqueak with BSD 3-Clause "New" or "Revised" License | 5 votes |
def set_readline(self): if not objectmodel.we_are_translated(): self.old_completer = readline.get_completer() self.old_delims = readline.get_completer_delims() readline.set_completer(completer) readline.set_completer_delims("\t ")
Example #6
Source File: pythonrc.py From pythonrc with MIT License | 4 votes |
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)
Example #7
Source File: gtp_engine.py From goreviewpartner with GNU General Public License v3.0 | 4 votes |
def run_interactive_gtp_session(engine): """Run a GTP engine session on stdin and stdout, using readline. engine -- Gtp_engine_protocol object This enables readline tab-expansion, and command history in ~/.gomill-gtp-history (if readline is available). Returns either when EOF is seen on stdin, or when the engine signals end of session. If stdin isn't a terminal, this is equivalent to run_gtp_session. If a write fails with 'broken pipe', this raises ControllerDisconnected. Note that this will propagate KeyboardInterrupt if the user presses ^C; normally you'll want to handle this to avoid an ugly traceback. """ # readline doesn't do anything if stdin isn't a tty, but it's simplest to # just not import it in that case. try: use_readline = os.isatty(sys.stdin.fileno()) if use_readline: import readline except Exception: use_readline = False if not use_readline: run_gtp_session(engine, sys.stdin, sys.stdout) return def write(s): sys.stdout.write(s) sys.stdout.flush() history_pathname = os.path.expanduser("~/.gomill-gtp-history") readline.parse_and_bind("tab: complete") old_completer = readline.get_completer() old_delims = readline.get_completer_delims() readline.set_completer(make_readline_completer(engine)) readline.set_completer_delims("") try: readline.read_history_file(history_pathname) except EnvironmentError: pass _run_gtp_session(engine, raw_input, write) try: readline.write_history_file(history_pathname) except EnvironmentError: pass readline.set_completer(old_completer) readline.set_completer_delims(old_delims)