X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbackend%2FECMA48Terminal.java;h=92758ee6a65e096072af59d53c5bca973f8469c0;hb=eb0d6c82905932e04acfb4066ab680ef867931ce;hp=0cbd4f0502f9ca96a73136b4f1d995efa219a682;hpb=9696a8f6da9a0d204740420d6d8571176ab81944;p=nikiroo-utils.git diff --git a/src/jexer/backend/ECMA48Terminal.java b/src/jexer/backend/ECMA48Terminal.java index 0cbd4f0..92758ee 100644 --- a/src/jexer/backend/ECMA48Terminal.java +++ b/src/jexer/backend/ECMA48Terminal.java @@ -45,7 +45,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.LinkedList; -import java.util.Map; import jexer.TImage; import jexer.bits.Cell; @@ -86,6 +85,8 @@ public class ECMA48Terminal extends LogicalScreen * 1024. */ private static final int MAX_COLOR_REGISTERS = 1024; + // Black-and-white is possible too. + // private static final int MAX_COLOR_REGISTERS = 2; // ------------------------------------------------------------------------ // Variables -------------------------------------------------------------- @@ -343,6 +344,16 @@ public class ECMA48Terminal extends LogicalScreen 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]; @@ -663,6 +674,14 @@ public class ECMA48Terminal extends LogicalScreen // 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 @@ -1436,6 +1455,11 @@ public class ECMA48Terminal extends LogicalScreen events.clear(); } + if (output.checkError()) { + // This is EOF. + done = true; + } + // Wait 20 millis for more data Thread.sleep(20); } @@ -1447,7 +1471,11 @@ public class ECMA48Terminal extends LogicalScreen done = true; } } // while ((done == false) && (stopReaderThread == false)) - // System.err.println("*** run() exiting..."); System.err.flush(); + + // TODO: pass an event up to TApplication to tell it this Backend is + // done. + + System.err.println("*** run() exiting..."); System.err.flush(); } // ------------------------------------------------------------------------