1 package be
.nikiroo
.fanfix
.reader
;
3 import java
.io
.IOException
;
6 import jexer
.TApplication
;
7 import jexer
.TApplication
.BackendType
;
8 import be
.nikiroo
.fanfix
.Instance
;
9 import be
.nikiroo
.fanfix
.data
.MetaData
;
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
16 * It is expected to be on par with the GUI version.
20 class TuiReader
extends BasicReader
{
22 * Will detect the backend to use.
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>.
28 * @return the backend to use
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
;
37 if (System
.getProperty("os.name").startsWith("Mac")) {
38 backendType
= TApplication
.BackendType
.SWING
;
41 if (System
.getProperty("jexer.Swing") != null) {
42 if (System
.getProperty("jexer.Swing", "false").equals("true")) {
43 backendType
= TApplication
.BackendType
.SWING
;
45 backendType
= TApplication
.BackendType
.XTERM
;
52 public void read(int chapter
) throws IOException
{
53 if (getStory() == null) {
54 throw new IOException("No story to read");
57 start(getStory().getMeta(), chapter
);
60 public void browse(String source
) {
61 start(getLibrary().getListBySource(source
));
65 * Start the application with the given stories.
68 * the stories to display
70 private void start(List
<MetaData
> metas
) {
72 TuiReaderApplication app
= new TuiReaderApplication(metas
, this,
74 new Thread(app
).start();
75 } catch (Exception e
) {
81 * Start the application with the given {@link MetaData} at the given open
85 * the story to display
89 private void start(MetaData meta
, int chapter
) {
91 TuiReaderApplication app
= new TuiReaderApplication(meta
, chapter
,
92 this, guessBackendType());
93 new Thread(app
).start();
94 } catch (Exception e
) {