问题描述
如何在提示工具包中以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
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)