Fanfiction step2 + SearchableTags
[fanfix.git] / src / be / nikiroo / fanfix / reader / tui / TuiReader.java
... / ...
CommitLineData
1package be.nikiroo.fanfix.reader.tui;
2
3import java.io.IOException;
4
5import jexer.TApplication;
6import jexer.TApplication.BackendType;
7import be.nikiroo.fanfix.Instance;
8import be.nikiroo.fanfix.reader.BasicReader;
9import be.nikiroo.fanfix.reader.Reader;
10
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 */
20class TuiReader extends BasicReader {
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 }
47 }
48
49 return backendType;
50 }
51
52 @Override
53 public void read(boolean sync) throws IOException {
54 try {
55 TuiReaderApplication app = new TuiReaderApplication(this,
56 guessBackendType());
57 new Thread(app).start();
58 } catch (Exception e) {
59 Instance.getTraceHandler().error(e);
60 }
61 }
62
63 @Override
64 public void browse(String source) {
65 try {
66 TuiReaderApplication app = new TuiReaderApplication(this, source,
67 guessBackendType());
68 new Thread(app).start();
69 } catch (Exception e) {
70 Instance.getTraceHandler().error(e);
71 }
72 }
73}