What's the best way to get text user-interface

2020-02-07 19:04发布

I need to implement a console application (possibly in Java) with ncurses-like functionality (such as navigating a menu and redrawing the whole screen).

The only solutions that I can find to do this so far are CHARVA ("A Java Windowing Toolkit for Text Terminals"), tuipeer ("A Text User Interface for the Java AWT") and a really old Dr. Dobb's article ("A Text UI for the Java AWT ").

So far, CHARVA is the best thing that I can find but I don't like the idea of it using JNI to wrap curses.

Is there any standard way, say with AWT/Swing, to do do this? What other alternatives are there?

标签: java ncurses tui
8条回答
爷的心禁止访问
2楼-- · 2020-02-07 19:25

You may want to go vote for this issue here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6351276

Essentially there is no good way to get ncurses-like functionality without JNI until this issue is addressed.

查看更多
在下西门庆
3楼-- · 2020-02-07 19:25

I believe Jcurses is a native java implementation of the curses API, I recall it have a few quirks, but it should be able to do what you want:

http://sourceforge.net/projects/javacurses/

查看更多
孤傲高冷的网名
4楼-- · 2020-02-07 19:25

I'm using JavaTUI (http://sourceforge.net/projects/javatui/files/) in my several console java projects. It's best what i can find but it so far from perfect. I'm think there is not a good TUI implemetation in java world.

查看更多
太酷不给撩
5楼-- · 2020-02-07 19:27

Try java curses (sorry it uses JNI). I also tried to implement a short version of this library just to learn JNI , see http://plindenbaum.blogspot.com/2008/01/java-native-interface-jni-notebook.html. One could also imagine a specialized JPanel displaying a matrix of characters:

public class TPanel extends JPanel
{
private Vector<Vector<YourCharAndStyle>> rows;

protected void paintComponent(Graphics g)
 {
 //paint the characters
 (...)
 }

}
查看更多
Rolldiameter
6楼-- · 2020-02-07 19:28

I think it would be better to abstract your Java code from the TUI and use ncurses against several separated parts of your application or using arguments, in a web-services style. For example, code your TUI and when the user calls an action, use ncurses to call your code passing some parameters

java -Daction=doSomething MyApp

This way you can code your app using a GUI also in case you need to.

查看更多
看我几分像从前
7楼-- · 2020-02-07 19:31

The short answer is deal with a Java wrapper around curses.

The long answer:

Terminals vary a lot, which is why terminfo/termcap libraries exist and why they are a mess to deal with (The maintainers of those projects are saints btw). They abstract away all the really basic terminal variations to something sane. Curses make those in nice efficient libraries to use.

If you want a pure Java solution, you'll need both those libraries or their equivalent in Java. I'm sure someone will point you to that if it exists, but I as far as I know it doesn't exist.

查看更多
登录 后发表回答