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