summaryrefslogtreecommitdiff
path: root/src/fe-text
diff options
context:
space:
mode:
authorAilin Nemui <ailin@esf51.localdomain>2014-01-09 15:20:29 +0100
committerAilin Nemui <ailin@esf51.localdomain>2014-06-30 02:41:34 +0200
commit96a292d40e7f6fe505c4a0f686d35132ffac8208 (patch)
tree6f101c12381cbf47b19ce85499a81435a1d9f4f6 /src/fe-text
parent2d4edc51877719c49d712271967313310f4796fb (diff)
downloadirssi-96a292d40e7f6fe505c4a0f686d35132ffac8208.zip
Finish 256 colour support for Irssi
256 colour patch is cleaned up and the remaining cases are made work, this includes especially Theme support, which was not implemented before. Changes not related to colours were reverted again, making a review of the two patches against master easier to follow. As a byproduct of the Hex-colour code parser, the 24bit colours are also implemented. Actually using them in the terminal is guarded by a compile time switch (as well as a run time switch), as it breaks the existing colour protocol and requires additional storage. To make a seamless usage, down-conversion is provided for 8 and 16 colours. Diverging from Tom's approach, the colour protocol is reverted back to the original one. Unfortunately, the changes required in the Theme engine will break the API. For more details, please refer to the patch documentation at either http://irssi-docs.wikispaces.com/Notes-256-Colour or https://github.com/shabble/irssi-docs/wiki/Notes-256-Colour
Diffstat (limited to 'src/fe-text')
-rw-r--r--src/fe-text/gui-printtext.c88
-rw-r--r--src/fe-text/statusbar.c4
-rw-r--r--src/fe-text/term-curses.c21
-rw-r--r--src/fe-text/term-terminfo.c135
-rw-r--r--src/fe-text/term.c34
-rw-r--r--src/fe-text/term.h26
-rw-r--r--src/fe-text/terminfo-core.c31
-rw-r--r--src/fe-text/terminfo-core.h2
-rw-r--r--src/fe-text/textbuffer-view.c147
-rw-r--r--src/fe-text/textbuffer-view.h3
-rw-r--r--src/fe-text/textbuffer.c153
-rw-r--r--src/fe-text/textbuffer.h33
12 files changed, 373 insertions, 304 deletions
diff --git a/src/fe-text/gui-printtext.c b/src/fe-text/gui-printtext.c
index 556fae1b..380ca114 100644
--- a/src/fe-text/gui-printtext.c
+++ b/src/fe-text/gui-printtext.c
@@ -29,7 +29,14 @@
#include "gui-printtext.h"
#include "gui-windows.h"
-int mirc_colors[] = { 15, 0, 1, 2, 12, 4, 5, 6, 14, 10, 3, 11, 9, 13, 8, 7 };
+int mirc_colors[] = { 15, 0, 1, 2, 12, 4, 5, 6, 14, 10, 3, 11, 9, 13, 8, 7,
+ /* 16-27 */ 52, 94, 100, 58, 22, 29, 23, 24, 17, 54, 53, 89,
+ /* 28-39 */ 88, 130, 142, 64, 28, 35, 30, 25, 18, 91, 90, 125,
+ /* 40-51 */ 124, 166, 184, 106, 34, 49, 37, 33, 19, 129, 127, 161,
+ /* 52-63 */ 196, 208, 226, 154, 46, 86, 51, 75, 21, 171, 201, 198,
+ /* 64-75 */ 203, 215, 227, 191, 83, 122, 87, 111, 63, 177, 207, 205,
+ /* 76-87 */ 217, 223, 229, 193, 157, 158, 159, 153, 147, 183, 219, 212,
+ /* 88-98 */ 16, 233, 235, 237, 239, 241, 244, 247, 250, 254, 231, -1 };
static int scrollback_lines, scrollback_time, scrollback_burst_remove;
static int next_xpos, next_ypos;
@@ -145,44 +152,43 @@ static void remove_old_lines(TEXT_BUFFER_VIEW_REC *view)
static void get_colors(int flags, int *fg, int *bg, int *attr)
{
+ *attr = 0;
if (flags & GUI_PRINT_FLAG_MIRC_COLOR) {
- g_message( "getcolor: handling mirc colors\n");
-
- /* mirc colors - real range is 0..15, but after 16
- colors wrap to 0, 1, ... */
- if (*bg >= 0) *bg = mirc_colors[*bg % 16];
- if (*fg >= 0) *fg = mirc_colors[*fg % 16];
- /* TODO: What to do here? */
- if (settings_get_bool("mirc_blink_fix"))
- *bg &= ~0x08;
+ /* mirc colors - extended colours proposal */
+ if (*bg >= 0) {
+ *bg = mirc_colors[*bg % 100];
+ flags &= ~GUI_PRINT_FLAG_COLOR_24_BG;
+ if (settings_get_bool("mirc_blink_fix"))
+ *bg = term_color256map[*bg&0xff] & ~0x08;
+ }
+ if (*fg >= 0) {
+ *fg = mirc_colors[*fg % 100];
+ flags &= ~GUI_PRINT_FLAG_COLOR_24_FG;
+ }
}
- if (*fg < 0 || *fg > 255) {
- g_message( "getcolor: fg %d outside range, setting to -1\n", *fg);
+ if (flags & GUI_PRINT_FLAG_COLOR_24_FG)
+ *attr |= ATTR_FGCOLOR24;
+ else if (*fg < 0 || *fg > 255) {
*fg = -1;
+ *attr |= ATTR_RESETFG;
}
- if (*bg < 0 || *bg > 255) {
- g_message( "getcolor: bf %d outside range, setting to -1\n", *bg);
+ else
+ *attr |= *fg;
+
+ if (flags & GUI_PRINT_FLAG_COLOR_24_BG)
+ *attr |= ATTR_BGCOLOR24;
+ else if (*bg < 0 || *bg > 255) {
*bg = -1;
+ *attr |= ATTR_RESETBG;
}
+ else
+ *attr |= (*bg << BG_SHIFT);
- *attr = 0;
- if (flags & GUI_PRINT_FLAG_REVERSE) {
- *attr |= ATTR_REVERSE;
- g_message( "getcolor: setting flag_reverse\n");
- }
- if (flags & GUI_PRINT_FLAG_BOLD) {
- *attr |= ATTR_BOLD;
- g_message( "getcolor: setting flag_bold\n");
- }
- if (flags & GUI_PRINT_FLAG_UNDERLINE) {
- *attr |= ATTR_UNDERLINE;
- g_message( "getcolor: setting flag_underline\n");
- }
- if (flags & GUI_PRINT_FLAG_BLINK) {
- *attr |= ATTR_BLINK;
- g_message( "getcolor: setting flag_blink\n");
- }
+ if (flags & GUI_PRINT_FLAG_REVERSE) *attr |= ATTR_REVERSE;
+ if (flags & GUI_PRINT_FLAG_BOLD) *attr |= ATTR_BOLD;
+ if (flags & GUI_PRINT_FLAG_UNDERLINE) *attr |= ATTR_UNDERLINE;
+ if (flags & GUI_PRINT_FLAG_BLINK) *attr |= ATTR_BLINK;
}
static void view_add_eol(TEXT_BUFFER_VIEW_REC *view, LINE_REC **line)
@@ -203,33 +209,15 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
LINE_INFO_REC lineinfo;
int fg, bg, flags, attr;
- attr = 0;
-
flags = GPOINTER_TO_INT(pflags);
fg = GPOINTER_TO_INT(fgcolor);
bg = GPOINTER_TO_INT(bgcolor);
-
- g_message( "SGPT str: '%s'\n", str);
-
-
- g_message( "SGPT start: fg: %d (%02x), bg: %d (%02x) attr: %d (%04x), flags: %d (0x%04x)\n",
- fg, fg, bg, bg, attr, attr, flags, flags);
-
get_colors(flags, &fg, &bg, &attr);
- g_message( "SGPT getcol: fg: %d (%02x), bg: %d (%02x) attr: %d (%04x)\n",
- fg, fg, (bg << 8), (bg << 8), attr, attr);
-
if (window == NULL) {
g_return_if_fail(next_xpos != -1);
- attr |= fg >= 0 ? fg : ATTR_RESETFG;
- attr |= bg >= 0 ? (bg << 8) : ATTR_RESETBG;
- g_message(
- "SGPT nowin: fg: %d (%02x), bg: %d (%02x) attr: %d (%04x)\n",
- fg, fg, (bg << 8), (bg << 8), attr, attr);
-
- term_set_color(root_window, attr);
+ term_set_color2(root_window, attr, fg, bg);
term_move(root_window, next_xpos, next_ypos);
if (flags & GUI_PRINT_FLAG_CLRTOEOL)
diff --git a/src/fe-text/statusbar.c b/src/fe-text/statusbar.c
index 68724293..5453c2d5 100644
--- a/src/fe-text/statusbar.c
+++ b/src/fe-text/statusbar.c
@@ -670,6 +670,8 @@ void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only,
SERVER_REC *server;
WI_ITEM_REC *wiitem;
char *tmpstr, *tmpstr2;
+ theme_rm_col reset;
+ strcpy(reset.m, "n");
int len;
if (str == NULL)
@@ -690,7 +692,7 @@ void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only,
/* expand templates */
tmpstr = theme_format_expand_data(current_theme, &str,
- 'n', 'n',
+ reset, reset,
NULL, NULL,
EXPAND_FLAG_ROOT |
EXPAND_FLAG_IGNORE_REPLACES |
diff --git a/src/fe-text/term-curses.c b/src/fe-text/term-curses.c
index fc674fd3..f1ee3131 100644
--- a/src/fe-text/term-curses.c
+++ b/src/fe-text/term-curses.c
@@ -275,21 +275,25 @@ static int get_attr(int color)
{
int attr;
+ if ((color & FG_MASK) >> 4)
+ color = (color & ~FG_MASK) | term_color256map[color & FG_MASK];
+ if ((color & BG_MASK) >> (BG_SHIFT + 4))
+ color = (color & ~BG_MASK) | (term_color256map[(color & BG_MASK) >> BG_SHIFT] << BG_SHIFT);
if (!term_use_colors)
- attr = (color & 0x70) ? A_REVERSE : 0;
- else if ((color & 0xff) == 8 || (color & (0xff | ATTR_RESETFG)) == 0)
+ attr = (color & (0x7 << BG_SHIFT)) ? A_REVERSE : 0;
+ else if ((color & ((0xf << BG_SHIFT) | 0xf)) == 8 || (color & (FG_MASK | BG_MASK | ATTR_RESETFG)) == 0)
attr = COLOR_PAIR(63);
- else if ((color & 0x77) == 0)
+ else if ((color & ((0x7 << BG_SHIFT) | 0x7)) == 0)
attr = A_NORMAL;
else {
if (color & ATTR_RESETFG) {
- color &= ~0x0f;
+ color &= ~FG_MASK;
color |= settings_get_int("default_color");
}
- attr = COLOR_PAIR((color&7) | ((color&0x70)>>1));
+ attr = COLOR_PAIR((color&0x7) | ((color&(0x7<<BG_SHIFT))>>BG_SHIFT<<3));
}
- if ((color & 0x08) || (color & ATTR_BOLD)) attr |= A_BOLD;
+ if ((color & 0x8) || (color & ATTR_BOLD)) attr |= A_BOLD;
if (color & ATTR_BLINK) attr |= A_BLINK;
if (color & ATTR_UNDERLINE) attr |= A_UNDERLINE;
@@ -298,6 +302,11 @@ static int get_attr(int color)
}
/* Change active color */
+void term_set_color2(TERM_WINDOW *window, int col, unsigned int fg_ignore, unsigned int bg_ignore)
+{
+ term_set_color(window, col);
+}
+
void term_set_color(TERM_WINDOW *window, int col)
{
wattrset(window->win, get_attr(col));
diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c
index 0b27f452..2ca2f347 100644
--- a/src/fe-text/term-terminfo.c
+++ b/src/fe-text/term-terminfo.c
@@ -22,9 +22,12 @@
#include "signals.h"
#include "term.h"
#include "terminfo-core.h"
+#include "fe-windows.h"
#include "utf8.h"
#include <signal.h>
+#include <termios.h>
+#include <stdio.h>
/* returns number of characters in the beginning of the buffer being a
a single character, or -1 if more input is needed. The character will be
@@ -48,7 +51,8 @@ static int vcmove, vcx, vcy, curs_visible;
static int crealx, crealy, cforcemove;
static int curs_x, curs_y;
-static int last_fg, last_bg, last_attrs;
+static unsigned int last_fg, last_bg;
+static int last_attrs;
static GSource *sigcont_source;
static volatile sig_atomic_t got_sigcont;
@@ -293,118 +297,119 @@ void term_window_scroll(TERM_WINDOW *window, int count)
term_lines_empty[window->y+y] = FALSE;
}
-void term_set_color(TERM_WINDOW *window, int col)
+inline static int term_putchar(int c)
{
- int set_normal;
+ return fputc(c, current_term->out);
+}
+
+/* copied from terminfo-core.c */
+int tputs();
+
+static int term_set_color_24bit(int bg, unsigned int lc)
+{
+ static char buf[20];
+ const unsigned char color[] = { lc >> 16, lc >> 8, lc };
+
+ if (!term_use_colors24) {
+ if (bg)
+ terminfo_set_bg(color_24bit_256(color));
+ else
+ terminfo_set_fg(color_24bit_256(color));
+ return -1;
+ }
+
+ /* \e[x8;2;...;...;...m */
+ sprintf(buf, "\033[%d8;2;%d;%d;%dm", bg ? 4 : 3, color[0], color[1], color[2]);
+ return tputs(buf, 0, term_putchar);
+}
- int fg = (col & FG_MASK);
- int bg = (col & BG_MASK) >> 8;
-// int attrs = (col & 0xff0000) >> 16;
+#define COLOR_RESET UINT_MAX
- if (col != ATTR_RESET) {
- g_message( "T-TI: set color called with col: %d (%08x)\n", col, col);
- g_message( "T-TI: fg: %d (0x%02x), bg: %d (0x%02x)\n", fg, fg, bg, bg);
- } else {
- //g_message( "T-TI: set color called with col: %d (%08x)\n", col, col);
- }
+/* Change active color */
+void term_set_color2(TERM_WINDOW *window, int col, unsigned int fgcol24, unsigned int bgcol24)
+{
+ int set_normal;
- set_normal = ((col & ATTR_RESETFG) && last_fg != ATTR_COLOR_UNDEFINED) ||
- ((col & ATTR_RESETBG) && last_bg != ATTR_COLOR_UNDEFINED);
+ unsigned int fg = (col & ATTR_FGCOLOR24) ? fgcol24 << 8 : (col & FG_MASK);
+ unsigned int bg = (col & ATTR_BGCOLOR24) ? bgcol24 << 8 : ((col & BG_MASK) >> BG_SHIFT);
- if (((last_attrs & ATTR_BOLD) && !(col & ATTR_BOLD)) ||
- ((last_attrs & ATTR_BLINK) && !(col & ATTR_BLINK))) {
+ set_normal = ((col & ATTR_RESETFG) && last_fg != COLOR_RESET) ||
+ ((col & ATTR_RESETBG) && last_bg != COLOR_RESET);
+ if (((last_attrs & ATTR_BOLD) && (col & ATTR_BOLD) == 0) ||
+ ((last_attrs & ATTR_BLINK) && (col & ATTR_BLINK) == 0)) {
/* we'll need to get rid of bold/blink - this can only be
done with setting the default color */
set_normal = TRUE;
}
if (set_normal) {
- last_fg = last_bg = ATTR_COLOR_UNDEFINED;
+ last_fg = last_bg = COLOR_RESET;
last_attrs = 0;
- g_message( "setnormal: setting last_* to 0%04x\n", last_fg);
terminfo_set_normal();
- /* terminfo_set_bg(123); */
- //terminfo_set_fg(47);
}
- /* if colors are disabled, any background color setting enables
- * reverse video mode
- */
-
- if (!term_use_colors && bg > 0) {
+ if (!term_use_colors && bg > 0)
col |= ATTR_REVERSE;
- }
/* reversed text (use standout) */
if (col & ATTR_REVERSE) {
- if ((last_attrs & ATTR_REVERSE) == 0) {
- g_message( "setreverse: on\n");
+ if ((last_attrs & ATTR_REVERSE) == 0)
terminfo_set_standout(TRUE);
- }
- } else if (last_attrs & ATTR_REVERSE) {
- g_message( "setreverse: off\n");
+ } else if (last_attrs & ATTR_REVERSE)
terminfo_set_standout(FALSE);
- }
/* set foreground color */
- if (fg != last_fg && (fg != 0 || (col & ATTR_RESETFG) == 0)) {
+ if (fg != last_fg &&
+ (fg != 0 || (col & ATTR_RESETFG) == 0)) {
if (term_use_colors) {
last_fg = fg;
- terminfo_set_fg(last_fg);
- g_message( "setfg: setting fg to %d (0x%04x)\n", fg, fg);
+ if (!(fg & 0xff))
+ term_set_color_24bit(0, last_fg >> 8);
+ else
+ terminfo_set_fg(last_fg);
}
}
/* set background color */
- /* TODO: What magic numbers? - originally 0xf0 - 11110000
- *
- */
- if (col & 0x8000 && window->term->TI_colors == 8) {
- g_message( "0x080 match: setting attr_bold\n");
+ if (window && (term_color256map[bg&0xff]&8) == window->term->TI_colors)
col |= ATTR_BLINK;
- }
-
- if (col & ATTR_BLINK) {
- g_message( "setblink\n");
+ if (col & ATTR_BLINK)
current_term->set_blink(current_term);
- }
- if (bg != last_bg && (bg != 0 || (col & ATTR_RESETBG) == 0)) {
+ if (bg != last_bg &&
+ (bg != 0 || (col & ATTR_RESETBG) == 0)) {
if (term_use_colors) {
last_bg = bg;
- terminfo_set_bg(last_bg);
- g_message( "setbg: setting bg to %d (0x%04x)\n", bg, bg);
+ if (!(bg & 0xff))
+ term_set_color_24bit(1, last_bg >> 8);
+ else
+ terminfo_set_bg(last_bg);
}
}
/* bold */
-
- /* TODO: maybe make this fg > 7, since that implies a bright
- * color,which bold can emulate.
- */
- if (fg > 0 && window->term->TI_colors == 8) {
- g_message( "0x080 match: setting attr_bold\n");
+ if (window && (term_color256map[fg&0xff]&8) == window->term->TI_colors)
col |= ATTR_BOLD;
- }
-
- if (col & ATTR_BOLD) {
- g_message("setbold\n");
+ if (col & ATTR_BOLD)
terminfo_set_bold();
- }
/* underline */
if (col & ATTR_UNDERLINE) {
- if ((last_attrs & ATTR_UNDERLINE) == 0) {
+ if ((last_attrs & ATTR_UNDERLINE) == 0)
terminfo_set_uline(TRUE);
- }
- } else if (last_attrs & ATTR_UNDERLINE) {
+ } else if (last_attrs & ATTR_UNDERLINE)
terminfo_set_uline(FALSE);
- }
- /* update the new attribute settings whilst ignoring color values. */
- last_attrs = col & ~( BG_MASK | FG_MASK );
+ /* update the new attribute settings whilst ignoring color values. */
+ last_attrs = col & ~( BG_MASK | FG_MASK );
}
+void term_set_color(TERM_WINDOW *window, int col)
+{
+ term_set_color2(window, col &~(ATTR_FGCOLOR24|ATTR_BGCOLOR24), UINT_MAX, UINT_MAX);
+}
+
+
void term_move(TERM_WINDOW *window, int x, int y)
{
if (x >= 0 && y >= 0) {
diff --git a/src/fe-text/term.c b/src/fe-text/term.c
index 38239016..4600f02e 100644
--- a/src/fe-text/term.c
+++ b/src/fe-text/term.c
@@ -37,6 +37,7 @@
int term_width, term_height;
int term_use_colors;
+int term_use_colors24;
int term_type;
static int force_colors;
@@ -106,10 +107,28 @@ static void cmd_redraw(void)
irssi_redraw();
}
+int term_color256map[] = {
+ 0, 4, 2, 6, 1, 5, 3, 7, 8,12,10,14, 9,13,11,15,
+ 0, 0, 1, 1, 1, 1, 0, 0, 3, 1, 1, 9, 2, 2, 3, 3, 3, 3,
+ 2, 2, 3, 3, 3, 3, 2, 2, 3, 3, 3,11,10,10, 3, 3,11,11,
+ 0, 0, 5, 1, 1, 9, 0, 8, 8, 8, 9, 9, 2, 8, 8, 8, 9, 9,
+ 2, 8, 8, 8, 9, 9, 2, 8, 8, 3, 3,11,10,10, 3, 3,11,11,
+ 4, 4, 5, 5, 5, 5, 4, 8, 8, 8, 9, 9, 6, 8, 8, 8, 9, 9,
+ 6, 8, 8, 8, 8, 9, 6, 8, 8, 8, 7, 7, 6, 6, 8, 7, 7, 7,
+ 4, 4, 5, 5, 5, 5, 4, 8, 8, 8, 9, 9, 6, 8, 8, 8, 8, 9,
+ 6, 8, 8, 8, 7, 7, 6, 6, 8, 7, 7, 7, 6, 6, 7, 7, 7, 7,
+ 4, 4, 5, 5, 5,13, 4, 8, 8, 5, 5,13, 6, 8, 8, 8, 7, 7,
+ 6, 6, 8, 7, 7, 7, 6, 6, 7, 7, 7, 7,14,14, 7, 7, 7, 7,
+ 12,12, 5, 5,13,13,12,12, 5, 5,13,13, 6, 6, 8, 7, 7, 7,
+ 6, 6, 7, 7, 7, 7,14,14, 7, 7, 7, 7,14,14, 7, 7, 7,15,
+ 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 7, 7, 7, 7, 7, 7, 0 };
+
static void read_settings(void)
{
const char *str;
int old_colors = term_use_colors;
+ int old_colors24 = term_use_colors24;
int old_type = term_type;
/* set terminal type */
@@ -133,7 +152,14 @@ static void read_settings(void)
term_use_colors = settings_get_bool("colors") &&
(force_colors || term_has_colors());
- if (term_use_colors != old_colors)
+#ifdef TERM_TRUECOLOR
+ term_use_colors24 = settings_get_bool("colors_ansi_24bit") &&
+ (force_colors || term_has_colors());
+#else
+ term_use_colors24 = FALSE;
+#endif
+
+ if (term_use_colors != old_colors || term_use_colors24 != old_colors24)
irssi_redraw();
}
@@ -149,6 +175,12 @@ void term_common_init(void)
force_colors = FALSE;
term_use_colors = term_has_colors() && settings_get_bool("colors");
+#ifdef TERM_TRUECOLOR
+ settings_add_bool("lookandfeel", "colors_ansi_24bit", FALSE);
+ term_use_colors24 = term_has_colors() && settings_get_bool("colors_ansi_24bit");
+#else
+ term_use_colors24 = FALSE;
+#endif
read_settings();
if (g_get_charset(&dummy)) {
diff --git a/src/fe-text/term.h b/src/fe-text/term.h
index 5a40d4b2..e5f66644 100644
--- a/src/fe-text/term.h
+++ b/src/fe-text/term.h
@@ -3,30 +3,19 @@
typedef struct _TERM_WINDOW TERM_WINDOW;
-/* text attributes */
-
-
#define FG_MASK ( 0x00ff )
#define BG_MASK ( 0xff00 )
+#define BG_SHIFT 8
+/* text attributes */
#define ATTR_RESETFG ( 0x010000 )
#define ATTR_RESETBG ( 0x020000 )
#define ATTR_BOLD ( 0x040000 )
-#define ATTR_BLINK ( 0x080000 )
+#define ATTR_BLINK ( 0x080000 )
#define ATTR_UNDERLINE ( 0x100000 )
#define ATTR_REVERSE ( 0x200000 )
-
-/* can also mean default color, probably. */
-#define ATTR_COLOR_UNDEFINED ( -1 )
-
-#define EXT_COLOR_BLACK ( 0 )
-#define EXT_COLOR_RED ( 1 )
-#define EXT_COLOR_GREEN ( 2 )
-#define EXT_COLOR_YELLOW ( 3 )
-#define EXT_COLOR_BLUE ( 4 )
-#define EXT_COLOR_MAGENTA ( 5 )
-#define EXT_COLOR_CYAN ( 6 )
-#define EXT_COLOR_WHITE ( 7 )
+#define ATTR_FGCOLOR24 ( 0x400000 )
+#define ATTR_BGCOLOR24 ( 0x800000 )
#define ATTR_RESET (ATTR_RESETFG|ATTR_RESETBG)
@@ -42,6 +31,8 @@ typedef guint32 unichar;
extern TERM_WINDOW *root_window;
extern int term_width, term_height;
extern int term_use_colors, term_type;
+extern int term_use_colors24;
+extern int term_color256map[];
/* Initialize / deinitialize terminal */
int term_init(void);
@@ -80,10 +71,9 @@ void term_window_clear(TERM_WINDOW *window);
/* Scroll window up/down */
void term_window_scroll(TERM_WINDOW *window, int count);
+void term_set_color2(TERM_WINDOW *window, int col, unsigned int fgcol24, unsigned int bgcol24);
void term_set_color(TERM_WINDOW *window, int col);
-void term_set_extended_color(TERM_WINDOW *window, int fg, int bg);
-
void term_move(TERM_WINDOW *window, int x, int y);
void term_addch(TERM_WINDOW *window, char chr);
void term_add_unichar(TERM_WINDOW *window, unichar chr);
diff --git a/src/fe-text/terminfo-core.c b/src/fe-text/terminfo-core.c
index 753cf928..ba9256b4 100644
--- a/src/fe-text/terminfo-core.c
+++ b/src/fe-text/terminfo-core.c
@@ -331,16 +331,29 @@ static void _set_standout(TERM_REC *term, int set)
tput(tparm(set ? term->TI_smso : term->TI_rmso));
}
+inline static int color256(const TERM_REC *term, const int color) {
+ if (color < term->TI_colors)
+ return color;
+
+ if (color < 16)
+ return color % term->TI_colors;
+
+ if (color < 256)
+ return term_color256map[color] % term->TI_colors;
+
+ return color % term->TI_colors;
+}
+
/* Change foreground color */
static void _set_fg(TERM_REC *term, int color)
{
- tput(tparm(term->TI_fg[color % term->TI_colors]));
+ tput(tparm(term->TI_fg[color256(term, color)]));
}
/* Change background color */
static void _set_bg(TERM_REC *term, int color)
{
- tput(tparm(term->TI_bg[color % term->TI_colors]));
+ tput(tparm(term->TI_bg[color256(term, color)]));
}
/* Beep */
@@ -519,19 +532,19 @@ static int term_setup(TERM_REC *term)
term_env = getenv("TERM");
if (term_env == NULL) {
- g_message( "TERM environment not set\n");
+ fprintf(stderr, "TERM environment not set\n");
return 0;
}
#ifdef HAVE_TERMINFO
if (setupterm(term_env, 1, &err) != 0) {
- g_message( "setupterm() failed for TERM=%s: %d\n", term_env, err);
+ fprintf(stderr, "setupterm() failed for TERM=%s: %d\n", term_env, err);
return 0;
}
#else
if (tgetent(term->buffer1, term_env) < 1)
{
- g_message( "Termcap not found for TERM=%s\n", term_env);
+ fprintf(stderr, "Termcap not found for TERM=%s\n", term_env);
return 0;
}
#endif
@@ -544,7 +557,7 @@ static int term_setup(TERM_REC *term)
else if (term->TI_hpa && term->TI_vpa)
term->move = _move_pa;
else {
- g_message( "Terminal doesn't support cursor movement\n");
+ fprintf(stderr, "Terminal doesn't support cursor movement\n");
return 0;
}
term->move_relative = _move_relative;
@@ -561,7 +574,7 @@ static int term_setup(TERM_REC *term)
else if (term->scroll == NULL && (term->TI_il1 && term->TI_dl1))
term->scroll = _scroll_line_1;
else if (term->scroll == NULL) {
- g_message( "Terminal doesn't support scrolling\n");
+ fprintf(stderr, "Terminal doesn't support scrolling\n");
return 0;
}
@@ -578,7 +591,7 @@ static int term_setup(TERM_REC *term)
/* we could do this by line inserts as well, but don't
bother - if some terminal has insert line it most probably
has delete line as well, if not a regular clear screen */
- g_message( "Terminal doesn't support clearing screen\n");
+ fprintf(stderr, "Terminal doesn't support clearing screen\n");
return 0;
}
@@ -586,7 +599,7 @@ static int term_setup(TERM_REC *term)
if (term->TI_el)
term->clrtoeol = _clrtoeol;
else {
- g_message( "Terminal doesn't support clearing to end of line\n");
+ fprintf(stderr, "Terminal doesn't support clearing to end of line\n");
return 0;
}
diff --git a/src/fe-text/terminfo-core.h b/src/fe-text/terminfo-core.h
index cd851198..9e2b76d5 100644
--- a/src/fe-text/terminfo-core.h
+++ b/src/fe-text/terminfo-core.h
@@ -16,8 +16,6 @@
#define terminfo_set_bold() current_term->set_bold(current_term)
#define terminfo_set_uline(set) current_term->set_uline(current_term, set)
#define terminfo_set_standout(set) current_term->set_standout(current_term, set)
-// new
-#define terminfo_set_blink() current_term->set_blink(current_term)
#define terminfo_is_colors_set(term) (term->TI_fg != NULL)
#define terminfo_beep(term) current_term->beep(current_term)
diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c
index 78509151..81deaf54 100644
--- a/src/fe-text/textbuffer-view.c
+++ b/src/fe-text/textbuffer-view.c
@@ -104,65 +104,78 @@ static void textbuffer_cache_unref(TEXT_BUFFER_CACHE_REC *cache)
textbuffer_cache_destroy(cache);
}
-#define FGATTR (ATTR_NOCOLORS | ATTR_RESETFG | 0xff)
-#define BGATTR (ATTR_NOCOLORS | ATTR_RESETBG | 0xff00)
+#define FGATTR (ATTR_NOCOLORS | ATTR_RESETFG | FG_MASK | ATTR_FGCOLOR24)
+#define BGATTR (ATTR_NOCOLORS | ATTR_RESETBG | BG_MASK | ATTR_BGCOLOR24)
static void update_cmd_color(unsigned char cmd, int *color)
{
- static int next_color_bg = 0;
- g_message( "update_cmd_color() color: 0x%08x, cmd: 0x%08x\n", *color, cmd);
-
- if (cmd & 0x80) { /* cmd message */
- switch (cmd) {
-
+ if ((cmd & 0x80) == 0) {
+ if (cmd & LINE_COLOR_BG) {
+ /* set background color */
+ *color &= FGATTR;
+ *color &= ~ATTR_FGCOLOR24;
+ if ((cmd & LINE_COLOR_DEFAULT) == 0)
+ *color |= (cmd & 0x0f) << BG_SHIFT;
+ else {
+ *color = (*color & FGATTR) | ATTR_RESETBG;
+ }
+ } else {
+ /* set foreground color */
+ *color &= BGATTR;
+ *color &= ~ATTR_BGCOLOR24;
+ if ((cmd & LINE_COLOR_DEFAULT) == 0)
+ *color |= cmd & 0x0f;
+ else {
+ *color = (*color & BGATTR) | ATTR_RESETFG;
+ }
+ }
+ } else switch (cmd) {
case LINE_CMD_UNDERLINE:
*color ^= ATTR_UNDERLINE;
- g_message( "update_cmd_color() toggle underline 0x%08d\n", *color);
-
break;
case LINE_CMD_REVERSE:
-
*color ^= ATTR_REVERSE;
- g_message( "update_cmd_color() toggle reverse 0x%08d\n", *color);
-
break;
case LINE_CMD_BLINK:
-
*color ^= ATTR_BLINK;
- g_message( "update_cmd_color() toggle blink 0x%08d\n", *color);
-
break;
case LINE_CMD_BOLD:
-
*color ^= ATTR_BOLD;
- g_message( "update_cmd_color() toggle bold 0x%08d\n", *color);
-
break;
case LINE_CMD_COLOR0:
*color &= BGATTR;
- g_message( "update_cmd_color() set BGATTR RESET 0x%08d\n", *color);
-
- break;
- case LINE_CMD_SELECT_FG:
- next_color_bg = 0;
- g_message( "update_cmd_color() Next color will be FG\n");
-
- break;
-
- case LINE_CMD_SELECT_BG:
- next_color_bg = 1;
- g_message( "update_cmd_color() Next color will be BG\n");
+ *color &= ~ATTR_FGCOLOR24;
break;
}
- } else {
- if (next_color_bg == 1) {
- *color = cmd << 8;
- } else {
- *color = cmd;
- }
- }
}
+#ifdef TERM_TRUECOLOR
+static void unformat_24bit_line_color(const unsigned char **ptr, int off, int *flags, int *fg, int *bg)
+{
+ unsigned int color;
+ unsigned char rgbx[4];
+ unsigned int i;
+ for (i = 0; i < 4; ++i) {
+ rgbx[i] = (*ptr)[i + off];
+ }
+ rgbx[3] -= 0x20;
+ *ptr += 4;
+ for (i = 0; i < 3; ++i) {
+ if (rgbx[3] & (0x10 << i))
+ rgbx[i] -= 0x20;
+ }
+ color = rgbx[0] << 16 | rgbx[1] << 8 | rgbx[2];
+ if (rgbx[3] & 0x1) {
+ *flags = (*flags & FGATTR) | ATTR_BGCOLOR24;
+ *bg = color;
+ }
+ else {
+ *flags = (*flags & BGATTR) | ATTR_FGCOLOR24;
+ *fg = color;
+ }
+}
+#endif
+
static inline unichar read_unichar(const unsigned char *data, const unsigned char **next, int *width)
{
unichar chr = g_utf8_get_char_validated(data, -1);
@@ -188,6 +201,7 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
unsigned char cmd;
const unsigned char *ptr, *next_ptr, *last_space_ptr;
int xpos, pos, indent_pos, last_space, last_color, color, linecount;
+ int last_bg24, last_fg24, bg24, fg24;
int char_width;
g_return_val_if_fail(line->text != NULL, NULL);
@@ -221,7 +235,18 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
/* set indentation position here - don't do
it if we're too close to right border */
if (xpos < view->width-5) indent_pos = xpos;
- } else
+ } else if (cmd == LINE_COLOR_EXT) {
+ color &= ~ATTR_FGCOLOR24;
+ color = (color & BGATTR) | *ptr++;
+ } else if (cmd == LINE_COLOR_EXT_BG) {
+ color &= ~ATTR_BGCOLOR24;
+ color = (color & FGATTR) | (*ptr++ << BG_SHIFT);
+ }
+#ifdef TERM_TRUECOLOR
+ else if (cmd == LINE_COLOR_24)
+ unformat_24bit_line_color(&ptr, 0, &color, &fg24, &bg24);
+#endif
+ else
update_cmd_color(cmd, &color);
continue;
}
@@ -253,7 +278,7 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
sub = g_new0(LINE_CACHE_SUB_REC, 1);
if (last_space > indent_pos && last_space > 10) {
/* go back to last space */
- color = last_color;
+ color = last_color; fg24 = last_fg24; bg24 = last_bg24;
ptr = last_space_ptr;
while (*ptr == ' ') ptr++;
} else if (view->longword_noindent) {
@@ -266,6 +291,9 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
sub->indent = xpos;
sub->indent_func = indent_func;
sub->color = color;
+#ifdef TERM_TRUECOLOR
+ sub->fg24 = fg24; sub->bg24 = bg24;
+#endif
lines = g_slist_append(lines, sub);
linecount++;
@@ -277,11 +305,11 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
if (!view->utf8 && char_width > 1) {
last_space = xpos;
last_space_ptr = next_ptr;
- last_color = color;
+ last_color = color; last_fg24 = fg24; last_bg24 = bg24;
} else if (*ptr == ' ') {
last_space = xpos;
last_space_ptr = ptr;
- last_color = color;
+ last_color = color; last_fg24 = fg24; last_bg24 = bg24;
}
xpos += char_width;
@@ -359,7 +387,7 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
const unsigned char *text, *end, *text_newline;
unsigned char *tmp;
unichar chr;
- int xpos, color, drawcount, first, need_move, need_clrtoeol, char_width;
+ int xpos, color, fg24, bg24, drawcount, first, need_move, need_clrtoeol, char_width;
if (view->dirty) /* don't bother drawing anything - redraw is coming */
return 0;
@@ -373,7 +401,6 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
xpos = drawcount = 0; first = TRUE;
text_newline = text =
subline == 0 ? line->text : cache->lines[subline-1].start;
- g_message( "view_line_draw()\n");
for (;;) {
if (text == text_newline) {
if (need_clrtoeol && xpos < term_width) {
@@ -395,6 +422,10 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
if (indent_func == NULL)
xpos = cache->lines[subline-1].indent;
color = cache->lines[subline-1].color;
+#ifdef TERM_TRUECOLOR
+ fg24 = cache->lines[subline-1].fg24;
+ bg24 = cache->lines[subline-1].bg24;
+#endif
} else {
indent_func = NULL;
}
@@ -412,12 +443,10 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
xpos = indent_func(view, line, ypos);
}
- if (need_move || xpos > 0) {
+ if (need_move || xpos > 0)
term_move(view->window, xpos, ypos);
- }
- g_message( "view_line_draw(): color: 0x%08x\n", color);
- term_set_color(view->window, color);
+ term_set_color2(view->window, color, fg24, bg24);
if (subline == cache->count-1) {
text_newline = NULL;
@@ -443,11 +472,17 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
text = tmp;
continue;
} else {
- update_cmd_color(*text, &color);
- g_message( "post update_cmd_color: 0x%08x\n",
- color);
-
- term_set_color(view->window, color);
+ if (*text == LINE_COLOR_EXT)
+ color = (color & BGATTR & ~ATTR_FGCOLOR24) | *++text;
+ else if (*text == LINE_COLOR_EXT_BG)
+ color = (color & FGATTR & ~ATTR_BGCOLOR24) | (*++text << BG_SHIFT);
+#ifdef TERM_TRUECOLOR
+ else if (*text == LINE_COLOR_24)
+ unformat_24bit_line_color(&text, 1, &color, &fg24, &bg24);
+#endif
+ else
+ update_cmd_color(*text, &color);
+ term_set_color2(view->window, color, fg24, bg24);
}
text++;
continue;
@@ -476,13 +511,9 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
term_addch(view->window, *text);
} else {
/* low-ascii */
- g_message( "printing inverse char %c\n",
- (chr & 127)+'A'-1);
term_set_color(view->window, ATTR_RESET|ATTR_REVERSE);
term_addch(view->window, (chr & 127)+'A'-1);
- g_message( "setting color back to: 0x%08x\n",
- color);
- term_set_color(view->window, color);
+ term_set_color2(view->window, color, fg24, bg24);
}
}
text = end;
diff --git a/src/fe-text/textbuffer-view.h b/src/fe-text/textbuffer-view.h
index 46da808e..48cba093 100644
--- a/src/fe-text/textbuffer-view.h
+++ b/src/fe-text/textbuffer-view.h
@@ -15,6 +15,9 @@ typedef struct {
int indent;
INDENT_FUNC indent_func;
int color;
+#ifdef TERM_TRUECOLOR
+ int fg24, bg24;
+#endif
/* first word in line belong to the end of the last word in
previous line */
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c
index 35f52a16..ad1b06f6 100644
--- a/src/fe-text/textbuffer.c
+++ b/src/fe-text/textbuffer.c
@@ -39,8 +39,8 @@ TEXT_BUFFER_REC *textbuffer_create(void)
buffer = g_slice_new0(TEXT_BUFFER_REC);
buffer->last_eol = TRUE;
- buffer->last_fg = LINE_COLOR_DEFAULT;
- buffer->last_bg = LINE_COLOR_DEFAULT | LINE_COLOR_BG;
+ buffer->last_fg = -1;
+ buffer->last_bg = -1;
return buffer;
}
@@ -148,6 +148,7 @@ static void text_chunk_append(TEXT_BUFFER_REC *buffer,
{
TEXT_CHUNK_REC *chunk;
int left;
+ int i;
if (len == 0)
return;
@@ -166,8 +167,12 @@ static void text_chunk_append(TEXT_BUFFER_REC *buffer,
}
}
- if (left > 0 && data[left-1] == 0)
- left--; /* don't split the commands */
+ for (i = 5; i > 0; --i) {
+ if (left >= i && data[left-i] == 0) {
+ left -= i; /* don't split the commands */
+ break;
+ }
+ }
memcpy(chunk->buffer + chunk->pos, data, left);
chunk->pos += left;
@@ -238,84 +243,92 @@ int textbuffer_line_exists_after(LINE_REC *line, LINE_REC *search)
return FALSE;
}
+#ifdef TERM_TRUECOLOR
+static void format_24bit_line_color(unsigned char *out, int *pos, int bg, unsigned int color)
+{
+ unsigned char rgb[] = { color >> 16, color >> 8, color };
+ unsigned char x = bg ? 0x1 : 0;
+ unsigned int i;
+ out[(*pos)++] = LINE_COLOR_24;
+ for (i = 0; i < 3; ++i) {
+ if (rgb[i] > 0x20)
+ out[(*pos)++] = rgb[i];
+ else {
+ out[(*pos)++] = 0x20 + rgb[i];
+ x |= 0x10 << i;
+ }
+ }
+ out[(*pos)++] = 0x20 + x;
+}
+#endif
+
void textbuffer_line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line,
int fg, int bg, int flags)
{
- unsigned char data[20];
- memset(data, 0, 20);
-
- int pos = 0;
- int i = 0;
- /* get the fg & bg command chars */
- /* TODO: These things are adding additional data to colours. */
- g_message( "TBLAC1: fg: 0x%08x, bg: 0x%08x, flags: 0x%08x, last_flags: 0x%08x\n",
- fg, bg, flags, buffer->last_flags);
+ unsigned char data[22];
+ int pos;
- /* fg = fg < 0 ? LINE_COLOR_DEFAULT : fg & 0xff; */
- /* bg = LINE_COLOR_BG | (bg < 0 ? LINE_COLOR_DEFAULT : bg & 0xff); */
- g_message( "TBLAC2: fg: 0x%02x, bg: 0x%02x\n", fg, bg);
-
- if (fg != buffer->last_fg) {
+ pos = 0;
+ if (fg != buffer->last_fg
+ || (flags & GUI_PRINT_FLAG_COLOR_24_FG) != (buffer->last_flags & GUI_PRINT_FLAG_COLOR_24_FG)) {
buffer->last_fg = fg;
data[pos++] = 0;
- data[pos++] = LINE_CMD_SELECT_FG;
- data[pos++] = 0;
- data[pos++] = fg == 0 ? LINE_CMD_COLOR0 : fg;
- g_message( "TBLAC2: fg: data[%d}=%d(0x%02x)\n", pos-1,data[pos-1],data[pos-1]);
-
+#ifdef TERM_TRUECOLOR
+ if (flags & GUI_PRINT_FLAG_COLOR_24_FG)
+ format_24bit_line_color(data, &pos, 0, fg);
+ else
+#endif
+ if (fg < 0)
+ data[pos++] = LINE_COLOR_DEFAULT;
+ else if (fg < 16)
+ data[pos++] = fg == 0 ? LINE_CMD_COLOR0 : fg;
+ else if (fg < 256) {
+ data[pos++] = LINE_COLOR_EXT;
+ data[pos++] = fg;
+ }
}
- if (bg != buffer->last_bg) {
+ if (bg != buffer->last_bg
+ || (flags & GUI_PRINT_FLAG_COLOR_24_BG) != (buffer->last_flags & GUI_PRINT_FLAG_COLOR_24_BG)) {
buffer->last_bg = bg;
data[pos++] = 0;
- data[pos++] = LINE_CMD_SELECT_BG;
- data[pos++] = 0;
- data[pos++] = bg;
- g_message( "TBLAC2: bg: data[%d}=%d(0x%02x)\n", pos-1,data[pos-1],data[pos-1]);
-
+#ifdef TERM_TRUECOLOR
+ if (flags & GUI_PRINT_FLAG_COLOR_24_BG)
+ format_24bit_line_color(data, &pos, 1, bg);
+ else
+#endif
+ if (bg < 0)
+ data[pos++] = LINE_COLOR_BG | LINE_COLOR_DEFAULT;
+ else if (bg < 16)
+ data[pos++] = LINE_COLOR_BG | bg;
+ else if (bg < 256) {
+ data[pos++] = LINE_COLOR_EXT_BG;
+ data[pos++] = bg;
+ }
}
if ((flags & GUI_PRINT_FLAG_UNDERLINE) != (buffer->last_flags & GUI_PRINT_FLAG_UNDERLINE)) {
data[pos++] = 0;
data[pos++] = LINE_CMD_UNDERLINE;
- g_message( "TBLAC2: underline: data[%d}=%d(0x%02x)\n", pos-1,data[pos-1],data[pos-1]);
-
}
if ((flags & GUI_PRINT_FLAG_REVERSE) != (buffer->last_flags & GUI_PRINT_FLAG_REVERSE)) {
data[pos++] = 0;
data[pos++] = LINE_CMD_REVERSE;
- g_message( "TBLAC2: reverse: data[%d}=%d(0x%02x)\n", pos-1,data[pos-1],data[pos-1]);
-
}
if ((flags & GUI_PRINT_FLAG_BLINK) != (buffer->last_flags & GUI_PRINT_FLAG_BLINK)) {
data[pos++] = 0;
data[pos++] = LINE_CMD_BLINK;
- g_message( "TBLAC2: blink: data[%d}=%d(0x%02x)\n", pos-1,data[pos-1],data[pos-1]);
-
}
if ((flags & GUI_PRINT_FLAG_BOLD) != (buffer->last_flags & GUI_PRINT_FLAG_BOLD)) {
data[pos++] = 0;
data[pos++] = LINE_CMD_BOLD;
- g_message( "TBLAC2: bold: data[%d}=%d(0x%02x)\n", pos,data[pos-1],data[pos-1]);
-
}
if (flags & GUI_PRINT_FLAG_INDENT) {
data[pos++] = 0;
data[pos++] = LINE_CMD_INDENT;
- g_message( "TBLAC2: indent: data[%d}=%d(0x%02x)\n", pos-1,data[pos-1],data[pos-1]);
-
}
- g_message( "TBLAC data:\n");
-
- for (i=0; i < 20; i++) {
- g_message( "%02x\n", data[i]);
- }
- g_message( "\n");
-
- if (pos > 0) {
- g_message( "calling textbuffer_insert()\n");
+ if (pos > 0)
*line = textbuffer_insert(buffer, *line, data, pos, NULL);
- }
buffer->last_flags = flags;
}
@@ -351,14 +364,11 @@ LINE_REC *textbuffer_insert(TEXT_BUFFER_REC *buffer, LINE_REC *insert_after,
data[len-2] == 0 && data[len-1] == LINE_CMD_EOL;
if (buffer->last_eol) {
- buffer->last_fg = LINE_COLOR_DEFAULT;
- buffer->last_bg = LINE_COLOR_DEFAULT | LINE_COLOR_BG;
+ buffer->last_fg = -1;
+ buffer->last_bg = -1;
buffer->last_flags = 0;
}
- g_message( "line created: '%s' %d\n", line->text, line->info.time);
- g_message( "Buffer %p\n", buffer);
-
return line;
}
@@ -413,22 +423,18 @@ void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer)
static void set_color(GString *str, int cmd)
{
- int color = ATTR_COLOR_UNDEFINED;
+ int color = -1;
if (!(cmd & LINE_COLOR_DEFAULT))
- color = (cmd & 0xff) + '0';
-
- g_message( "textbuffer.c:set_color color: %d (%02x)\n", color, color);
+ color = (cmd & 0x0f)+'0';
if ((cmd & LINE_COLOR_BG) == 0) {
/* change foreground color */
- g_string_append_printf(str, "%c%c%c",
- LINE_FORMAT_MARKER,
+ g_string_append_printf(str, "\004%c%c",
color, FORMAT_COLOR_NOCHANGE);
} else {
/* change background color */
- g_string_append_printf(str, "%c%c%c",
- LINE_FORMAT_MARKER,
+ g_string_append_printf(str, "\004%c%c",
FORMAT_COLOR_NOCHANGE, color);
}
}
@@ -467,13 +473,17 @@ void textbuffer_line2text(LINE_REC *line, int coloring, GString *str)
if (!coloring) {
/* no colors, skip coloring commands */
+ if (cmd == LINE_COLOR_EXT || cmd == LINE_COLOR_EXT_BG)
+ ptr++;
+#ifdef TERM_TRUECOLOR
+ else if (cmd == LINE_COLOR_24)
+ ptr+=4;
+#endif
+
continue;
}
- /* these magic numbers correspond with some of IS_COLOR_CODE in
- * formats.c:843 (31 and 22) */
-
- if ((cmd & 0x80) == 0) {
+ if ((cmd & LINE_CMD_EOL) == 0) {
/* set color */
set_color(str, cmd);
} else switch (cmd) {
@@ -499,6 +509,17 @@ void textbuffer_line2text(LINE_REC *line, int coloring, GString *str)
g_string_append_printf(str, "\004%c",
FORMAT_STYLE_INDENT);
break;
+ case LINE_COLOR_EXT:
+ format_ext_color(str, 0, *ptr++);
+ break;
+ case LINE_COLOR_EXT_BG:
+ format_ext_color(str, 1, *ptr++);
+ break;
+#ifdef TERM_TRUECOLOR
+ case LINE_COLOR_24:
+ g_string_append_printf(str, "\004%c", FORMAT_COLOR_24);
+ break;
+#endif
}
}
}
diff --git a/src/fe-text/textbuffer.h b/src/fe-text/textbuffer.h
index a94a06af..6123ba7a 100644
--- a/src/fe-text/textbuffer.h
+++ b/src/fe-text/textbuffer.h
@@ -8,20 +8,20 @@
#define LINE_COLOR_BG 0x20
#define LINE_COLOR_DEFAULT 0x10
-/* command values (see _LINE_REC protocol) */
enum {
LINE_CMD_EOL=0x80, /* line ends here */
LINE_CMD_CONTINUE, /* line continues in next block */
- /* TODO: no longer needed */
LINE_CMD_COLOR0, /* change to black, would be same as \0\0 but it breaks things.. */
LINE_CMD_UNDERLINE, /* enable/disable underlining */
LINE_CMD_REVERSE, /* enable/disable reversed text */
LINE_CMD_INDENT, /* if line is split, indent it at this position */
LINE_CMD_BLINK, /* enable/disable blink */
LINE_CMD_BOLD, /* enable/disable bold */
- LINE_CMD_SELECT_FG,
- LINE_CMD_SELECT_BG
-
+ LINE_COLOR_EXT, /* extended color */
+ LINE_COLOR_EXT_BG, /* extended bg */
+#ifdef TERM_TRUECOLOR
+ LINE_COLOR_24, /* 24bit color */
+#endif
};
typedef struct {
@@ -29,7 +29,6 @@ typedef struct {
time_t time;
} LINE_INFO_REC;
-/* TODO: fixme. */
typedef struct _LINE_REC {
/* Text in the line. \0 means that the next char will be a
color or command.
@@ -44,28 +43,6 @@ typedef struct _LINE_REC {
DO NOT ADD BLACK WITH \0\0 - this will break things. Use
LINE_CMD_COLOR0 instead. */
-
-
- /* NEW COLOUR PROTOCOL:
-
- 0x00 - indicates command or colour.
- 0x01 - command follows (1 byte)
- -- following may be omitted if LINE_CMD_USE_DEFAULT_[FB}G is set.
- 0x02 - BG colour follows (1 byte)
- 0x04 - FG colour follows (1 byte)
-
-
- Things that will need to be fixed:
-
- * textbuffer-view.c:update_cmd_color()
- * textbuffer-view.c:view_line_draw()
- * textbuffer-view.c:view_update_line_cache()
-
- * textbuffer.c:textbuffer_line2text()
- * textbuffer.c:mark_temp_eol macro
-
- * gui-printtext.c ?
- */
struct _LINE_REC *prev, *next;
unsigned char *text;