提示用户填写模板?
我从来没能在任何语言中找到关于此的任何内容,但我想做的事情对我来说似乎相当简单。
我想提示用户输入,但让他们填写某种模板。让我们使用一个简单的 DD-MM-YYYY
日期作为示例。
[█ - - ]
█
是用户写入的位置。 当他们编写时,[
和 -
保持在原来的位置,光标跳过它们,然后按 Enter 键提交。
我并不期望有人为我编写所有这些内容,但是 cin
和 cout
似乎是太粗糙的工具,所以我想知道在哪里如果没有的话,我什至应该开始。
是否有什么东西已经做到了这一点,或者至少有什么东西可以让我更好地控制光标以允许我自己编写它? 我不想想要绘制一个带有窗口、边框和颜色的完整 TUI,所以 ncurses 只会妨碍我。我只想要一个返回输入的单行文本字段。
编辑:对于有用的库来说,最有前途的非 ncruses 替代方案似乎是 Terminal。
I've never been able to find anything about this in any language, but what I want to do seems rather simple to me.
I want to prompt the user for input, but have them fill in a sort of template. Let's use a simple DD-MM-YYYY
date as an example.
[█ - - ]
█
is where the user writes.
As they write, the [
and -
stay where they are, with the cursor jumping past them, and hitting enter submits.
I'm not expecting anyone to write all of this for me, but cin
and cout
seem to be too crude a tools to do this, and so I'm wondering where I should even start, if not there.
Is there something that already does this, or at least something that gives me more control of the cursor to allow me to write it myself?
I do not want to be drawing a full-on TUI with windows and boarders and colors, so ncurses would just get in the way. I just want a single-line text field that returns the input.
EDIT: The most promising non-ncruses alternative for a helpful library seems to be Terminal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您需要的是基于文本的 GUI 库,例如 ncurses。执行控制台工作是特定于平台的,每个系统都有自己的控制台 API 来执行此操作。如果您想自己实现这一点,则必须检查您的目标操作系统在控制台 API 方面为您提供了哪些选项,并基于此构建自定义解决方案。
Generally what you want is a text-based GUI library, such as ncurses. Doing console work is platform-specific, and every system has its own console API to do this. If you want to implement this yourself, you would have to examine what options does your target operating system give you in terms of console API, and build a custom solution based on that.