C 命令行应用程序:如何以编程方式移动光标
我正在用 C 语言编写一个命令行计算器,如果它能够在每次关闭(例如)突出显示前一个括号时移动光标(例如在 emacs 等中),那么它将非常有用。
例如,如果您启动 emacs,然后输入:
(blah)
然后在输入右括号后一段时间,第一个括号会突出显示。
我尝试过谷歌搜索,但我真的不知道要搜索什么。
是否有一种简单且多平台的方法(至少在 Linux 上工作就可以了,但我希望它至少也能在 Windows 上工作)以这种方式移动光标?
I am writing a commandline calculator in C, and it would be very useful if it had the ability to move the cursor each time you close (for example) a parenthesis highlighting the previous one, like in emacs, etc.
For example, if you launch emacs, and type:
(blah)
then for a while after you type the closing parenthesis, the first one is highlighted.
I've tried some googling, but I don't really know what to search for.
Is there a simple and multiplatform (at the very least it's fine if it'd work on Linux, but I'd like it to work at least on Windows as well) way to move the cursor in this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想更好地控制控制台,请查看 ncurses 库。
Linux控制台也可以通过控制台代码进行控制。不需要库,只需
printf
将适当的代码输出到stdout
即可。If you want better control over the console, take a look at the ncurses library.
The Linux console can also be controlled through console codes. No libraries needed, just
printf
the appropriate codes tostdout
.您应该搜索的内容是“termcap”、“terminfo”或“curses”。
The things you should search for are 'termcap', 'terminfo' or 'curses.'
ncurses
应该能够做你想做的事情重新要求。ncurses
should be able to do what you're asking for.查看 ANSI 转义码。它们非常基础,但却是一个很好的起点。结果是它们适用于大多数终端(Linux 和 Windows)。
Check out ANSI escape codes. They are pretty basic, but a good place to start. The upshot is that they work for most terminals (Linux and Windows).