X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fjexer%2Ftterminal%2FECMA48.java;fp=src%2Fjexer%2Ftterminal%2FECMA48.java;h=c6aa0b21e7f981ac5a66d7f65fa49ac7aec2e9f8;hp=369eca93005702b700d1ebc2c48ca4a77afa713e;hb=5ca5f8e5310b189232ed337643f3b7b2ce6cd3b1;hpb=8d3480c7b92b79c8e774261fd6a8fe719286cf67 diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index 369eca9..c6aa0b2 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -506,6 +506,11 @@ public class ECMA48 implements Runnable { */ private ArrayList userQueue = new ArrayList(); + /** + * Number of bytes/characters passed to consume(). + */ + private long readCount = 0; + /** * DECSC/DECRC save/restore a subset of the total state. This class * encapsulates those specific flags/modes. @@ -854,6 +859,34 @@ public class ECMA48 implements Runnable { // ECMA48 ----------------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * Wait for a period of time to get output from the launched process. + * + * @param millis millis to wait for, or 0 to wait forever + * @return true if the launched process has emitted something + */ + public boolean waitForOutput(final int millis) { + if (millis < 0) { + throw new IllegalArgumentException("timeout must be >= 0"); + } + int waitedMillis = millis; + final int pollTimeout = 5; + while (true) { + if (readCount != 0) { + return true; + } + if ((millis > 0) && (waitedMillis < 0)){ + return false; + } + try { + Thread.sleep(pollTimeout); + } catch (InterruptedException e) { + // SQUASH + } + waitedMillis -= pollTimeout; + } + } + /** * Process keyboard and mouse events from the user. * @@ -4971,6 +5004,7 @@ public class ECMA48 implements Runnable { * @param ch character from the remote side */ private void consume(final int ch) { + readCount++; // DEBUG // System.err.printf("%c STATE = %s\n", ch, scanState);