python - 在嵌套完成 python-prompt-ttoolkit 中使用自定义分隔符
问题描述
我正在使用 python-prompt-toolkit 进行自动补全,它对于单次补全工作非常好。但我需要使用嵌套补全。考虑文档中的以下示例:
from prompt_toolkit import prompt
from prompt_toolkit.completion import NestedCompleter
completer = NestedCompleter.from_nested_dict(
{
"show":
{"version": None,
"clock": None,
"ip": {"interface": {"brief": None}}
},
"exit": None,
}
)
def main():
text = prompt("Type a command: ", completer=completer)
print("You said: %s" % text)
if __name__ == "__main__":
main()
虽然它确实有效,但它仅在我使用空格作为分隔符(即,在单词之间保留空格)来分隔单词时才有效,例如
。但是show version
我想使用'\\' or '/'
(取决于操作系统)作为分隔符,所以它会像show/ip/interface/brief
(类似壳路径完成如何工作)。我知道你可以做到这一点,但我不知道怎么做?非常感谢您的帮助。
解决方案
推荐阅读
- javascript - 按名称 javascript 禁用许多字段
- angularjs - 如何切换到量角器中的通知弹出窗口?
- python-3.x - Python 3,如何为 pip 可安装包和可运行脚本导入模块?
- r - 错误使用 sapply 和 split 在 facet wrap ggplot 上具有不同的 pvalue 和 r^2
- c++ - 在谷歌测试中创建模拟类的向量
- c# - 使用正则表达式替换的 SSIS/C# 中的字符串未更新
- arrays - Angular 5 用于从 JSON API 绑定和过滤数据到下拉列表
- java - 将 sortedInsert 插入具有 Java 属性的单个 LinkedList.of 对象的问题
- python - 如何在 Python 中将 SVG 转换为 PNG 或 JPEG?
- django - 如何让 Django Channels 处理更高的消息频率?