Fix remote calls with (valid) NULL arguments
[fanfix.git] / src / be / nikiroo / fanfix / reader / TuiReader.java
... / ...
CommitLineData
1package be.nikiroo.fanfix.reader;
2
3import java.io.IOException;
4
5import jexer.TApplication;
6import jexer.TApplication.BackendType;
7import be.nikiroo.fanfix.Instance;
8
9/**
10 * This {@link Reader}is based upon the TUI widget library 'jexer'
11 * (https://github.com/klamonte/jexer/) and offer, as its name suggest, a Text
12 * User Interface.
13 * <p>
14 * It is expected to be on par with the GUI version.
15 *
16 * @author niki
17 */
18class TuiReader extends BasicReader {
19 /**
20 * Will detect the backend to use.
21 * <p>
22 * Swing is the default backend on Windows and MacOS while evreything else
23 * will use XTERM unless explicitly overridden by <tt>jexer.Swing</tt> =
24 * <tt>true</tt> or <tt>false</tt>.
25 *
26 * @return the backend to use
27 */
28 private static BackendType guessBackendType() {
29 // TODO: allow a config option to force one or the other?
30 TApplication.BackendType backendType = TApplication.BackendType.XTERM;
31 if (System.getProperty("os.name").startsWith("Windows")) {
32 backendType = TApplication.BackendType.SWING;
33 }
34
35 if (System.getProperty("os.name").startsWith("Mac")) {
36 backendType = TApplication.BackendType.SWING;
37 }
38
39 if (System.getProperty("jexer.Swing") != null) {
40 if (System.getProperty("jexer.Swing", "false").equals("true")) {
41 backendType = TApplication.BackendType.SWING;
42 } else {
43 backendType = TApplication.BackendType.XTERM;
44 }
45 }
46
47 return backendType;
48 }
49
50 @Override
51 public void read() throws IOException {
52 try {
53 TuiReaderApplication app = new TuiReaderApplication(this,
54 guessBackendType());
55 new Thread(app).start();
56 } catch (Exception e) {
57 Instance.getTraceHandler().error(e);
58 }
59 }
60
61 @Override
62 public void browse(String source) {
63 try {
64 TuiReaderApplication app = new TuiReaderApplication(this, source,
65 guessBackendType());
66 new Thread(app).start();
67 } catch (Exception e) {
68 Instance.getTraceHandler().error(e);
69 }
70 }
71}