*/
package jexer.tterminal;
-import java.awt.Graphics2D;
+import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
/**
* The maximum number of lines in the scrollback buffer.
*/
- private int maxScrollback = 10000;
+ private int scrollbackMax = 10000;
/**
* The terminal's input. For type == XTERM, this is an InputStreamReader
*/
private ArrayList<TInputEvent> userQueue = new ArrayList<TInputEvent>();
+ /**
+ * 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.
// 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.
*
display.add(line);
}
while (display.size() > height) {
- scrollback.add(display.remove(0));
+ appendScrollbackLine(display.remove(0));
}
}
+ /**
+ * Get the maximum number of lines in the scrollback buffer.
+ *
+ * @return the maximum number of lines in the scrollback buffer
+ */
+ public int getScrollbackMax() {
+ return scrollbackMax;
+ }
+
+ /**
+ * Set the maximum number of lines for the scrollback buffer.
+ *
+ * @param scrollbackMax the maximum number of lines for the scrollback
+ * buffer
+ */
+ public final void setScrollbackMax(final int scrollbackMax) {
+ this.scrollbackMax = scrollbackMax;
+ }
+
/**
* Get visible cursor flag.
*
toGround();
}
+ /**
+ * Append a to the scrollback buffer, clearing image data for lines more
+ * than three screenfuls in.
+ */
+ private void appendScrollbackLine(DisplayLine line) {
+ scrollback.add(line);
+ if (scrollback.size() > height * 3) {
+ scrollback.get(scrollback.size() - (height * 3)).clearImages();
+ }
+ }
+
/**
* Append a new line to the bottom of the display, adding lines off the
* top to the scrollback buffer.
*/
private void newDisplayLine() {
// Scroll the top line off into the scrollback buffer
- scrollback.add(display.get(0));
- if (scrollback.size() > maxScrollback) {
+ appendScrollbackLine(display.get(0));
+ while (scrollback.size() > scrollbackMax) {
scrollback.remove(0);
scrollback.trimToSize();
}
* @param ch character from the remote side
*/
private void consume(final int ch) {
+ readCount++;
// DEBUG
// System.err.printf("%c STATE = %s\n", ch, scanState);
}
Cell cell = new Cell();
- cell.setImage(image.getSubimage(x * textWidth,
- y * textHeight, width, height));
+ if ((width != textWidth) || (height != textHeight)) {
+ BufferedImage newImage;
+ newImage = new BufferedImage(textWidth, textHeight,
+ BufferedImage.TYPE_INT_ARGB);
+
+ Graphics gr = newImage.getGraphics();
+ gr.drawImage(image.getSubimage(x * textWidth,
+ y * textHeight, width, height),
+ 0, 0, null, null);
+ gr.dispose();
+ cell.setImage(newImage);
+ } else {
+ cell.setImage(image.getSubimage(x * textWidth,
+ y * textHeight, width, height));
+ }
cells[x][y] = cell;
}