在python-prompt-toolkit-3.0.2上添加键绑定会破坏建议和历史搜索
我正在尝试添加一种不同的方式来完成多行输入。应该很简单,但我得到了一个意想不到的结果:添加新绑定后,历史记录和建议功能停止工作 我尝试使用load_basic_绑定,但没有任何帮助 如果我再评论一下键绑定、建议和历史作品 从prompt_toolkit导入PromptSession 从prompt_toolkit.auto_建议导入AutoSuggestFromHistory 从prompt_toolkit.key_binding导入KeyBindings 会话=提示会话 加载空绑定 绑定=键绑定 阅读基础知识也不起作用 绑定=加载\基本\绑定 问题就在这里 添加此项后,请记录历史并建议停止工作 应该添加一种新的退出方式 我用渴望的真假来测试,没有任何变化 @bindings.add def_事件: event.app.exitresult=event.app.current\u buffer.text 尽管如此: text=session.prompt '> ', auto_suggest=AutoSuggestFromHistory, key_bindings=bindings,如果我对键绑定进行注释,则历史记录和搜索工作将重新开始 multiline=True,此错误只发生在multiline上,如果将此设置为False,则错误不会发生 启用\u历史\u搜索=真 打印“您说过的:%s”%text 若我使用load_basic_绑定,我可以使用Alt+Enter接受命令,并将其添加到历史记录中。 因为我必须添加函数,将命令添加到历史记录中在python-prompt-toolkit-3.0.2上添加键绑定会破坏建议和历史搜索,python,prompt-toolkit,Python,Prompt Toolkit,我正在尝试添加一种不同的方式来完成多行输入。应该很简单,但我得到了一个意想不到的结果:添加新绑定后,历史记录和建议功能停止工作 我尝试使用load_basic_绑定,但没有任何帮助 如果我再评论一下键绑定、建议和历史作品 从prompt_toolkit导入PromptSession 从prompt_toolkit.auto_建议导入AutoSuggestFromHistory 从prompt_toolkit.key_binding导入KeyBindings 会话=提示会话 加载空绑定 绑定=键绑
session.history.append_string(event.app.current_buffer.text)
使用箭头,我可以从历史中选择。它显示了历史的启示
在基于Ubuntu 18.04、Python 3.7.6、Prompt Toolkit 3.0.2的Linux Mint 19.2上测试
当我使用load_basic_绑定运行所有代码并使用alt+Enter时,它会添加到历史记录中——我可以使用,但不会添加到历史记录中。似乎您必须添加函数,以便将其添加到历史记录中。
from prompt_toolkit import PromptSession
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.bindings.basic import load_basic_bindings
session = PromptSession()
# load empty binds
#bindings = KeyBindings()
# reading from the basic binds did not work either
bindings = load_basic_bindings()
# HERE IS THE PROBLEM
# After adding this the history and suggest stop working
# should just add a new way to exit
# I have tested with the eager True and False, with no changes
@bindings.add('#')
def _(event):
session.history.append_string(event.app.current_buffer.text)
event.app.exit(result=event.app.current_buffer.text)
while True:
text = session.prompt(
'> ',
auto_suggest=AutoSuggestFromHistory(),
key_bindings=bindings, # if I comment the key bindings, the history and search work againg
multiline=True, # this bug just happens on multiline, if put this False the bug does not happens
enable_history_search=True
)
print('You said: %s' % text)