Windows 中的 python 制表符补全

发布于 2024-07-26 23:11:00 字数 332 浏览 6 评论 0原文

我正在用 python 编写一个类似 shell 的跨平台程序,我想添加自定义制表符完成操作。 在 Unix 系统上,我可以使用内置的 readline 模块,并使用如下代码来指定按下 TAB 键时可能完成的列表:

import readline
readline.parse_and_bind( 'tab: complete' )
readline.set_completer( ... )

如何在 Windows 上执行此操作? 如果可能的话,我想避免依赖第三方软件包。 如果不存在解决方案,是否可以简单地捕获 TAB 键按下,以便我可以从头开始实现自己的解决方案?

I'm writing a cross-platform shell like program in python and I'd like to add custom tab-completion actions. On Unix systems I can use the built-in readline module and use code like the following to specify a list of possible completions when I hit the TAB key:

import readline
readline.parse_and_bind( 'tab: complete' )
readline.set_completer( ... )

How can I do this on Windows? I'd like to avoid relying on 3rd-party packages if possible. If no solution exists is it possible to simply trap TAB key press so that I can implement my own from scratch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泪意 2024-08-02 23:11:00

你看一下 PyReadline:适用于 Windows 的基于 ctypes 的 readline 吗? 虽然第 3 方软件包不是您的选择,但也许它对于构建自己的软件包很有用,不是:)。

Do u have a look at PyReadline: a ctypes-based readline for Windows? Although 3rd-party packages is NOT your option, maybe it's useful for build one's own, isn't it:).

疾风者 2024-08-02 23:11:00

你也可以看看 ipython 如何使用 pyreadline 来实现它,也许

you could look at how ipython does it with pyreadline as well, maybe

月朦胧 2024-08-02 23:11:00

另一种可以查看的方法是 readline.py

Another possibility to check out is readline.py.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文