python - prompt-toolkit 在一列中以 READLINE_LIKE 样式完成
问题描述
如何在提示工具包中以 READLINE_LIKE 样式完成一列中的自定义单词?我正在尝试添加 '\n' 来创建一个新行,但它会自动在下一行之前添加制表符。
from prompt_toolkit.completion import Completer, Completion
from prompt_toolkit.shortcuts import CompleteStyle, prompt
class MyCompleter(Completer):
def get_completions(self, document, complete_event):
word = document.get_word_before_cursor()
c = [('one', 'description of One'), ('two', 'description of Two'), ('three', 'description of Three')]
for complete in c:
if complete[0].startswith(word):
display = complete[0] + ' -> ' + complete[1] + '\n'
yield Completion(
complete[0],
start_position=-len(word),
display=display,
)
prompt(
"> ",
completer=MyCompleter(),
complete_style=CompleteStyle.READLINE_LIKE
)
以下代码显示如下完成:
> <Tab>
one -> description of One
two -> description of Two
three -> description of Three
但我希望它是这样的:
> <Tab>
one -> description of One
two -> description of Two
three -> description of Three
解决方案
推荐阅读
- automapper - 在 Automapper 中处理多种日期格式
- max - 您将使用哪些操作来实现具有入队和出队的优先队列 PQ?
- scala - Spark Scala 错误 - 错误:在类中找不到主要方法
- powershell - 用于向现有 CSV 文件添加包含 4 个项目的新行的 Powershell 脚本
- c++ - g++ 9 个概念支持包括
在 Ubuntu 18.04 上 - linux - Bash脚本比较变量文件名列表从一个txt文件到另一个并在linux中做某事
- c++ - nxn数组不打印到outfile?
- python-3.x - 将 Ubutnu 中的 Python 指向 3.6
- xamarin - 如何在 Xamarin.Forms 中为 StackLayout 正确创建自定义渲染器?
- java - 通过 Java Webapp 从查询中下载非常大的结果