LICENSE CHANGED TO MIT
[nikiroo-utils.git] / README.md
... / ...
CommitLineData
1Jexer - Java Text User Interface library
2========================================
3
4This library implements a text-based windowing system reminiscient of
5Borland's [Turbo Vision](http://en.wikipedia.org/wiki/Turbo_Vision)
6system. (For those wishing to use the actual C++ Turbo Vision
7library, see [Sergio Sigala's C++ version based on the public domain
8sources released by Borland.](http://tvision.sourceforge.net/) )
9
10Jexer currently supports three backends:
11
12* System.in/out to a command-line ECMA-48 / ANSI X3.64 type terminal
13 (tested on Linux + xterm). I/O is handled through terminal escape
14 sequences generated by the library itself: ncurses is not required
15 or linked to. xterm mouse tracking using UTF8 and SGR coordinates
16 are supported. For the demo application, this is the default
17 backend on non-Windows platforms.
18
19* The same command-line ECMA-48 / ANSI X3.64 type terminal as above,
20 but to any general InputStream/OutputStream. See the file
21 jexer.demos.Demo2 for an example of running the demo over a TCP
22 socket.
23
24* Java Swing UI. This backend can be selected by setting
25 jexer.Swing=true. The default window size for Swing is 132x40,
26 which is set in jexer.session.SwingSession. For the demo
27 application, this is the default backend on Windows platforms.
28
29Additional backends can be created by subclassing
30jexer.backend.Backend and passing it into the TApplication
31constructor.
32
33
34
35License
36-------
37
38This project is licensed under the MIT License. See the file LICENSE
39for the full license text.
40
41
42
43Acknowledgements
44----------------
45
46Jexer makes use of the Terminus TrueType font [made available
47here](http://files.ax86.net/terminus-ttf/) .
48
49
50
51Usage
52-----
53
54Simply subclass TApplication and then run it in a new thread:
55
56```Java
57import jexer.*;
58
59class MyApplication extends TApplication {
60
61 public MyApplication() throws Exception {
62 super(BackendType.SWING); // Could also use BackendType.XTERM
63
64 // Create standard menus for File and Window
65 addFileMenu();
66 addWindowMenu();
67
68 // Add a custom window, see below for its code.
69 addWindow(new MyWindow(this));
70 }
71
72 public static void main(String [] args) {
73 try {
74 MyApplication app = new MyApplication();
75 (new Thread(app)).start();
76 } catch (Throwable t) {
77 t.printStackTrace();
78 }
79 }
80}
81```
82
83Similarly, subclass TWindow and add some widgets:
84
85```Java
86class MyWindow extends TWindow {
87
88 public MyWindow(TApplication application) {
89 // See TWindow's API for several constructors. This one uses the
90 // application, title, width, and height. Note that the window width
91 // and height include the borders. The widgets inside the window
92 // will see (0, 0) as the top-left corner inside the borders,
93 // i.e. what the window would see as (1, 1).
94 super(application, "My Window", 30, 20);
95
96 // See TWidget's API for convenience methods to add various kinds of
97 // widgets. Note that ANY widget can be a container for other
98 // widgets: TRadioGroup for example has TRadioButtons as child
99 // widgets.
100
101 // We will add a basic label, text entry field, and button.
102 addLabel("This is a label", 5, 3);
103 addField(5, 5, 20, false, "enter text here");
104 // For the button, we will pop up a message box if the user presses
105 // it.
106 addButton("Press &Me!", 5, 8, new TAction() {
107 public void DO() {
108 MyWindow.this.messageBox("Box Title", "You pressed me, yay!");
109 }
110 } );
111 }
112}
113```
114
115Put these into a file, compile it with jexer.jar in the classpath, run
116it and you'll see an application like this:
117
118![The Example Code Above](/screenshots/readme_application.png?raw=true "The application in the text of README.md")
119
120See the files in jexer.demos for many more detailed examples showing
121all of the existing UI controls. The demo can be run in three
122different ways:
123
124 * 'java -jar jexer.jar' . This will use System.in/out with
125 xterm-like sequences on non-Windows platforms. On Windows it will
126 use a Swing JFrame.
127
128 * 'java -Djexer.Swing=true -jar jexer.jar' . This will always use
129 Swing on any platform.
130
131 * 'java -cp jexer.jar jexer.demos.Demo2 PORT' (where PORT is a
132 number to run the TCP daemon on). This will use the telnet
133 protocol to establish an 8-bit clean channel and be aware of
134 screen size changes.
135
136
137
138More Screenshots
139----------------
140
141![Several Windows Open Including A Terminal](/screenshots/screenshot1.png?raw=true "Several Windows Open Including A Terminal")
142
143![Yo Dawg...](/screenshots/yodawg.png?raw=true "Yo Dawg, I heard you like text windowing systems, so I ran a text windowing system inside your text windowing system so you can have a terminal in your terminal.")
144
145
146
147System Properties
148-----------------
149
150The following properties control features of Jexer:
151
152 jexer.Swing
153 -----------
154
155 Used only by jexer.demos.Demo1. If true, use the Swing interface
156 for the demo application. Default: true on Windows platforms
157 (os.name starts with "Windows"), false on non-Windows platforms.
158
159 jexer.Swing.cursorStyle
160 -----------------------
161
162 Used by jexer.io.SwingScreen. Selects the cursor style to draw.
163 Valid values are: underline, block, outline. Default: underline.
164
165
166
167Known Issues / Arbitrary Decisions
168----------------------------------
169
170Some arbitrary design decisions had to be made when either the
171obviously expected behavior did not happen or when a specification was
172ambiguous. This section describes such issues.
173
174 - TTerminalWindow will hang on input from the remote if the
175 TApplication is exited before the TTerminalWindow's process has
176 closed on its own. This is due to a Java limitation/interaction
177 between blocking reads (which is necessary to get UTF8 translation
178 correct) and file streams.
179
180 - See jexer.tterminal.ECMA48 for more specifics of terminal
181 emulation limitations.
182
183 - TTerminalWindow uses cmd.exe on Windows. Output will not be seen
184 until enter is pressed, due to cmd.exe's use of line-oriented
185 input (see the ENABLE_LINE_INPUT flag for GetConsoleMode() and
186 SetConsoleMode()).
187
188 - TTerminalWindow launches 'script -fqe /dev/null' on non-Windows
189 platforms. This is a workaround for the C library behavior of
190 checking for a tty: script launches $SHELL in a pseudo-tty. This
191 works on Linux but might not on other Posix-y platforms.
192
193 - Java's InputStreamReader as used by the ECMA48 backend requires a
194 valid UTF-8 stream. The default X10 encoding for mouse
195 coordinates outside (160,94) can corrupt that stream, at best
196 putting garbage keyboard events in the input queue but at worst
197 causing the backend reader thread to throw an Exception and exit
198 and make the entire UI unusable. Mouse support therefore requires
199 a terminal that can deliver either UTF-8 coordinates (1005 mode)
200 or SGR coordinates (1006 mode). Most modern terminals can do
201 this.
202
203 - jexer.session.TTYSession calls 'stty size' once every second to
204 check the current window size, performing the same function as
205 ioctl(TIOCGWINSZ) but without requiring a native library.
206
207 - jexer.io.ECMA48Terminal calls 'stty' to perform the equivalent of
208 cfmakeraw() when using System.in/out. System.out is also
209 (blindly!) put in 'stty sane cooked' mode when exiting.
210
211
212
213Roadmap
214-------
215
216Many tasks remain before calling this version 1.0:
217
2180.0.4
219
220- TStatusBar
221- TEditor
222- TWindow
223 - "Smart placement" for new windows
224
2250.0.5: BUG HUNT
226
227- Swing performance. Even with double buffering it isn't great.
228
2290.1.0: BETA RELEASE
230
231- TSpinner
232- TComboBox
233- TCalendar
234
235Wishlist features (2.0):
236
237- TTerminal
238 - Handle resize events (pass to child process)
239- Screen
240 - Allow complex characters in putCharXY() and detect them in putStringXY().
241- Drag and drop
242 - TEditor
243 - TField
244 - TText
245 - TTerminal
246 - TComboBox