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
This commit is contained in:
Ailin Nemui 2014-01-09 15:20:29 +01:00
commit 96a292d40e
28 changed files with 904 additions and 493 deletions

View file

@ -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)
{
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;
}
if (*fg < 0 || *fg > 255) {
g_message( "getcolor: fg %d outside range, setting to -1\n", *fg);
*fg = -1;
}
if (*bg < 0 || *bg > 255) {
g_message( "getcolor: bf %d outside range, setting to -1\n", *bg);
*bg = -1;
}
*attr = 0;
if (flags & GUI_PRINT_FLAG_REVERSE) {
*attr |= ATTR_REVERSE;
g_message( "getcolor: setting flag_reverse\n");
if (flags & GUI_PRINT_FLAG_MIRC_COLOR) {
/* 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 (flags & GUI_PRINT_FLAG_BOLD) {
*attr |= ATTR_BOLD;
g_message( "getcolor: setting flag_bold\n");
if (flags & GUI_PRINT_FLAG_COLOR_24_FG)
*attr |= ATTR_FGCOLOR24;
else if (*fg < 0 || *fg > 255) {
*fg = -1;
*attr |= ATTR_RESETFG;
}
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");
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);
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)