X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Ftui%2FTuiReader.java;fp=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Ftui%2FTuiReader.java;h=7192854ea6fed7f07978427a9c6534fbeb07e74a;hb=16a81ef7656c5c692fb831927e75edde25dd77a0;hp=0000000000000000000000000000000000000000;hpb=5895a95876fe63e76e726ef7fc4c97efe2ebd5b1;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/tui/TuiReader.java b/src/be/nikiroo/fanfix/reader/tui/TuiReader.java new file mode 100644 index 0000000..7192854 --- /dev/null +++ b/src/be/nikiroo/fanfix/reader/tui/TuiReader.java @@ -0,0 +1,73 @@ +package be.nikiroo.fanfix.reader.tui; + +import java.io.IOException; + +import jexer.TApplication; +import jexer.TApplication.BackendType; +import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.reader.BasicReader; +import be.nikiroo.fanfix.reader.Reader; + +/** + * This {@link Reader}is based upon the TUI widget library 'jexer' + * (https://github.com/klamonte/jexer/) and offer, as its name suggest, a Text + * User Interface. + *

+ * It is expected to be on par with the GUI version. + * + * @author niki + */ +class TuiReader extends BasicReader { + /** + * Will detect the backend to use. + *

+ * Swing is the default backend on Windows and MacOS while evreything else + * will use XTERM unless explicitly overridden by jexer.Swing = + * true or false. + * + * @return the backend to use + */ + private static BackendType guessBackendType() { + // TODO: allow a config option to force one or the other? + TApplication.BackendType backendType = TApplication.BackendType.XTERM; + if (System.getProperty("os.name").startsWith("Windows")) { + backendType = TApplication.BackendType.SWING; + } + + if (System.getProperty("os.name").startsWith("Mac")) { + backendType = TApplication.BackendType.SWING; + } + + if (System.getProperty("jexer.Swing") != null) { + if (System.getProperty("jexer.Swing", "false").equals("true")) { + backendType = TApplication.BackendType.SWING; + } else { + backendType = TApplication.BackendType.XTERM; + } + } + + return backendType; + } + + @Override + public void read() throws IOException { + try { + TuiReaderApplication app = new TuiReaderApplication(this, + guessBackendType()); + new Thread(app).start(); + } catch (Exception e) { + Instance.getTraceHandler().error(e); + } + } + + @Override + public void browse(String source) { + try { + TuiReaderApplication app = new TuiReaderApplication(this, source, + guessBackendType()); + new Thread(app).start(); + } catch (Exception e) { + Instance.getTraceHandler().error(e); + } + } +}