Java CLI UI 设计:框架还是库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2417495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 21:01:44  来源:igfitidea点击:

Java CLI UI-design: frameworks or libraries?

javaframeworksdesign-patternscommand-line-interfaceui-design

提问by Fuu

I'm currently working on a small utility program that only requires a command line interface, and I started wondering if Java provided any standard way of creating the CLI, in a similar way that Swing and the likes exist for GUIs. I'm not really interested in command line parameters and parsing of them, but rather the command based interaction the user has with the program to use it. This is for the situations where GUI simply is unnecessary or not an option for using the program.

我目前正在开发一个只需要命令行界面的小型实用程序,我开始想知道 Java 是否提供了任何创建 CLI 的标准方法,类似于用于 GUI 的 Swing 等。我对命令行参数和解析它们并不真正感兴趣,而是对用户与程序进行基于命令的交互以使用它感兴趣。这适用于 GUI 根本不需要或不是使用该程序的选项的情况。

Googling the subject pretty much only results in tutorials on how to use BufferedReader and the likes to do rudimentary interaction with the user, aimed at people learning the basics of Java and writing simple UI that asks for name and prints "Hello World!" etc..

谷歌搜索这个主题几乎只会得到关于如何使用 BufferedReader 等与用户进行基本交互的教程,目的是让人们学习 Java 的基础知识并编写简单的 UI 来询问名称并打印“Hello World!” 等等..

Are the any libraries that are focused on providing a good framework for quickly implementing a more complex CLI UI or is this really something that everyone implements in ad hoc manner for their own utilities?

是否有任何库专注于为快速实现更复杂的 CLI UI 提供良好的框架,或者这真的是每个人都以特别方式为自己的实用程序实现的东西?

Maybe someone knows of patterns for the implementation that were created back in time when not everything was graphical? That would also be useful resource.

也许有人知道实现的模式是在并非一切都是图形的时候创建的?这也是有用的资源。

采纳答案by John

Perhaps CLI Toolkit...

也许 CLI 工具包...

http://alexis.royer.free.fr/CLI/

http://alexis.royer.free.fr/CLI/

回答by Pierre Rust

You can also have a look and Clamshell-cli or spring shell:

你也可以看看 Clamshell-cli 或 spring shell:

  • Clamshell-cliis relatively simple and easy to use : You can look at jmx-clito get a nice example of what can be done with it.

  • Spring Shellis bigger but more feature-full (tab completion, etc). It has been extracted from spring Roo and released as an independent framework

  • Clamshell-cli相对简单且易于使用:您可以查看jmx-cli以获得一个很好的示例,说明可以使用它做什么。

  • Spring Shell更大但功能更全(选项卡完成等)。它是从 spring Roo 中提取出来的,作为一个独立的框架发布

回答by Joe

There is a project called JLine that provides cross-platform support for general command-line input handling:

有一个名为 JLine 的项目,它为通用命令行输入处理提供跨平台支持:

http://jline.sourceforge.net/

http://jline.sourceforge.net/

More of a support library than a framework though.

与其说是一个框架,不如说是一个支持库。

回答by David Soroko

Try searching for CURSES and java, something like http://www.google.co.uk/search?q=curses+for+java. Long time ago CHARVA ( http://www.pitman.co.za/projects/charva/index.html) looked nice.

尝试搜索 CURSES 和 java,例如http://www.google.co.uk/search?q=curses+for+java。很久以前 CHARVA ( http://www.pitman.co.za/projects/charva/index.html) 看起来不错。

回答by Al.

I've used the apache commons CLI library in the past and has worked well for me: http://commons.apache.org/cli/

我过去使用过 apache commons CLI 库并且对我来说效果很好:http: //commons.apache.org/cli/