2 * Jexer - Java Text User Interface
6 * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a>
8 * License: LGPLv3 or later
10 * Copyright: This module is licensed under the GNU Lesser General
11 * Public License Version 3. Please see the file "COPYING" in this
12 * directory for more information about the GNU Lesser General Public
15 * Copyright (C) 2015 Kevin Lamonte
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public License
19 * as published by the Free Software Foundation; either version 3 of
20 * the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this program; if not, see
29 * http://www.gnu.org/licenses/, or write to the Free Software
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
33 package jexer
.backend
;
35 import java
.io
.InputStream
;
36 import java
.io
.OutputStream
;
37 import java
.io
.UnsupportedEncodingException
;
38 import java
.util
.List
;
40 import jexer
.event
.TInputEvent
;
41 import jexer
.io
.ECMA48Screen
;
42 import jexer
.io
.ECMA48Terminal
;
45 * This class uses an xterm/ANSI X3.64/ECMA-48 type terminal to provide a
46 * screen, keyboard, and mouse to TApplication.
48 public class ECMA48Backend
extends Backend
{
51 * Input events are processed by this Terminal.
53 private ECMA48Terminal terminal
;
58 * @param input an InputStream connected to the remote user, or null for
59 * System.in. If System.in is used, then on non-Windows systems it will
60 * be put in raw mode; shutdown() will (blindly!) put System.in in cooked
61 * mode. input is always converted to a Reader with UTF-8 encoding.
62 * @param output an OutputStream connected to the remote user, or null
63 * for System.out. output is always converted to a Writer with UTF-8
66 public ECMA48Backend(InputStream input
, OutputStream output
) throws UnsupportedEncodingException
{
68 // Create a terminal and explicitly set stdin into raw mode
69 terminal
= new ECMA48Terminal(input
, output
);
72 screen
= new ECMA48Screen(terminal
);
75 terminal
.getOutput().write(terminal
.clearAll());
80 * Sync the logical screen to the physical device.
83 public void flushScreen() {
84 screen
.flushPhysical();
88 * Get keyboard, mouse, and screen resize events.
90 * @param timeout maximum amount of time (in millis) to wait for an
91 * event. 0 means to return immediately, i.e. perform a poll.
92 * @return events received, or an empty list if the timeout was reached
96 public List
<TInputEvent
> getEvents(int timeout
) {
97 return terminal
.getEvents();
101 * Subclasses must provide an implementation that closes sockets,
102 * restores console, etc.
105 public void shutdown() {