summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmadeusz Sławiński <amade@asmblr.net>2017-07-07 18:39:34 +0200
committerAmadeusz Sławiński <amade@asmblr.net>2017-07-09 23:50:32 +0200
commit86ce25b620c52c9bdea94bf1185a274466f69b80 (patch)
treeb0a2334081f78dc0774189b8941f29971447ffd2
parente1dd1c2fe9339c57f743e41032d379c85c1c3388 (diff)
separate handling of 16 color and 256 color escapes
on xterm echo -e "\e[38;5;1mtest\e[1mtest" puts both 'test' strings in same color, however in screen, second one is bright do note that defbce on, may interfere with this Bug: 50601 Signed-off-by: Amadeusz Sławiński <amade@asmblr.net>
-rw-r--r--src/ansi.c8
-rw-r--r--src/display.c54
-rw-r--r--src/process.c8
3 files changed, 43 insertions, 27 deletions
diff --git a/src/ansi.c b/src/ansi.c
index 4e958fa..c0ce6b6 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -1708,9 +1708,9 @@ static void SelectRendition(Window *win)
if (jj < 0 || jj > 255)
continue;
if (j == 38) {
- colorfg = jj | 0x01000000;
+ colorfg = jj | 0x02000000;
} else {
- colorbg = jj | 0x01000000;
+ colorbg = jj | 0x02000000;
}
continue;
}
@@ -1724,9 +1724,9 @@ static void SelectRendition(Window *win)
b = win->w_args[i + 4];
if (j == 38) {
- colorfg = 0x02000000 | (r << 16) | (g << 8) | b;
+ colorfg = 0x04000000 | (r << 16) | (g << 8) | b;
} else {
- colorbg = 0x02000000 | (r << 16) | (g << 8) | b;
+ colorbg = 0x04000000 | (r << 16) | (g << 8) | b;
}
i += 4;
continue;
diff --git a/src/display.c b/src/display.c
index 15a313c..5a8d08b 100644
--- a/src/display.c
+++ b/src/display.c
@@ -1245,8 +1245,9 @@ int color256to88(int color)
* SetColor - Sets foreground and background color
* 0x00000000 <- default color ("transparent")
* one note here that "null" variable is pointer to array of 0 and that's one of reasons to use it this way
- * 0x010000xx <- 256 color
- * 0x02xxxxxx <- truecolor
+ * 0x0100000x <- 16 base color
+ * 0x020000xx <- 256 color
+ * 0x04xxxxxx <- truecolor
*/
void SetColor(uint32_t foreground, uint32_t background)
{
@@ -1289,14 +1290,7 @@ void SetColor(uint32_t foreground, uint32_t background)
AddCStr("\033[39m"); /* works because AX is set */
}
if (f != of && (f & 0x01000000)) {
- f &= 0x0ff;
- if (f > 15 && D_CCO != 256) {
- f = D_CCO == 88 && D_CAF ? color256to88(f) : color256to16(f);
- of = f;
- }
- if (f > 15 && D_CAF) {
- AddCStr2(D_CAF, f);
- }
+ f &= 0x0f;
if (f < 8) {
if (D_CAF)
AddCStr2(D_CAF, f);
@@ -1307,7 +1301,21 @@ void SetColor(uint32_t foreground, uint32_t background)
AddCStr2("\033[9%p1%dm", f & 7);
}
}
- if (f != of && (f & 0x02000000) && hastruecolor) {
+ if (f != of && (f & 0x02000000)) {
+ f &= 0x0ff;
+ if (f > 15 && D_CCO != 256) {
+ f = D_CCO == 88 && D_CAF ? color256to88(f) : color256to16(f);
+ }
+ if (D_CAF) {
+ //AddCStr2(D_CAF, f);
+ FILE *F = fopen("/tmp/debug", "a+");
+ fprintf(F, "%s\n", D_CAF);
+ fclose(F);
+ tputs(tparm("\033[38;5;%dm", f), 1, DoAddChar);
+ }
+
+ }
+ if (f != of && (f & 0x04000000) && hastruecolor) {
uint8_t _r, _g, _b;
_r = (f & 0x00ff0000) >> 16;
@@ -1323,14 +1331,7 @@ void SetColor(uint32_t foreground, uint32_t background)
AddCStr("\033[49m"); /* works because AX is set */
}
if (b != ob && (b & 0x01000000)) {
- b &= 0x0ff;
- if (b > 15 && D_CCO != 256) {
- b = D_CCO == 88 && D_CAB ? color256to88(b) : color256to16(b);
- ob = b;
- }
- if (b > 15 && D_CAB) {
- AddCStr2(D_CAB, b);
- }
+ b &= 0x0f;
if (b < 8) {
if (D_CAB)
AddCStr2(D_CAB, b);
@@ -1341,7 +1342,20 @@ void SetColor(uint32_t foreground, uint32_t background)
AddCStr2("\033[10%p1%dm", b & 7);
}
}
- if (b != ob && (b & 0x02000000) && hastruecolor) {
+ if (b != ob && (b & 0x02000000)) {
+ b &= 0x0ff;
+ if (b > 15 && D_CCO != 256) {
+ b = D_CCO == 88 && D_CAB ? color256to88(b) : color256to16(b);
+ }
+ if (D_CAB) {
+ // AddCStr2(D_CAB, b);
+ FILE *F = fopen("/tmp/debug", "a+");
+ fprintf(F, "%s\n", D_CAB);
+ fclose(F);
+ tputs(tparm("\033[48;5;%dm", b), 1, DoAddChar);
+ }
+ }
+ if (b != ob && (b & 0x04000000) && hastruecolor) {
uint8_t _r, _g, _b;
_r = (b & 0x00ff0000) >> 16;
diff --git a/src/process.c b/src/process.c
index 4592dd6..25ec6ec 100644
--- a/src/process.c
+++ b/src/process.c
@@ -5746,7 +5746,7 @@ uint64_t ParseAttrColor(char *str, int msgok)
*cm = 0;
break;
case 'x':
- *cm = 2;
+ *cm = 4;
case '0':
case '1':
case '2':
@@ -5757,7 +5757,7 @@ uint64_t ParseAttrColor(char *str, int msgok)
case '7':
case '8':
case '9':
- if (!*cm) *cm = 1;
+ if (!*cm) *cm = 2;
*cl = *cl * 10 + (*str - '0');
break;
case ';':
@@ -5798,7 +5798,7 @@ uint64_t ParseAttrColor(char *str, int msgok)
* xx 00 00 00 00 00 00 00 - attr
* 00 x0 00 00 00 00 00 00 - what kind of background
* 00 0x 00 00 00 00 00 00 - what kind of foreground
- * 0 - default, 1 - 256, 2 - truecolor
+ * 0 - default, 1 - base 16; 2 - 256, 4 - truecolor
* 00 00 xx xx xx 00 00 00 - background
* 00 00 00 00 00 xx xx xx - foreground
* mc -structure to modify
@@ -5813,8 +5813,10 @@ void ApplyAttrColor(uint64_t i, struct mchar *mc)
h = (0x00FF000000000000 & i) >> 48;
+ if (h & 0x40) b |= 0x04000000;
if (h & 0x20) b |= 0x02000000;
if (h & 0x10) b |= 0x01000000;
+ if (h & 0x04) f |= 0x04000000;
if (h & 0x02) f |= 0x02000000;
if (h & 0x01) f |= 0x01000000;