TUI: update (most menu functions working)
[fanfix.git] / src / be / nikiroo / fanfix / reader / TuiReader.java
CommitLineData
c1873e56
NR
1package be.nikiroo.fanfix.reader;
2
3import java.io.IOException;
c1873e56 4
6322ab64
NR
5import jexer.TApplication;
6import jexer.TApplication.BackendType;
c1873e56 7import be.nikiroo.fanfix.Instance;
c1873e56 8
6322ab64
NR
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 */
c1873e56 18class TuiReader extends BasicReader {
6322ab64
NR
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 }
c1873e56
NR
45 }
46
6322ab64 47 return backendType;
c1873e56
NR
48 }
49
211f7ddb 50 @Override
bc2ea776 51 public void read() throws IOException {
6322ab64 52 try {
bc2ea776 53 TuiReaderApplication app = new TuiReaderApplication(this,
6322ab64
NR
54 guessBackendType());
55 new Thread(app).start();
56 } catch (Exception e) {
57 Instance.syserr(e);
58 }
59 }
60
211f7ddb 61 @Override
bc2ea776 62 public void browse(String source) {
c1873e56 63 try {
e2d017a3 64 TuiReaderApplication app = new TuiReaderApplication(this, source,
bc2ea776 65 guessBackendType());
c1873e56
NR
66 new Thread(app).start();
67 } catch (Exception e) {
68 Instance.syserr(e);
69 }
70 }
71}