X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbackend%2FGenericBackend.java;h=ede3c0bff4365743f1d8c38d3c4b130f1cdc01f0;hb=12b90437b5f22c2ae6e9b9b14c3b62b60f6143e5;hp=908be1ef8c60400c5f3db36ef34bc62ef8b032b5;hpb=a69ed767c9c07cf35cf1c5f7821fc009cfe79cd2;p=nikiroo-utils.git diff --git a/src/jexer/backend/GenericBackend.java b/src/jexer/backend/GenericBackend.java index 908be1e..ede3c0b 100644 --- a/src/jexer/backend/GenericBackend.java +++ b/src/jexer/backend/GenericBackend.java @@ -31,6 +31,8 @@ package jexer.backend; import java.util.List; import jexer.event.TInputEvent; +import jexer.event.TCommandEvent; +import static jexer.TCommand.*; /** * This abstract class provides a screen, keyboard, and mouse to @@ -58,6 +60,16 @@ public abstract class GenericBackend implements Backend { */ protected TerminalReader terminal; + /** + * By default, GenericBackend adds a cmAbort after it sees + * cmBackendDisconnect, so that TApplication will exit when the user + * closes the Swing window or disconnects the ECMA48 streams. But + * MultiBackend wraps multiple Backends, and needs to decide when to send + * cmAbort differently. Setting this to false is how it manages that. + * Note package private access. + */ + boolean abortOnDisconnect = true; + // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ @@ -108,6 +120,18 @@ public abstract class GenericBackend implements Backend { public void getEvents(final List queue) { if (terminal.hasEvents()) { terminal.getEvents(queue); + + // This default backend assumes a single user, and if that user + // becomes disconnected we should terminate the application. + if ((queue.size() > 0) && (abortOnDisconnect == true)) { + TInputEvent event = queue.get(queue.size() - 1); + if (event instanceof TCommandEvent) { + TCommandEvent command = (TCommandEvent) event; + if (command.equals(cmBackendDisconnect)) { + queue.add(new TCommandEvent(cmAbort)); + } + } + } } } @@ -137,4 +161,11 @@ public abstract class GenericBackend implements Backend { terminal.setListener(listener); } + /** + * Reload backend options from System properties. + */ + public void reloadOptions() { + terminal.reloadOptions(); + } + }