X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FTuiReader.java;h=c71cf95f5be244914eda25cd46e4d69493452852;hb=e2d017a31297742d3ea6ac215c3487fa6c67ddb1;hp=12f048240a05f0d19d116eec3c7df4c82c61a57a;hpb=68e2c6d20049d713de1bd31b749450b2f60d8340;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/TuiReader.java b/src/be/nikiroo/fanfix/reader/TuiReader.java index 12f0482..c71cf95 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReader.java +++ b/src/be/nikiroo/fanfix/reader/TuiReader.java @@ -1,33 +1,68 @@ package be.nikiroo.fanfix.reader; import java.io.IOException; -import java.util.List; +import jexer.TApplication; +import jexer.TApplication.BackendType; import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.LocalLibrary; -import be.nikiroo.fanfix.data.MetaData; +/** + * 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 { - @Override - public void read() throws IOException { - if (getStory() == null) { - throw new IOException("No story to read"); + /** + * 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; + } } - open(getLibrary(), getStory().getMeta().getLuid()); + return backendType; } @Override - public void read(int chapter) throws IOException { - // TODO: show a special page? - read(); + public void read() throws IOException { + try { + TuiReaderApplication app = new TuiReaderApplication(this, + guessBackendType()); + new Thread(app).start(); + } catch (Exception e) { + Instance.syserr(e); + } } @Override public void browse(String source) { - List stories = getLibrary().getListBySource(source); try { - TuiReaderApplication app = new TuiReaderApplication(stories, this); + TuiReaderApplication app = new TuiReaderApplication(this, source, + guessBackendType()); new Thread(app).start(); } catch (Exception e) { Instance.syserr(e);