From 5ca5f8e5310b189232ed337643f3b7b2ce6cd3b1 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Sun, 10 Nov 2019 17:10:54 -0600 Subject: [PATCH] lint --- build.xml | 2 ++ src/jexer/TTerminalWidget.java | 13 ++++++++++++ src/jexer/TTerminalWindow.java | 15 ++++++++++++- src/jexer/bits/Cell.java | 2 +- src/jexer/teditor/Highlighter.java | 2 +- src/jexer/tterminal/ECMA48.java | 34 ++++++++++++++++++++++++++++++ src/jexer/tterminal/Sixel.java | 4 ++-- 7 files changed, 67 insertions(+), 5 deletions(-) diff --git a/build.xml b/build.xml index 327793a..2e86167 100644 --- a/build.xml +++ b/build.xml @@ -52,6 +52,8 @@ target="1.6" source="1.6" > + + diff --git a/src/jexer/TTerminalWidget.java b/src/jexer/TTerminalWidget.java index acd1cc2..f488320 100644 --- a/src/jexer/TTerminalWidget.java +++ b/src/jexer/TTerminalWidget.java @@ -999,6 +999,19 @@ public class TTerminalWidget extends TScrollableWidget } // synchronized (emulator) } + /** + * 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 (emulator == null) { + return false; + } + return emulator.waitForOutput(millis); + } + /** * Check if a mouse press/release/motion event coordinate is over the * emulator. diff --git a/src/jexer/TTerminalWindow.java b/src/jexer/TTerminalWindow.java index e96c50c..bb3e14a 100644 --- a/src/jexer/TTerminalWindow.java +++ b/src/jexer/TTerminalWindow.java @@ -166,7 +166,7 @@ public class TTerminalWindow extends TScrollableWindow { newStatusBar(i18n.getString("statusBarRunning")); // Spin it up - terminal = new TTerminalWidget(this, 0, 0, new TAction() { + terminal = new TTerminalWidget(this, 0, 0, command, new TAction() { public void DO() { onShellExit(); } @@ -452,4 +452,17 @@ public class TTerminalWindow extends TScrollableWindow { getApplication().postEvent(new TMenuEvent(TMenu.MID_REPAINT)); } + /** + * 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 (terminal == null) { + return false; + } + return terminal.waitForOutput(millis); + } + } diff --git a/src/jexer/bits/Cell.java b/src/jexer/bits/Cell.java index a8efa2b..ed3c202 100644 --- a/src/jexer/bits/Cell.java +++ b/src/jexer/bits/Cell.java @@ -419,7 +419,7 @@ public final class Cell extends CellAttributes { int B = 23; int hash = A; hash = (B * hash) + super.hashCode(); - hash = (B * hash) + (int)ch; + hash = (B * hash) + ch; hash = (B * hash) + width.hashCode(); if (image != null) { /* diff --git a/src/jexer/teditor/Highlighter.java b/src/jexer/teditor/Highlighter.java index a484194..44a2ed0 100644 --- a/src/jexer/teditor/Highlighter.java +++ b/src/jexer/teditor/Highlighter.java @@ -87,7 +87,7 @@ public class Highlighter { * @return color associated with name, e.g. bold yellow on blue */ public CellAttributes getColor(final String name) { - CellAttributes attr = (CellAttributes) colors.get(name); + CellAttributes attr = colors.get(name); return attr; } 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); diff --git a/src/jexer/tterminal/Sixel.java b/src/jexer/tterminal/Sixel.java index a4c00fc..5768a0f 100644 --- a/src/jexer/tterminal/Sixel.java +++ b/src/jexer/tterminal/Sixel.java @@ -574,10 +574,10 @@ public class Sixel { case REPEAT: if ((ch >= '0') && (ch <= '9')) { if (repeatCount == -1) { - repeatCount = (int) (ch - '0'); + repeatCount = (ch - '0'); } else { repeatCount *= 10; - repeatCount += (int) (ch - '0'); + repeatCount += (ch - '0'); } } return; -- 2.27.0