如何实现制表符补全
我试图弄清楚如何在 C++ 应用程序中实现子命令的制表符补全。我希望它的功能与 Git 的制表符补全非常相似。我正在浏览 Git 的源代码,但它并没有引起我的注意。
我已经搜索了实现选项卡完成的方法,但没有找到直接的答案,因此我猜测它可能不一定是每个单独的应用程序都必须实现的功能。制表符补全是执行应用程序的特定 shell 的功能吗?关于让我的应用程序支持制表符补全(尤其是在 C++ 中),我需要了解哪些基础知识?
I'm trying to figure out how to implement tab completion for subcommands in a C++ application. I would like it to function much like Git's tab completion. I'm trolling through Git's source, but it's not jumping out at me.
I've searched for ways to implement tab completion and haven't found a straight-forward answer, so I'm guessing it might not necessarily be a feature each individual application has to implement. Is tab completion a feature of the particular shell the application is being executed from? What are the basics I need to know about getting my application to support tab completion (particularly in C++)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该问题已在评论中得到解答。
制表符补全是执行应用程序的特定 shell 的功能吗?
关于让我的应用程序支持制表符补全(尤其是在 C++ 中),我需要了解哪些基础知识?
The question was answered in the comments.
Is tab completion a feature of the particular shell the application is being executed from?
What are the basics I need to know about getting my application to support tab completion (particularly in C++)?
请查看此处的代码。这应该给你一个很好的起点。
您应该熟悉 Trie 数据结构,因为这是用于实现 tab 补全的常用数据结构。网上有很多教程解释的,你可以查一下。
伪代码(给定字符串列表):
对于列表中的每个字符串,将其字符存储在 Trie 数据结构中。
当用户按下 Tab 键时:
Look at the code here. This should give you a pretty good starting point.
You should be familiar with Trie data structure, as this is the common data structure used to implement tab completion. There are lots of tutorials explaining it online, look it up.
Pseudo-code (given a list of strings):
For each string in the list, store its characters in Trie data structure.
when the user hit tab key: