| 1 | package be.nikiroo.fanfix.reader.tui; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import jexer.TApplication; |
| 6 | import jexer.TApplication.BackendType; |
| 7 | import be.nikiroo.fanfix.Instance; |
| 8 | import be.nikiroo.fanfix.reader.BasicReader; |
| 9 | import be.nikiroo.fanfix.reader.Reader; |
| 10 | import be.nikiroo.fanfix.supported.SupportType; |
| 11 | |
| 12 | /** |
| 13 | * This {@link Reader}is based upon the TUI widget library 'jexer' |
| 14 | * (https://github.com/klamonte/jexer/) and offer, as its name suggest, a Text |
| 15 | * User Interface. |
| 16 | * <p> |
| 17 | * It is expected to be on par with the GUI version. |
| 18 | * |
| 19 | * @author niki |
| 20 | */ |
| 21 | class TuiReader extends BasicReader { |
| 22 | /** |
| 23 | * Will detect the backend to use. |
| 24 | * <p> |
| 25 | * Swing is the default backend on Windows and MacOS while evreything else |
| 26 | * will use XTERM unless explicitly overridden by <tt>jexer.Swing</tt> = |
| 27 | * <tt>true</tt> or <tt>false</tt>. |
| 28 | * |
| 29 | * @return the backend to use |
| 30 | */ |
| 31 | private static BackendType guessBackendType() { |
| 32 | // TODO: allow a config option to force one or the other? |
| 33 | TApplication.BackendType backendType = TApplication.BackendType.XTERM; |
| 34 | if (System.getProperty("os.name").startsWith("Windows")) { |
| 35 | backendType = TApplication.BackendType.SWING; |
| 36 | } |
| 37 | |
| 38 | if (System.getProperty("os.name").startsWith("Mac")) { |
| 39 | backendType = TApplication.BackendType.SWING; |
| 40 | } |
| 41 | |
| 42 | if (System.getProperty("jexer.Swing") != null) { |
| 43 | if (System.getProperty("jexer.Swing", "false").equals("true")) { |
| 44 | backendType = TApplication.BackendType.SWING; |
| 45 | } else { |
| 46 | backendType = TApplication.BackendType.XTERM; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return backendType; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void read(boolean sync) throws IOException { |
| 55 | // TODO |
| 56 | if (!sync) { |
| 57 | // How could you do a not-sync in TUI mode? |
| 58 | throw new java.lang.IllegalStateException( |
| 59 | "Async mode not implemented yet."); |
| 60 | } |
| 61 | |
| 62 | try { |
| 63 | TuiReaderApplication app = new TuiReaderApplication(this, |
| 64 | guessBackendType()); |
| 65 | app.run(); |
| 66 | } catch (Exception e) { |
| 67 | Instance.getInstance().getTraceHandler().error(e); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void browse(String source) { |
| 73 | try { |
| 74 | TuiReaderApplication app = new TuiReaderApplication(this, source, |
| 75 | guessBackendType()); |
| 76 | app.run(); |
| 77 | } catch (Exception e) { |
| 78 | Instance.getInstance().getTraceHandler().error(e); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public void search(boolean sync) throws IOException { |
| 84 | // TODO |
| 85 | if (sync) { |
| 86 | throw new java.lang.IllegalStateException("Not implemented yet."); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public void search(SupportType searchOn, String keywords, int page, |
| 92 | int item, boolean sync) { |
| 93 | // TODO |
| 94 | if (sync) { |
| 95 | throw new java.lang.IllegalStateException("Not implemented yet."); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public void searchTag(SupportType searchOn, int page, int item, |
| 101 | boolean sync, Integer... tags) { |
| 102 | // TODO |
| 103 | if (sync) { |
| 104 | throw new java.lang.IllegalStateException("Not implemented yet."); |
| 105 | } |
| 106 | } |
| 107 | } |