1
0
mirror of https://github.com/irssi/irssi.git synced 2024-09-01 04:14:16 -04:00

Make line_add_colors part of the textbuffer api.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4748 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Emanuele Giaquinta 2008-03-10 12:05:43 +00:00 committed by exg
parent a3526caf41
commit da232b18c1
3 changed files with 59 additions and 56 deletions

View File

@ -32,7 +32,6 @@
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 };
static int scrollback_lines, scrollback_time, scrollback_burst_remove; static int scrollback_lines, scrollback_time, scrollback_burst_remove;
static int last_fg, last_bg, last_flags;
static int next_xpos, next_ypos; static int next_xpos, next_ypos;
static GHashTable *indent_functions; static GHashTable *indent_functions;
@ -161,51 +160,6 @@ static void get_colors(int flags, int *fg, int *bg, int *attr)
if (flags & GUI_PRINT_FLAG_BLINK) *attr |= ATTR_BLINK; if (flags & GUI_PRINT_FLAG_BLINK) *attr |= ATTR_BLINK;
} }
static void line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line,
int fg, int bg, int flags)
{
unsigned char data[20];
int pos;
/* 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);
if (flags & GUI_PRINT_FLAG_BOLD)
fg |= LINE_COLOR_BOLD;
if (flags & GUI_PRINT_FLAG_BLINK)
bg |= LINE_COLOR_BLINK;
pos = 0;
if (fg != last_fg) {
last_fg = fg;
data[pos++] = 0;
data[pos++] = fg == 0 ? LINE_CMD_COLOR0 : fg;
}
if (bg != last_bg) {
last_bg = bg;
data[pos++] = 0;
data[pos++] = bg;
}
if ((flags & GUI_PRINT_FLAG_UNDERLINE) != (last_flags & GUI_PRINT_FLAG_UNDERLINE)) {
data[pos++] = 0;
data[pos++] = LINE_CMD_UNDERLINE;
}
if ((flags & GUI_PRINT_FLAG_REVERSE) != (last_flags & GUI_PRINT_FLAG_REVERSE)) {
data[pos++] = 0;
data[pos++] = LINE_CMD_REVERSE;
}
if (flags & GUI_PRINT_FLAG_INDENT) {
data[pos++] = 0;
data[pos++] = LINE_CMD_INDENT;
}
if (pos > 0)
*line = textbuffer_insert(buffer, *line, data, pos, NULL);
last_flags = flags;
}
static void line_add_indent_func(TEXT_BUFFER_REC *buffer, LINE_REC **line, static void line_add_indent_func(TEXT_BUFFER_REC *buffer, LINE_REC **line,
const char *function) const char *function)
{ {
@ -269,11 +223,8 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
if (flags & GUI_PRINT_FLAG_NEWLINE) { if (flags & GUI_PRINT_FLAG_NEWLINE) {
view_add_eol(view, &insert_after); view_add_eol(view, &insert_after);
last_fg = LINE_COLOR_DEFAULT;
last_bg = LINE_COLOR_DEFAULT | LINE_COLOR_BG;
last_flags = 0;
} }
line_add_colors(view->buffer, &insert_after, fg, bg, flags); textbuffer_line_add_colors(view->buffer, &insert_after, fg, bg, flags);
if (flags & GUI_PRINT_FLAG_INDENT_FUNC) { if (flags & GUI_PRINT_FLAG_INDENT_FUNC) {
/* specify the indentation function */ /* specify the indentation function */
@ -292,10 +243,6 @@ static void sig_gui_printtext_finished(WINDOW_REC *window)
TEXT_BUFFER_VIEW_REC *view; TEXT_BUFFER_VIEW_REC *view;
LINE_REC *insert_after; LINE_REC *insert_after;
last_fg = LINE_COLOR_DEFAULT;
last_bg = LINE_COLOR_DEFAULT | LINE_COLOR_BG;
last_flags = 0;
view = WINDOW_GUI(window)->view; view = WINDOW_GUI(window)->view;
insert_after = WINDOW_GUI(window)->use_insert_after ? insert_after = WINDOW_GUI(window)->use_insert_after ?
WINDOW_GUI(window)->insert_after : view->buffer->cur_line; WINDOW_GUI(window)->insert_after : view->buffer->cur_line;
@ -313,8 +260,6 @@ static void read_settings(void)
void gui_printtext_init(void) void gui_printtext_init(void)
{ {
last_fg = LINE_COLOR_DEFAULT;
last_bg = LINE_COLOR_DEFAULT | LINE_COLOR_BG;
next_xpos = next_ypos = -1; next_xpos = next_ypos = -1;
default_indent_func = NULL; default_indent_func = NULL;
indent_functions = g_hash_table_new((GHashFunc) g_str_hash, indent_functions = g_hash_table_new((GHashFunc) g_str_hash,

View File

@ -266,6 +266,53 @@ int textbuffer_line_exists_after(LINE_REC *line, LINE_REC *search)
return FALSE; return FALSE;
} }
static int last_fg, last_bg, last_flags;
void textbuffer_line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line,
int fg, int bg, int flags)
{
unsigned char data[20];
int pos;
/* 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);
if (flags & GUI_PRINT_FLAG_BOLD)
fg |= LINE_COLOR_BOLD;
if (flags & GUI_PRINT_FLAG_BLINK)
bg |= LINE_COLOR_BLINK;
pos = 0;
if (fg != last_fg) {
last_fg = fg;
data[pos++] = 0;
data[pos++] = fg == 0 ? LINE_CMD_COLOR0 : fg;
}
if (bg != last_bg) {
last_bg = bg;
data[pos++] = 0;
data[pos++] = bg;
}
if ((flags & GUI_PRINT_FLAG_UNDERLINE) != (last_flags & GUI_PRINT_FLAG_UNDERLINE)) {
data[pos++] = 0;
data[pos++] = LINE_CMD_UNDERLINE;
}
if ((flags & GUI_PRINT_FLAG_REVERSE) != (last_flags & GUI_PRINT_FLAG_REVERSE)) {
data[pos++] = 0;
data[pos++] = LINE_CMD_REVERSE;
}
if (flags & GUI_PRINT_FLAG_INDENT) {
data[pos++] = 0;
data[pos++] = LINE_CMD_INDENT;
}
if (pos > 0)
*line = textbuffer_insert(buffer, *line, data, pos, NULL);
last_flags = flags;
}
LINE_REC *textbuffer_append(TEXT_BUFFER_REC *buffer, LINE_REC *textbuffer_append(TEXT_BUFFER_REC *buffer,
const unsigned char *data, int len, const unsigned char *data, int len,
LINE_INFO_REC *info) LINE_INFO_REC *info)
@ -296,6 +343,12 @@ LINE_REC *textbuffer_insert(TEXT_BUFFER_REC *buffer, LINE_REC *insert_after,
buffer->last_eol = len >= 2 && buffer->last_eol = len >= 2 &&
data[len-2] == 0 && data[len-1] == LINE_CMD_EOL; data[len-2] == 0 && data[len-1] == LINE_CMD_EOL;
if (buffer->last_eol) {
last_fg = LINE_COLOR_DEFAULT;
last_bg = LINE_COLOR_DEFAULT | LINE_COLOR_BG;
last_flags = 0;
}
return line; return line;
} }
@ -533,6 +586,8 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
void textbuffer_init(void) void textbuffer_init(void)
{ {
last_fg = LINE_COLOR_DEFAULT;
last_bg = LINE_COLOR_DEFAULT | LINE_COLOR_BG;
buffer_chunk = g_mem_chunk_new("text buffer chunk", buffer_chunk = g_mem_chunk_new("text buffer chunk",
sizeof(TEXT_BUFFER_REC), sizeof(TEXT_BUFFER_REC),
sizeof(TEXT_BUFFER_REC)*32, G_ALLOC_AND_FREE); sizeof(TEXT_BUFFER_REC)*32, G_ALLOC_AND_FREE);

View File

@ -79,6 +79,9 @@ void textbuffer_line_unref_list(TEXT_BUFFER_REC *buffer, GList *list);
LINE_REC *textbuffer_line_last(TEXT_BUFFER_REC *buffer); LINE_REC *textbuffer_line_last(TEXT_BUFFER_REC *buffer);
int textbuffer_line_exists_after(LINE_REC *line, LINE_REC *search); int textbuffer_line_exists_after(LINE_REC *line, LINE_REC *search);
void textbuffer_line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line,
int fg, int bg, int flags);
/* Append text to buffer. When \0<EOL> is found at the END OF DATA, a new /* Append text to buffer. When \0<EOL> is found at the END OF DATA, a new
line is created. You must send the EOL command before you can do anything line is created. You must send the EOL command before you can do anything
else with the buffer. */ else with the buffer. */