import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.Date;
TApplicationImpl();
}
+ /**
+ * Public constructor. The backend type will be BackendType.ECMA48.
+ *
+ * @param input the InputStream underlying 'reader'. Its available()
+ * method is used to determine if reader.read() will block or not.
+ * @param reader a Reader connected to the remote user.
+ * @param writer a PrintWriter connected to the remote user.
+ * @param setRawMode if true, set System.in into raw mode with stty.
+ * This should in general not be used. It is here solely for Demo3,
+ * which uses System.in.
+ * @throws IllegalArgumentException if input, reader, or writer are null.
+ */
+ public TApplication(final InputStream input, final Reader reader,
+ final PrintWriter writer, final boolean setRawMode) {
+
+ backend = new ECMA48Backend(this, input, reader, writer, setRawMode);
+ TApplicationImpl();
+ }
+
+ /**
+ * Public constructor. The backend type will be BackendType.ECMA48.
+ *
+ * @param input the InputStream underlying 'reader'. Its available()
+ * method is used to determine if reader.read() will block or not.
+ * @param reader a Reader connected to the remote user.
+ * @param writer a PrintWriter connected to the remote user.
+ * @throws IllegalArgumentException if input, reader, or writer are null.
+ */
+ public TApplication(final InputStream input, final Reader reader,
+ final PrintWriter writer) {
+
+ this(input, reader, writer, false);
+ }
+
/**
* Public constructor. This hook enables use with new non-Jexer
* backends.
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.List;
terminal.flush();
}
+ /**
+ * Public constructor.
+ *
+ * @param listener the object this backend needs to wake up when new
+ * input comes in
+ * @param input the InputStream underlying 'reader'. Its available()
+ * method is used to determine if reader.read() will block or not.
+ * @param reader a Reader connected to the remote user.
+ * @param writer a PrintWriter connected to the remote user.
+ * @param setRawMode if true, set System.in into raw mode with stty.
+ * This should in general not be used. It is here solely for Demo3,
+ * which uses System.in.
+ * @throws IllegalArgumentException if input, reader, or writer are null.
+ */
+ public ECMA48Backend(final Object listener, final InputStream input,
+ final Reader reader, final PrintWriter writer,
+ final boolean setRawMode) {
+
+ // Create a terminal and explicitly set stdin into raw mode
+ terminal = new ECMA48Terminal(listener, input, reader, writer,
+ setRawMode);
+
+ // Keep the terminal's sessionInfo so that TApplication can see it
+ sessionInfo = terminal.getSessionInfo();
+
+ // Create a screen
+ screen = new ECMA48Screen(terminal);
+
+ // Clear the screen
+ terminal.getOutput().write(terminal.clearAll());
+ terminal.flush();
+ }
+
+ /**
+ * Public constructor.
+ *
+ * @param listener the object this backend needs to wake up when new
+ * input comes in
+ * @param input the InputStream underlying 'reader'. Its available()
+ * method is used to determine if reader.read() will block or not.
+ * @param reader a Reader connected to the remote user.
+ * @param writer a PrintWriter connected to the remote user.
+ * @throws IllegalArgumentException if input, reader, or writer are null.
+ */
+ public ECMA48Backend(final Object listener, final InputStream input,
+ final Reader reader, final PrintWriter writer) {
+
+ this(listener, input, reader, writer, false);
+ }
+
/**
* Sync the logical screen to the physical device.
*/
--- /dev/null
+/*
+ * Jexer - Java Text User Interface
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (C) 2016 Kevin Lamonte
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * @author Kevin Lamonte [kevin.lamonte@gmail.com]
+ * @version 1
+ */
+package jexer.demos;
+
+import java.io.*;
+
+/**
+ * This class is the main driver for a simple demonstration of Jexer's
+ * capabilities. This one passes separate Reader/Writer to TApplication,
+ * which will behave quite badly due to System.in/out not being in raw mode.
+ */
+public class Demo3 {
+
+ /**
+ * Main entry point.
+ *
+ * @param args Command line arguments
+ */
+ public static void main(final String [] args) {
+ try {
+ if (args.length == 0) {
+ System.err.printf("USAGE: java -cp jexer.jar jexer.demos.Demo3\n");
+ return;
+ }
+ DemoApplication app = new DemoApplication(System.in,
+ new InputStreamReader(System.in, "UTF-8"),
+ new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")),
+ true);
+ (new Thread(app)).start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
addAllWidgets();
}
+ /**
+ * Public constructor.
+ *
+ * @param input the InputStream underlying 'reader'. Its available()
+ * method is used to determine if reader.read() will block or not.
+ * @param reader a Reader connected to the remote user.
+ * @param writer a PrintWriter connected to the remote user.
+ * @param setRawMode if true, set System.in into raw mode with stty.
+ * This should in general not be used. It is here solely for Demo3,
+ * which uses System.in.
+ * @throws IllegalArgumentException if input, reader, or writer are null.
+ */
+ public DemoApplication(final InputStream input, final Reader reader,
+ final PrintWriter writer, final boolean setRawMode) {
+ super(input, reader, writer, setRawMode);
+ addAllWidgets();
+ }
+
+ /**
+ * Public constructor.
+ *
+ * @param input the InputStream underlying 'reader'. Its available()
+ * method is used to determine if reader.read() will block or not.
+ * @param reader a Reader connected to the remote user.
+ * @param writer a PrintWriter connected to the remote user.
+ * @throws IllegalArgumentException if input, reader, or writer are null.
+ */
+ public DemoApplication(final InputStream input, final Reader reader,
+ final PrintWriter writer) {
+
+ this(input, reader, writer, false);
+ }
+
/**
* Handle menu events.
*
readerThread.start();
}
+ /**
+ * Constructor sets up state for getEvent().
+ *
+ * @param listener the object this backend needs to wake up when new
+ * input comes in
+ * @param input the InputStream underlying 'reader'. Its available()
+ * method is used to determine if reader.read() will block or not.
+ * @param reader a Reader connected to the remote user.
+ * @param writer a PrintWriter connected to the remote user.
+ * @param setRawMode if true, set System.in into raw mode with stty.
+ * This should in general not be used. It is here solely for Demo3,
+ * which uses System.in.
+ * @throws IllegalArgumentException if input, reader, or writer are null.
+ */
+ public ECMA48Terminal(final Object listener, final InputStream input,
+ final Reader reader, final PrintWriter writer,
+ final boolean setRawMode) {
+
+ if (input == null) {
+ throw new IllegalArgumentException("InputStream must be specified");
+ }
+ if (reader == null) {
+ throw new IllegalArgumentException("Reader must be specified");
+ }
+ if (writer == null) {
+ throw new IllegalArgumentException("Writer must be specified");
+ }
+ reset();
+ mouse1 = false;
+ mouse2 = false;
+ mouse3 = false;
+ stopReaderThread = false;
+ this.listener = listener;
+
+ inputStream = input;
+ this.input = reader;
+
+ if (setRawMode == true) {
+ sttyRaw();
+ }
+ this.setRawMode = setRawMode;
+
+ if (input instanceof SessionInfo) {
+ // This is a TelnetInputStream that exposes window size and
+ // environment variables from the telnet layer.
+ sessionInfo = (SessionInfo) input;
+ }
+ if (sessionInfo == null) {
+ sessionInfo = new TSessionInfo();
+ }
+
+ this.output = writer;
+
+ // Enable mouse reporting and metaSendsEscape
+ this.output.printf("%s%s", mouse(true), xtermMetaSendsEscape(true));
+ this.output.flush();
+
+ // Hang onto the window size
+ windowResize = new TResizeEvent(TResizeEvent.Type.SCREEN,
+ sessionInfo.getWindowWidth(), sessionInfo.getWindowHeight());
+
+ // Spin up the input reader
+ eventQueue = new LinkedList<TInputEvent>();
+ readerThread = new Thread(this);
+ readerThread.start();
+ }
+
+ /**
+ * Constructor sets up state for getEvent().
+ *
+ * @param listener the object this backend needs to wake up when new
+ * input comes in
+ * @param input the InputStream underlying 'reader'. Its available()
+ * method is used to determine if reader.read() will block or not.
+ * @param reader a Reader connected to the remote user.
+ * @param writer a PrintWriter connected to the remote user.
+ * @throws IllegalArgumentException if input, reader, or writer are null.
+ */
+ public ECMA48Terminal(final Object listener, final InputStream input,
+ final Reader reader, final PrintWriter writer) {
+
+ this(listener, input, reader, writer, false);
+ }
+
/**
* Restore terminal to normal state.
*/