用于为 Java 应用程序构建交互式 shell 的库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14080604/
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-31 14:59:29  来源:igfitidea点击:

Libraries for constructing an interactive shell for Java application

javalibraries

提问by ianc1215

I am looking for libraries for Java that will allow me to create an interactive shell. I have done some search around and have not turned up a whole lot. Most of what I have found is libraries for adding command argument parsing to my application which does not help me a lot.

我正在寻找允许我创建交互式 shell 的 Java 库。我已经做了一些搜索,并没有出现很多。我发现的大部分内容是用于向我的应用程序添加命令参数解析的库,这对我没有多大帮助。

The best lead I have found is a library called Clichewhich does exactly what I need. The problem is its too simple. I am looking for something that has more customization.

我找到的最好的线索是一个名为Cliche的库,它完全符合我的需要。问题是它太简单了。我正在寻找具有更多自定义功能的东西。

Has anyone come across something a little more advanced?

有没有人遇到过更高级的东西?

回答by mikera

Options to consider:

要考虑的选项:

  • javacurses / JCurses- a console-based windowing toolkit, similar to the UNIX curses design
  • swing-consolemight be appropriate if you want a console-style view / output in a Swing GUI window. you could use this to build an interactive shell.
  • JLine- library for console input similar to GNU readline
  • Several JVM languages offer an interactive REPL environmentwhich can be used as an interactive shell, e.g. Clojure
  • javacurses / JCurses- 基于控制台的窗口工具包,类似于 UNIX 的 curses 设计
  • 如果您想要在 Swing GUI 窗口中获得控制台样式的视图/输出,swing-console可能是合适的。您可以使用它来构建交互式外壳。
  • JLine- 类似于 GNU readline 的控制台输入库
  • 几种 JVM 语言提供了一个交互式REPL 环境,可以用作交互式 shell,例如 Clojure

回答by Gonzalo

We are using Spring shell, and it worked really well for us. Some of its features:

我们正在使用Spring shell,它对我们来说非常有效。它的一些特点:

  • A simple, annotation driven, programming model to contribute custom commands

  • Use of Spring's classpath scanning functionality asthe basis for a
    command plugin strategy and command develoment

  • Inheritance of the Roo Shell features, most notably tab completion, colorization, and script execution.

  • Customization of command prompt, banner, shell history file name.

  • 一个简单的、注释驱动的编程模型来贡献自定义命令

  • 使用 Spring 的类路径扫描功能作为
    命令插件策略和命令开发的基础

  • 继承 Roo Shell 功能,最显着的是选项卡完成、着色和脚本执行。

  • 自定义命令提示符、横幅、shell 历史文件名。

回答by burna

According to this QuestionJLinecan be a good try.

根据这个问题JLine可以很好地尝试。

Features of JLine

JLine的特点

  • Command history - Lines that have been previously entered may be recalled and edited and can be persisted so that they are available
    across sessions of your program.
  • Line editing - JLine allows full editing of the current command line and attempts to mimic as much of the behavior of GNU Readline as possible, including support for both emacs and vi key mappings.
  • Completion - JLine provides a pluggable mechanism for implementing command line tab completion (of course completion can be bound to any key you wish).
  • Custom Key bindings - Keys may be arbitrarily remapped to perform a specific action, and JLine attempts to honor any mapping that is set in your existing readline .inputrc file.
  • Character Masking - Input may be gathered from the user without any visual feedback. This is useful for prompting for passwords.
  • 99.99% Java - The vast portion of JLine is all Java, using only some small bit of native code, provided by the Jansi project, to
    support Windows.
  • 命令历史 - 先前输入的行可以被调用和编辑,并且可以保留,以便它们
    在您的程序的会话中可用。
  • 行编辑 - JLine 允许对当前命令行进行完整编辑,并尝试尽可能多地模仿 GNU Readline 的行为,包括对 emacs 和 vi 键映射的支持。
  • Completion - JLine 提供了一种可插入的机制来实现命令行选项卡完成(当然完成可以绑定到您希望的任何键)。
  • 自定义键绑定 - 可以任意重新映射键以执行特定操作,并且 JLine 尝试遵守在现有 readline .inputrc 文件中设置的任何映射。
  • 字符屏蔽 - 可以从用户那里收集输入,而无需任何视觉反馈。这对于提示输入密码很有用。
  • 99.99% Java - JLine 的大部分都是 Java,只使用了一小部分由 Jansi 项目提供的本机代码来
    支持 Windows。