git://git.nikiroo.be
/
fanfix.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
#35 CJK WIP
[fanfix.git]
/
src
/
jexer
/
backend
/
ECMA48Terminal.java
diff --git
a/src/jexer/backend/ECMA48Terminal.java
b/src/jexer/backend/ECMA48Terminal.java
index 518024c5d0099c07d22f5489cb7a69c1ba7a7106..e22e4fe91e277e1afd5abbeb0d6e83b917d4743f 100644
(file)
--- a/
src/jexer/backend/ECMA48Terminal.java
+++ b/
src/jexer/backend/ECMA48Terminal.java
@@
-44,16
+44,17
@@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
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.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 jexer.event.TInputEvent;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import jexer.event.TResizeEvent;
+import static jexer.TCommand.*;
import static jexer.TKeypress.*;
/**
import static jexer.TKeypress.*;
/**
@@
-85,6
+86,8
@@
public class ECMA48Terminal extends LogicalScreen
* 1024.
*/
private static final int MAX_COLOR_REGISTERS = 1024;
* 1024.
*/
private static final int MAX_COLOR_REGISTERS = 1024;
+ // Black-and-white is possible too.
+ // private static final int MAX_COLOR_REGISTERS = 2;
// ------------------------------------------------------------------------
// Variables --------------------------------------------------------------
// ------------------------------------------------------------------------
// Variables --------------------------------------------------------------
@@
-342,6
+345,16
@@
public class ECMA48Terminal extends LogicalScreen
int green = (color >>> 8) & 0xFF;
int blue = color & 0xFF;
int green = (color >>> 8) & 0xFF;
int blue = color & 0xFF;
+ if (MAX_COLOR_REGISTERS == 2) {
+ if (((red * red) + (green * green) + (blue * blue)) < 35568) {
+ // Black
+ return 0;
+ }
+ // White
+ return 1;
+ }
+
+
rgbToHsl(red, green, blue, hsl);
int hue = hsl[0];
int sat = hsl[1];
rgbToHsl(red, green, blue, hsl);
int hue = hsl[0];
int sat = hsl[1];
@@
-662,6
+675,14
@@
public class ECMA48Terminal extends LogicalScreen
// map the BufferedImage colors to their nearest neighbor in RGB
// space.
// map the BufferedImage colors to their nearest neighbor in RGB
// space.
+ if (MAX_COLOR_REGISTERS == 2) {
+ rgbColors.add(0);
+ rgbColors.add(0xFFFFFF);
+ rgbSortedIndex[0] = 0;
+ rgbSortedIndex[1] = 1;
+ return;
+ }
+
// We build a palette using the Hue-Saturation-Luminence model,
// with 5+ bits for Hue, 2+ bits for Saturation, and 1+ bit for
// Luminance. We convert these colors to 24-bit RGB, sort them
// We build a palette using the Hue-Saturation-Luminence model,
// with 5+ bits for Hue, 2+ bits for Saturation, and 1+ bit for
// Luminance. We convert these colors to 24-bit RGB, sort them
@@
-1087,7
+1108,7
@@
public class ECMA48Terminal extends LogicalScreen
reloadOptions();
// Spin up the input reader
reloadOptions();
// Spin up the input reader
- eventQueue = new
Linked
List<TInputEvent>();
+ eventQueue = new
Array
List<TInputEvent>();
readerThread = new Thread(this);
readerThread.start();
readerThread = new Thread(this);
readerThread.start();
@@
-1173,7
+1194,7
@@
public class ECMA48Terminal extends LogicalScreen
reloadOptions();
// Spin up the input reader
reloadOptions();
// Spin up the input reader
- eventQueue = new
Linked
List<TInputEvent>();
+ eventQueue = new
Array
List<TInputEvent>();
readerThread = new Thread(this);
readerThread.start();
readerThread = new Thread(this);
readerThread.start();
@@
-1370,7
+1391,7
@@
public class ECMA48Terminal extends LogicalScreen
// available() will often return > 1, so we need to read in chunks to
// stay caught up.
char [] readBuffer = new char[128];
// 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
Linked
List<TInputEvent>();
+ List<TInputEvent> events = new
Array
List<TInputEvent>();
while (!done && !stopReaderThread) {
try {
while (!done && !stopReaderThread) {
try {
@@
-1435,6
+1456,11
@@
public class ECMA48Terminal extends LogicalScreen
events.clear();
}
events.clear();
}
+ if (output.checkError()) {
+ // This is EOF.
+ done = true;
+ }
+
// Wait 20 millis for more data
Thread.sleep(20);
}
// Wait 20 millis for more data
Thread.sleep(20);
}
@@
-1446,6
+1472,17
@@
public class ECMA48Terminal extends LogicalScreen
done = true;
}
} // while ((done == false) && (stopReaderThread == false))
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();
}
// System.err.println("*** run() exiting..."); System.err.flush();
}
@@
-2814,7
+2851,9
@@
public class ECMA48Terminal extends LogicalScreen
int [] rgbArray;
for (int i = 0; i < cells.size() - 1; i++) {
int [] rgbArray;
for (int i = 0; i < cells.size() - 1; i++) {
- if (cells.get(i).isInvertedImage()) {
+ 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;
rgbArray = new int[imageWidth * imageHeight];
for (int j = 0; j < rgbArray.length; j++) {
rgbArray[j] = 0xFFFFFF;
@@
-2846,7
+2885,9
@@
public class ECMA48Terminal extends LogicalScreen
}
}
totalWidth -= ((cells.size() - 1) * imageWidth);
}
}
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;
rgbArray = new int[totalWidth * imageHeight];
for (int j = 0; j < rgbArray.length; j++) {
rgbArray[j] = 0xFFFFFF;
@@
-2921,6
+2962,8
@@
public class ECMA48Terminal extends LogicalScreen
// colored pixels, and select the color.
sb.append(String.format("$#%d", i));
// 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.
for (int imageX = 0; imageX < image.getWidth(); imageX++) {
// Add up all the pixels that match this color.
@@
-2953,10
+2996,32
@@
public class ECMA48Terminal extends LogicalScreen
}
}
assert (data >= 0);
}
}
assert (data >= 0);
- assert (data <
127
);
+ assert (data <
64
);
data += 63;
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++)
} // 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.
} // for (int i = 0; i < MAX_COLOR_REGISTERS; i++)
// Advance to the next scan line.
@@
-2975,6
+3040,15
@@
public class ECMA48Terminal extends LogicalScreen
return (startSixel(x, y) + sb.toString() + endSixel());
}
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 -----------------------------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// End sixel output support -----------------------------------------------
// ------------------------------------------------------------------------