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