简体   繁体   English

命令行的日期选择器

[英]Date picker for command line

How are datepickers handled in a CLI environment? 在CLI环境中如何处理日期选择器? Is the most common route to just treat it as a text input with custom validation? 最常见的途径是将其视为具有自定义验证的文本输入吗? Are there custom "controls" that keep formatting and only allow you to edit the digits (think __/__/__ ). 是否有保留格式的自定义“控件”,仅允许您编辑数字(请考虑__/__/__ )。 Would an interactive calendar (possibly rendered using cli-tables and arrow keys / enter ) be possible/better? 交互式日历(可能使用cli-tablearrow keys渲染/ enter )是否可能/更好?

Extra Details 额外细节

I'm developing a command line app using Node.js and the Vorpal and I would like some sort of datepicker interface. 我正在使用Node.js和Vorpal开发命令行应用程序,我想要某种日期选择器界面。

Other libraries like Inquirer.js provide easy-to-use picklists, checkboxes, and input validation. 诸如Inquirer.js之类的其他库提供了易于使用的选择列表,复选框和输入验证。 They act just as they would within a GUI. 它们的行为就像在GUI中一样。

The app in question is essentially a task manager app, allowing you to edit tasks to say when you started and stopped. 该应用实质上是一个任务管理器应用,可让您编辑任务以说出启动和停止的时间。 So the dates that are required would refer to ranges (start -> stop) and all relatively recent. 因此,所需的日期将涉及范围(开始->停止)以及所有相对较新的日期。

I've never seen a datepicker (GUI) in a CLI app before, but it's totally possible to make it with Vorpal and create a Vorpal extension for it, using these commands . 我以前从未在CLI应用程序中见过日期选择器(GUI),但是完全可以使用Vorpal来创建日期选择器,并使用这些命令为其创建Vorpal扩展。

I've successfully done this type of thing once, in building less for Vorpal , which does screen redraws based on arrow key movements, etc, which would be a similar endeavor. 我已经成功完成了这种类型的操作, less了Vorpal的构建,它会根据箭头键的移动等进行屏幕重绘,这也是类似的工作。 You can check out the source here for how I do it. 您可以在此处查看我的来源。

But that's a bit of work. 但这有点工作。

The other idea (and maybe this can tie into the above) is to simply make a smart-validating date input. 另一个想法(也许可以结合到上面)是简单地输入一个智能验证日期输入。

There's a ton of Javascript date libraries like this one that can parse human date strings and standardize them. 有大量的JavaScript日期库, 像这样的可以解析人的日期字符串和规范他们。 So you would just do a normal Inquirer input, and add some validation to it. 因此,您只需要输入普通的Inquirer输入,然后向其中添加一些验证即可。


Does that help? 有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM