import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-import java.util.LinkedList;
import jexer.TImage;
import jexer.bits.Cell;
import jexer.bits.CellAttributes;
import jexer.bits.Color;
+import jexer.event.TCommandEvent;
import jexer.event.TInputEvent;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import jexer.event.TResizeEvent;
+import static jexer.TCommand.*;
import static jexer.TKeypress.*;
/**
reloadOptions();
// Spin up the input reader
- eventQueue = new LinkedList<TInputEvent>();
+ eventQueue = new ArrayList<TInputEvent>();
readerThread = new Thread(this);
readerThread.start();
reloadOptions();
// Spin up the input reader
- eventQueue = new LinkedList<TInputEvent>();
+ eventQueue = new ArrayList<TInputEvent>();
readerThread = new Thread(this);
readerThread.start();
// available() will often return > 1, so we need to read in chunks to
// stay caught up.
char [] readBuffer = new char[128];
- List<TInputEvent> events = new LinkedList<TInputEvent>();
+ List<TInputEvent> events = new ArrayList<TInputEvent>();
while (!done && !stopReaderThread) {
try {
events.clear();
}
+ if (output.checkError()) {
+ // This is EOF.
+ done = true;
+ }
+
// Wait 20 millis for more data
Thread.sleep(20);
}
done = true;
}
} // while ((done == false) && (stopReaderThread == false))
+
+ // Pass an event up to TApplication to tell it this Backend is done.
+ synchronized (eventQueue) {
+ eventQueue.add(new TCommandEvent(cmBackendDisconnect));
+ }
+ if (listener != null) {
+ synchronized (listener) {
+ listener.notifyAll();
+ }
+ }
+
// System.err.println("*** run() exiting..."); System.err.flush();
}
int [] rgbArray;
for (int i = 0; i < cells.size() - 1; i++) {
- if (cells.get(i).isInvertedImage()) {
+ int tileWidth = Math.min(cells.get(i).getImage().getWidth(),
+ imageWidth);
+ int tileHeight = Math.min(cells.get(i).getImage().getHeight(),
+ imageHeight);
+ if (false && cells.get(i).isInvertedImage()) {
+ // I used to put an all-white cell over the cursor, don't do
+ // that anymore.
rgbArray = new int[imageWidth * imageHeight];
for (int j = 0; j < rgbArray.length; j++) {
rgbArray[j] = 0xFFFFFF;
}
} else {
- rgbArray = cells.get(i).getImage().getRGB(0, 0,
- imageWidth, imageHeight, null, 0, imageWidth);
+ try {
+ rgbArray = cells.get(i).getImage().getRGB(0, 0,
+ tileWidth, tileHeight, null, 0, tileWidth);
+ } catch (Exception e) {
+ throw new RuntimeException("image " + imageWidth + "x" +
+ imageHeight +
+ "tile " + tileWidth + "x" +
+ tileHeight +
+ " cells.get(i).getImage() " +
+ cells.get(i).getImage() +
+ " i " + i +
+ " fullWidth " + fullWidth +
+ " fullHeight " + fullHeight, e);
+ }
}
/*
fullWidth, fullHeight, cells.size(), getTextWidth());
*/
- image.setRGB(i * imageWidth, 0, imageWidth, imageHeight,
- rgbArray, 0, imageWidth);
- if (imageHeight < fullHeight) {
+ image.setRGB(i * imageWidth, 0, tileWidth, tileHeight,
+ rgbArray, 0, tileWidth);
+ if (tileHeight < fullHeight) {
int backgroundColor = cells.get(i).getBackground().getRGB();
for (int imageX = 0; imageX < image.getWidth(); imageX++) {
for (int imageY = imageHeight; imageY < fullHeight;
}
}
totalWidth -= ((cells.size() - 1) * imageWidth);
- if (cells.get(cells.size() - 1).isInvertedImage()) {
+ if (false && cells.get(cells.size() - 1).isInvertedImage()) {
+ // I used to put an all-white cell over the cursor, don't do that
+ // anymore.
rgbArray = new int[totalWidth * imageHeight];
for (int j = 0; j < rgbArray.length; j++) {
rgbArray[j] = 0xFFFFFF;
}
} else {
- rgbArray = cells.get(cells.size() - 1).getImage().getRGB(0, 0,
- totalWidth, imageHeight, null, 0, totalWidth);
+ try {
+ rgbArray = cells.get(cells.size() - 1).getImage().getRGB(0, 0,
+ totalWidth, imageHeight, null, 0, totalWidth);
+ } catch (Exception e) {
+ throw new RuntimeException("image " + imageWidth + "x" +
+ imageHeight + " cells.get(cells.size() - 1).getImage() " +
+ cells.get(cells.size() - 1).getImage(), e);
+ }
}
image.setRGB((cells.size() - 1) * imageWidth, 0, totalWidth,
imageHeight, rgbArray, 0, totalWidth);
// colored pixels, and select the color.
sb.append(String.format("$#%d", i));
+ int oldData = -1;
+ int oldDataCount = 0;
for (int imageX = 0; imageX < image.getWidth(); imageX++) {
// Add up all the pixels that match this color.
}
}
assert (data >= 0);
- assert (data < 127);
+ assert (data < 64);
data += 63;
- sb.append((char) data);
+
+ if (data == oldData) {
+ oldDataCount++;
+ } else {
+ if (oldDataCount == 1) {
+ sb.append((char) oldData);
+ } else if (oldDataCount > 1) {
+ sb.append(String.format("!%d", oldDataCount));
+ sb.append((char) oldData);
+ }
+ oldDataCount = 1;
+ oldData = data;
+ }
+
} // for (int imageX = 0; imageX < image.getWidth(); imageX++)
+
+ // Emit the last sequence.
+ if (oldDataCount == 1) {
+ sb.append((char) oldData);
+ } else if (oldDataCount > 1) {
+ sb.append(String.format("!%d", oldDataCount));
+ sb.append((char) oldData);
+ }
+
} // for (int i = 0; i < MAX_COLOR_REGISTERS; i++)
// Advance to the next scan line.
return (startSixel(x, y) + sb.toString() + endSixel());
}
+ /**
+ * Get the sixel support flag.
+ *
+ * @return true if this terminal is emitting sixel
+ */
+ public boolean hasSixel() {
+ return sixel;
+ }
+
// ------------------------------------------------------------------------
// End sixel output support -----------------------------------------------
// ------------------------------------------------------------------------