本文整理汇总了Python中gnureadline.get_line_buffer方法的典型用法代码示例。如果您正苦于以下问题:Python gnureadline.get_line_buffer方法的具体用法?Python gnureadline.get_line_buffer怎么用?Python gnureadline.get_line_buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnureadline
的用法示例。
在下文中一共展示了gnureadline.get_line_buffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: complete
# 需要导入模块: import gnureadline [as 别名]
# 或者: from gnureadline import get_line_buffer [as 别名]
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:
original_line = readline.get_line_buffer()
line = original_line.lstrip()
stripped = len(original_line) - len(line)
start_index = readline.get_begidx() - stripped
end_index = readline.get_endidx() - stripped
if start_index > 0:
cmd, args = self.parse_line(line)
if cmd == '':
complete_function = self.default_completer
else:
try:
complete_function = getattr(self, 'complete_' + cmd)
except AttributeError:
complete_function = self.default_completer
else:
complete_function = self.raw_command_completer
self.completion_matches = complete_function(text, line, start_index, end_index)
try:
return self.completion_matches[state]
except IndexError:
return None
示例2: complete
# 需要导入模块: import gnureadline [as 别名]
# 或者: from gnureadline import get_line_buffer [as 别名]
def complete(self, text, state):
"""Return the next possible completion for 'text'."""
if state == 0:
origline = readline.get_line_buffer()
begidx = readline.get_begidx()
endidx = readline.get_endidx()
if begidx > 0:
cmd, args, foo = self.parseline(origline)
if cmd == '':
compfunc = self.completedefault
else:
try:
compfunc = getattr(self, 'complete_' + cmd.lower())
except AttributeError:
try:
compfunc = self.ctx.lookup_compfunction(cmd)
except AttributeError:
compfunc = self.completedefault
else:
compfunc = self.completenames
arglist = [item.strip() for item in origline.strip().split()]
comp_state = self.get_compstate(text, arglist)
self.completion_matches = compfunc(text, origline, arglist, comp_state, begidx, endidx)
try:
return self.completion_matches[state]
except:
return None
#def get_names(self):
# names = []
# classes = [self.__class__]
# while classes:
# aclass = classes.pop(0)
# if aclass.__bases__:
# classes = classes + list(aclass.__bases__)
# names = names + dir(aclass)
# return names
示例3: complete
# 需要导入模块: import gnureadline [as 别名]
# 或者: from gnureadline import get_line_buffer [as 别名]
def complete(self, text, state):
response = None
if state == 0:
# This is the first time for this text,
# so build a match list.
origline = readline.get_line_buffer()
begin = readline.get_begidx()
end = readline.get_endidx()
being_completed = origline[begin:end]
words = origline.split()
logging.debug('origline=%s', repr(origline))
logging.debug('begin=%s', begin)
logging.debug('end=%s', end)
logging.debug('being_completed=%s', being_completed)
logging.debug('words=%s', words)
if not words:
self.current_candidates = sorted(
self.options.keys()
)
else:
try:
if begin == 0:
# first word
candidates = self.options.keys()
else:
# later word
first = words[0]
candidates = self.options[first]
if being_completed:
# match options with portion of input
# being completed
self.current_candidates = [
w for w in candidates
if w.startswith(being_completed)
]
else:
# matching empty string,
# use all candidates
self.current_candidates = candidates
logging.debug('candidates=%s',
self.current_candidates)
except (KeyError, IndexError) as err:
logging.error('completion error: %s', err)
self.current_candidates = []
try:
response = self.current_candidates[state]
except IndexError:
response = None
logging.debug('complete(%s, %s) => %s',
repr(text), state, response)
return response