diff options
author | Tom Feist <shabble@metavore.org> | 2011-05-03 15:40:34 +0100 |
---|---|---|
committer | Ailin Nemui <ailin@esf51.localdomain> | 2014-06-30 00:54:16 +0200 |
commit | 2d4edc51877719c49d712271967313310f4796fb (patch) | |
tree | a427b451338dd0e7b27b462a971528acdfbaca4d /src/fe-text/textbuffer.c | |
parent | 2e6f16c0faf345245c5a224de529827a51203d1c (diff) | |
download | irssi-2d4edc51877719c49d712271967313310f4796fb.zip |
Initial implementation of 256 colour support for Irssi
This patch implements some 256 colour support for Irssi up from the
previous 16 colours. Initial parsing of the %x/%X format codes is
implemented and the parser accounts in advances the char* for
that.
The colour attributes are widened from 4 to 8 bit. The colour protocol
is changed to a new format. Some pointers to remaining work are
written in the comment in textbuffer.h.
Note that Irssi already does support requesting 256 colours from the
terminal in the original source code, so this part did not have to be
touched.
Diffstat (limited to 'src/fe-text/textbuffer.c')
-rw-r--r-- | src/fe-text/textbuffer.c | 61 |
1 files changed, 52 insertions, 9 deletions
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index 69f5969c..35f52a16 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -242,47 +242,80 @@ void textbuffer_line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line, int fg, int bg, int flags) { unsigned char data[20]; - int pos; + memset(data, 0, 20); + int pos = 0; + int i = 0; /* get the fg & bg command chars */ - fg = fg < 0 ? LINE_COLOR_DEFAULT : fg & 0x0f; - bg = LINE_COLOR_BG | (bg < 0 ? LINE_COLOR_DEFAULT : bg & 0x0f); + /* 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); + + /* 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); - pos = 0; if (fg != buffer->last_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]); + } if (bg != buffer->last_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]); + } 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) + if (pos > 0) { + g_message( "calling textbuffer_insert()\n"); *line = textbuffer_insert(buffer, *line, data, pos, NULL); + } buffer->last_flags = flags; } @@ -323,6 +356,9 @@ LINE_REC *textbuffer_insert(TEXT_BUFFER_REC *buffer, LINE_REC *insert_after, buffer->last_flags = 0; } + g_message( "line created: '%s' %d\n", line->text, line->info.time); + g_message( "Buffer %p\n", buffer); + return line; } @@ -377,18 +413,22 @@ void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer) static void set_color(GString *str, int cmd) { - int color = -1; + int color = ATTR_COLOR_UNDEFINED; if (!(cmd & LINE_COLOR_DEFAULT)) - color = (cmd & 0x0f)+'0'; + color = (cmd & 0xff) + '0'; + + g_message( "textbuffer.c:set_color color: %d (%02x)\n", color, color); if ((cmd & LINE_COLOR_BG) == 0) { /* change foreground color */ - g_string_append_printf(str, "\004%c%c", + g_string_append_printf(str, "%c%c%c", + LINE_FORMAT_MARKER, color, FORMAT_COLOR_NOCHANGE); } else { /* change background color */ - g_string_append_printf(str, "\004%c%c", + g_string_append_printf(str, "%c%c%c", + LINE_FORMAT_MARKER, FORMAT_COLOR_NOCHANGE, color); } } @@ -430,6 +470,9 @@ void textbuffer_line2text(LINE_REC *line, int coloring, GString *str) continue; } + /* these magic numbers correspond with some of IS_COLOR_CODE in + * formats.c:843 (31 and 22) */ + if ((cmd & 0x80) == 0) { /* set color */ set_color(str, cmd); |