mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
enable mirc colour processing
This commit is contained in:
parent
57fb173130
commit
8fd6dccaf1
@ -1222,8 +1222,14 @@ char *strip_codes(const char *input)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send a fully parsed text string for GUI to print */
|
/* parse text string into GUI_PRINT_FLAG_* separated pieces and emit them to handler
|
||||||
void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
handler is a SIGNAL_FUNC with the following arguments:
|
||||||
|
|
||||||
|
WINDOW_REC *window, void *fgcolor_int, void *bgcolor_int,
|
||||||
|
void *flags_int, const char *textpiece, TEXT_DEST_REC *dest
|
||||||
|
|
||||||
|
*/
|
||||||
|
void format_send_as_gui_flags(TEXT_DEST_REC *dest, const char *text, SIGNAL_FUNC handler)
|
||||||
{
|
{
|
||||||
THEME_REC *theme;
|
THEME_REC *theme;
|
||||||
char *dup, *str, *ptr, type;
|
char *dup, *str, *ptr, type;
|
||||||
@ -1238,8 +1244,8 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
|||||||
|
|
||||||
if (*str == '\0') {
|
if (*str == '\0') {
|
||||||
/* empty line, write line info only */
|
/* empty line, write line info only */
|
||||||
signal_emit_id(signal_gui_print_text, 6, dest->window, GINT_TO_POINTER(fgcolor),
|
handler(dest->window, GINT_TO_POINTER(fgcolor), GINT_TO_POINTER(bgcolor),
|
||||||
GINT_TO_POINTER(bgcolor), GINT_TO_POINTER(flags), str, dest);
|
GINT_TO_POINTER(flags), str, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*str != '\0') {
|
while (*str != '\0') {
|
||||||
@ -1259,16 +1265,14 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
|||||||
|
|
||||||
if (*str != '\0' || (flags & GUI_PRINT_FLAG_CLRTOEOL)) {
|
if (*str != '\0' || (flags & GUI_PRINT_FLAG_CLRTOEOL)) {
|
||||||
/* send the text to gui handler */
|
/* send the text to gui handler */
|
||||||
signal_emit_id(signal_gui_print_text, 6, dest->window,
|
handler(dest->window, GINT_TO_POINTER(fgcolor), GINT_TO_POINTER(bgcolor),
|
||||||
GINT_TO_POINTER(fgcolor),
|
GINT_TO_POINTER(flags), str, dest);
|
||||||
GINT_TO_POINTER(bgcolor),
|
|
||||||
GINT_TO_POINTER(flags), str,
|
|
||||||
dest);
|
|
||||||
flags &= ~(GUI_PRINT_FLAG_INDENT|GUI_PRINT_FLAG_CLRTOEOL);
|
flags &= ~(GUI_PRINT_FLAG_INDENT|GUI_PRINT_FLAG_CLRTOEOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == '\n') {
|
if (type == '\n') {
|
||||||
format_newline(dest);
|
handler(dest->window, GINT_TO_POINTER(-1), GINT_TO_POINTER(-1),
|
||||||
|
GINT_TO_POINTER(GUI_PRINT_FLAG_NEWLINE), "", dest);
|
||||||
fgcolor = theme->default_color;
|
fgcolor = theme->default_color;
|
||||||
bgcolor = -1;
|
bgcolor = -1;
|
||||||
flags &= GUI_PRINT_FLAG_INDENT|GUI_PRINT_FLAG_MONOSPACE;
|
flags &= GUI_PRINT_FLAG_INDENT|GUI_PRINT_FLAG_MONOSPACE;
|
||||||
@ -1414,6 +1418,20 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
|||||||
g_free(dup);
|
g_free(dup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static void gui_print_text_emitter(WINDOW_REC *window, void *fgcolor_int, void *bgcolor_int,
|
||||||
|
void *flags_int, const char *textpiece,
|
||||||
|
TEXT_DEST_REC *dest)
|
||||||
|
{
|
||||||
|
signal_emit_id(signal_gui_print_text, 6, window, fgcolor_int, bgcolor_int, flags_int,
|
||||||
|
textpiece, dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send a fully parsed text string for GUI to print */
|
||||||
|
void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
||||||
|
{
|
||||||
|
format_send_as_gui_flags(dest, text, (SIGNAL_FUNC) gui_print_text_emitter);
|
||||||
|
}
|
||||||
|
|
||||||
void format_gui_flags(GString *out, int *last_fg, int *last_bg, int *last_flags, int fg, int bg,
|
void format_gui_flags(GString *out, int *last_fg, int *last_bg, int *last_flags, int fg, int bg,
|
||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#ifndef IRSSI_FE_COMMON_CORE_FORMATS_H
|
#ifndef IRSSI_FE_COMMON_CORE_FORMATS_H
|
||||||
#define IRSSI_FE_COMMON_CORE_FORMATS_H
|
#define IRSSI_FE_COMMON_CORE_FORMATS_H
|
||||||
|
|
||||||
#include <irssi/src/fe-common/core/themes.h>
|
#include <irssi/src/core/signals.h>
|
||||||
#include <irssi/src/fe-common/core/fe-windows.h>
|
#include <irssi/src/fe-common/core/fe-windows.h>
|
||||||
|
#include <irssi/src/fe-common/core/themes.h>
|
||||||
|
|
||||||
#define GUI_PRINT_FLAG_BOLD 0x0001
|
#define GUI_PRINT_FLAG_BOLD 0x0001
|
||||||
#define GUI_PRINT_FLAG_REVERSE 0x0002
|
#define GUI_PRINT_FLAG_REVERSE 0x0002
|
||||||
@ -130,6 +131,14 @@ char *strip_codes(const char *input);
|
|||||||
|
|
||||||
/* send a fully parsed text string for GUI to print */
|
/* send a fully parsed text string for GUI to print */
|
||||||
void format_send_to_gui(TEXT_DEST_REC *dest, const char *text);
|
void format_send_to_gui(TEXT_DEST_REC *dest, const char *text);
|
||||||
|
/* parse text string into GUI_PRINT_FLAG_* separated pieces and emit them to handler
|
||||||
|
handler is a SIGNAL_FUNC with the following arguments:
|
||||||
|
|
||||||
|
WINDOW_REC *window, void *fgcolor_int, void *bgcolor_int,
|
||||||
|
void *flags_int, const char *textpiece, TEXT_DEST_REC *dest
|
||||||
|
|
||||||
|
*/
|
||||||
|
void format_send_as_gui_flags(TEXT_DEST_REC *dest, const char *text, SIGNAL_FUNC handler);
|
||||||
|
|
||||||
#define FORMAT_COLOR_NOCHANGE ('0'-1) /* don't change this, at least hilighting depends this value */
|
#define FORMAT_COLOR_NOCHANGE ('0'-1) /* don't change this, at least hilighting depends this value */
|
||||||
#define FORMAT_COLOR_EXT1 ('0'-2)
|
#define FORMAT_COLOR_EXT1 ('0'-2)
|
||||||
|
@ -238,7 +238,7 @@ static void remove_old_lines(TEXT_BUFFER_VIEW_REC *view)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_colors(int *flags, int *fg, int *bg, int *attr)
|
void gui_printtext_get_colors(int *flags, int *fg, int *bg, int *attr)
|
||||||
{
|
{
|
||||||
*attr = 0;
|
*attr = 0;
|
||||||
if (*flags & GUI_PRINT_FLAG_MIRC_COLOR) {
|
if (*flags & GUI_PRINT_FLAG_MIRC_COLOR) {
|
||||||
@ -336,7 +336,7 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
|
|||||||
flags = GPOINTER_TO_INT(pflags);
|
flags = GPOINTER_TO_INT(pflags);
|
||||||
fg = GPOINTER_TO_INT(fgcolor);
|
fg = GPOINTER_TO_INT(fgcolor);
|
||||||
bg = GPOINTER_TO_INT(bgcolor);
|
bg = GPOINTER_TO_INT(bgcolor);
|
||||||
get_colors(&flags, &fg, &bg, &attr);
|
gui_printtext_get_colors(&flags, &fg, &bg, &attr);
|
||||||
|
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
print_text_no_window(flags, fg, bg, attr, str);
|
print_text_no_window(flags, fg, bg, attr, str);
|
||||||
|
@ -21,5 +21,6 @@ void gui_printtext_internal(int xpos, int ypos, const char *str);
|
|||||||
void gui_printtext_after(TEXT_DEST_REC *dest, LINE_REC *prev, const char *str);
|
void gui_printtext_after(TEXT_DEST_REC *dest, LINE_REC *prev, const char *str);
|
||||||
void gui_printtext_after_time(TEXT_DEST_REC *dest, LINE_REC *prev, const char *str, time_t time);
|
void gui_printtext_after_time(TEXT_DEST_REC *dest, LINE_REC *prev, const char *str, time_t time);
|
||||||
void gui_printtext_window_border(int xpos, int ypos);
|
void gui_printtext_window_border(int xpos, int ypos);
|
||||||
|
void gui_printtext_get_colors(int *flags, int *fg, int *bg, int *attr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -205,10 +205,47 @@ static void sig_gui_print_text_finished(WINDOW_REC *window)
|
|||||||
gui->insert_after = insert_after;
|
gui->insert_after = insert_after;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void parse_colors_collector(const WINDOW_REC *window, const void *fgcolor_int,
|
||||||
|
const void *bgcolor_int, const void *flags_int,
|
||||||
|
const char *textpiece, const TEXT_DEST_REC *dest)
|
||||||
|
{
|
||||||
|
int fg, bg, flags, attr;
|
||||||
|
|
||||||
|
flags = GPOINTER_TO_INT(flags_int);
|
||||||
|
fg = GPOINTER_TO_INT(fgcolor_int);
|
||||||
|
bg = GPOINTER_TO_INT(bgcolor_int);
|
||||||
|
gui_printtext_get_colors(&flags, &fg, &bg, &attr);
|
||||||
|
|
||||||
|
if (flags & GUI_PRINT_FLAG_NEWLINE) {
|
||||||
|
g_string_append_c(color_buf->cur_text, '\n');
|
||||||
|
}
|
||||||
|
format_gui_flags(color_buf->cur_text, &color_buf->last_fg, &color_buf->last_bg,
|
||||||
|
&color_buf->last_flags, fg, bg, flags);
|
||||||
|
|
||||||
|
g_string_append(color_buf->cur_text, textpiece);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *parse_colors(TEXT_DEST_REC *dest, const char *text)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (text == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
color_buf = textbuffer_create(NULL);
|
||||||
|
format_send_as_gui_flags(dest, text, (SIGNAL_FUNC) parse_colors_collector);
|
||||||
|
tmp = g_strdup(color_buf->cur_text->str);
|
||||||
|
textbuffer_destroy(color_buf);
|
||||||
|
color_buf = NULL;
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
||||||
{
|
{
|
||||||
|
TEXT_DEST_REC dest;
|
||||||
GUI_WINDOW_REC *gui;
|
GUI_WINDOW_REC *gui;
|
||||||
LINE_REC *curr;
|
char *tmp, *text = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail(buffer != NULL, NULL);
|
g_return_val_if_fail(buffer != NULL, NULL);
|
||||||
g_return_val_if_fail(buffer->window != NULL, NULL);
|
g_return_val_if_fail(buffer->window != NULL, NULL);
|
||||||
@ -218,11 +255,11 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (line->info.level & MSGLEVEL_FORMAT && line->info.format != NULL) {
|
if (line->info.level & MSGLEVEL_FORMAT && line->info.format != NULL) {
|
||||||
TEXT_DEST_REC dest;
|
LINE_REC *curr;
|
||||||
THEME_REC *theme;
|
THEME_REC *theme;
|
||||||
int formatnum;
|
int formatnum;
|
||||||
TEXT_BUFFER_FORMAT_REC *format_rec;
|
TEXT_BUFFER_FORMAT_REC *format_rec;
|
||||||
char *text, *tmp, *str;
|
char *str;
|
||||||
|
|
||||||
curr = line;
|
curr = line;
|
||||||
line = NULL;
|
line = NULL;
|
||||||
@ -267,17 +304,18 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
|||||||
dest.flags |= PRINT_FLAG_FORMAT;
|
dest.flags |= PRINT_FLAG_FORMAT;
|
||||||
|
|
||||||
current_time = (time_t) -1;
|
current_time = (time_t) -1;
|
||||||
return str;
|
|
||||||
} else if (format_rec->format != NULL) {
|
} else if (format_rec->format != NULL) {
|
||||||
g_free(text);
|
g_free(text);
|
||||||
return NULL;
|
text = NULL;
|
||||||
} else {
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
special_fill_cache(NULL);
|
special_fill_cache(NULL);
|
||||||
} else {
|
} else {
|
||||||
return g_strdup(line->info.text);
|
format_create_dest(&dest, NULL, NULL, line->info.level, buffer->window);
|
||||||
|
text = g_strdup(line->info.text);
|
||||||
}
|
}
|
||||||
|
tmp = parse_colors(&dest, text);
|
||||||
|
g_free(text);
|
||||||
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void textbuffer_formats_init(void)
|
void textbuffer_formats_init(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user