python纵向制表符命令_Python中raw_input()中子命令的制表符完成

我试图在主列表的子列表上完成制表符之类的东西

commands = ['help', 'set', 'info']

sub_command = ['module', 'level']

modules = ['pr', 'tls', 'tld']

levels = ['high', 'mid', 'low']

任何想法如何做这样的事情:

>>> se mo tl

这是主要列表的代码:

from core.libs.interpreter import interpreter

import re

try:

import readline

except ImportError:

print '\n[!] The "readline" module is required to provide elaborate line editing and history features'

else:

pass

COMMANDS = interpreter.commands

RE_SPACE = re.compile('.*\s+$', re.M)

class Completer(object):

'''

internal readline buffer to determine the state of the overall completion,

which makes the state logic a bit simpler

'''

def complete(self, text, state):

"Generic readline completion entry point."

buffer = readline.get_line_buffer()

line = readline.get_line_buffer().split()

# show all commands

if not line:

return [c + ' ' for c in COMMANDS][state]

# account for last argument ending in a space

if RE_SPACE.match(buffer):

line.append('')

# resolve command to the implementation function

cmd = line[0].strip()

if cmd in COMMANDS:

#impl = getattr(self, 'complete_%s' % cmd)

args = line[1:]

if args:

return (args + [None])[state]

return [cmd + ' '][state]

results = [c + ' ' for c in COMMANDS if c.startswith(cmd)] + [None]

return results[state]

def tab(self):

# to work with non nix systems

try:

readline.set_completer_delims(' \t\n;')

readline.parse_and_bind("tab: complete")

readline.set_completer(self.complete)

except:

pass

complete = Completer()

我试图遵循这个tutorial,但没有运气。

提前致谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值