mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 12:23:37 +02:00
Merge pull request #1079 from ailin-nemui/reformat2
reapply a theme to previous formats
This commit is contained in:
commit
86b72d5829
32 changed files with 1206 additions and 634 deletions
|
|
@ -233,6 +233,7 @@ static void event_command(const char *data)
|
|||
(data[1] == *cmdchar && data[2] == '^'))
|
||||
&& !command_hide_output++) {
|
||||
signal_add_first("print starting", (SIGNAL_FUNC) sig_stop);
|
||||
signal_add_first("print noformat", (SIGNAL_FUNC) sig_stop);
|
||||
signal_add_first("print format", (SIGNAL_FUNC) sig_stop);
|
||||
signal_add_first("print text", (SIGNAL_FUNC) sig_stop);
|
||||
}
|
||||
|
|
@ -242,6 +243,7 @@ static void event_command_last(const char *data)
|
|||
{
|
||||
if (command_hide_output && !--command_hide_output) {
|
||||
signal_remove("print starting", (SIGNAL_FUNC) sig_stop);
|
||||
signal_remove("print noformat", (SIGNAL_FUNC) sig_stop);
|
||||
signal_remove("print format", (SIGNAL_FUNC) sig_stop);
|
||||
signal_remove("print text", (SIGNAL_FUNC) sig_stop);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -850,14 +850,13 @@ char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest, time_t t)
|
|||
return linestart;
|
||||
}
|
||||
|
||||
void format_newline(WINDOW_REC *window)
|
||||
void format_newline(TEXT_DEST_REC *dest)
|
||||
{
|
||||
g_return_if_fail(window != NULL);
|
||||
g_return_if_fail(dest != NULL);
|
||||
g_return_if_fail(dest->window != NULL);
|
||||
|
||||
signal_emit_id(signal_gui_print_text, 6, window,
|
||||
GINT_TO_POINTER(-1), GINT_TO_POINTER(-1),
|
||||
GINT_TO_POINTER(GUI_PRINT_FLAG_NEWLINE),
|
||||
"", NULL);
|
||||
signal_emit_id(signal_gui_print_text, 6, dest->window, GINT_TO_POINTER(-1),
|
||||
GINT_TO_POINTER(-1), GINT_TO_POINTER(GUI_PRINT_FLAG_NEWLINE), "", dest);
|
||||
}
|
||||
|
||||
#ifndef TERM_TRUECOLOR
|
||||
|
|
@ -1223,8 +1222,14 @@ char *strip_codes(const char *input)
|
|||
return str;
|
||||
}
|
||||
|
||||
/* send a fully parsed text string for GUI to print */
|
||||
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)
|
||||
{
|
||||
THEME_REC *theme;
|
||||
char *dup, *str, *ptr, type;
|
||||
|
|
@ -1239,8 +1244,8 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
|||
|
||||
if (*str == '\0') {
|
||||
/* empty line, write line info only */
|
||||
signal_emit_id(signal_gui_print_text, 6, dest->window, GINT_TO_POINTER(fgcolor),
|
||||
GINT_TO_POINTER(bgcolor), GINT_TO_POINTER(flags), str, dest);
|
||||
handler(dest->window, GINT_TO_POINTER(fgcolor), GINT_TO_POINTER(bgcolor),
|
||||
GINT_TO_POINTER(flags), str, dest);
|
||||
}
|
||||
|
||||
while (*str != '\0') {
|
||||
|
|
@ -1260,16 +1265,14 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
|||
|
||||
if (*str != '\0' || (flags & GUI_PRINT_FLAG_CLRTOEOL)) {
|
||||
/* send the text to gui handler */
|
||||
signal_emit_id(signal_gui_print_text, 6, dest->window,
|
||||
GINT_TO_POINTER(fgcolor),
|
||||
GINT_TO_POINTER(bgcolor),
|
||||
GINT_TO_POINTER(flags), str,
|
||||
dest);
|
||||
handler(dest->window, GINT_TO_POINTER(fgcolor), GINT_TO_POINTER(bgcolor),
|
||||
GINT_TO_POINTER(flags), str, dest);
|
||||
flags &= ~(GUI_PRINT_FLAG_INDENT|GUI_PRINT_FLAG_CLRTOEOL);
|
||||
}
|
||||
|
||||
if (type == '\n') {
|
||||
format_newline(dest->window);
|
||||
handler(dest->window, GINT_TO_POINTER(-1), GINT_TO_POINTER(-1),
|
||||
GINT_TO_POINTER(GUI_PRINT_FLAG_NEWLINE), "", dest);
|
||||
fgcolor = theme->default_color;
|
||||
bgcolor = -1;
|
||||
flags &= GUI_PRINT_FLAG_INDENT|GUI_PRINT_FLAG_MONOSPACE;
|
||||
|
|
@ -1415,6 +1418,104 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
|||
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,
|
||||
int flags)
|
||||
{
|
||||
if (fg != *last_fg ||
|
||||
(flags & GUI_PRINT_FLAG_COLOR_24_FG) != (*last_flags & GUI_PRINT_FLAG_COLOR_24_FG)) {
|
||||
*last_fg = fg;
|
||||
|
||||
#ifdef TERM_TRUECOLOR
|
||||
if (flags & GUI_PRINT_FLAG_COLOR_24_FG) {
|
||||
*last_flags |= GUI_PRINT_FLAG_COLOR_24_FG;
|
||||
format_24bit_color(out, 0, fg);
|
||||
} else {
|
||||
*last_flags &= ~GUI_PRINT_FLAG_COLOR_24_FG;
|
||||
#endif
|
||||
if (fg < 0) {
|
||||
g_string_append_c(out, 4);
|
||||
g_string_append_c(out, (char) -1);
|
||||
g_string_append_c(out, FORMAT_COLOR_NOCHANGE);
|
||||
} else {
|
||||
format_ext_color(out, 0, fg);
|
||||
}
|
||||
#ifdef TERM_TRUECOLOR
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (bg != *last_bg ||
|
||||
(flags & GUI_PRINT_FLAG_COLOR_24_BG) != (*last_flags & GUI_PRINT_FLAG_COLOR_24_BG)) {
|
||||
*last_bg = bg;
|
||||
#ifdef TERM_TRUECOLOR
|
||||
if (flags & GUI_PRINT_FLAG_COLOR_24_BG) {
|
||||
*last_flags |= GUI_PRINT_FLAG_COLOR_24_BG;
|
||||
format_24bit_color(out, 1, bg);
|
||||
} else {
|
||||
*last_flags &= ~GUI_PRINT_FLAG_COLOR_24_BG;
|
||||
#endif
|
||||
if (bg < 0) {
|
||||
g_string_append_c(out, 4);
|
||||
g_string_append_c(out, FORMAT_COLOR_NOCHANGE);
|
||||
g_string_append_c(out, (char) -1);
|
||||
} else {
|
||||
format_ext_color(out, 1, bg);
|
||||
}
|
||||
#ifdef TERM_TRUECOLOR
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((flags & GUI_PRINT_FLAG_UNDERLINE) != (*last_flags & GUI_PRINT_FLAG_UNDERLINE)) {
|
||||
*last_flags ^= GUI_PRINT_FLAG_UNDERLINE;
|
||||
g_string_append_c(out, 4);
|
||||
g_string_append_c(out, FORMAT_STYLE_UNDERLINE);
|
||||
}
|
||||
if ((flags & GUI_PRINT_FLAG_REVERSE) != (*last_flags & GUI_PRINT_FLAG_REVERSE)) {
|
||||
*last_flags ^= GUI_PRINT_FLAG_REVERSE;
|
||||
g_string_append_c(out, 4);
|
||||
g_string_append_c(out, FORMAT_STYLE_REVERSE);
|
||||
}
|
||||
if ((flags & GUI_PRINT_FLAG_BLINK) != (*last_flags & GUI_PRINT_FLAG_BLINK)) {
|
||||
*last_flags ^= GUI_PRINT_FLAG_BLINK;
|
||||
g_string_append_c(out, 4);
|
||||
g_string_append_c(out, FORMAT_STYLE_BLINK);
|
||||
}
|
||||
if ((flags & GUI_PRINT_FLAG_BOLD) != (*last_flags & GUI_PRINT_FLAG_BOLD)) {
|
||||
*last_flags ^= GUI_PRINT_FLAG_BOLD;
|
||||
g_string_append_c(out, 4);
|
||||
g_string_append_c(out, FORMAT_STYLE_BOLD);
|
||||
}
|
||||
if ((flags & GUI_PRINT_FLAG_ITALIC) != (*last_flags & GUI_PRINT_FLAG_ITALIC)) {
|
||||
*last_flags ^= GUI_PRINT_FLAG_ITALIC;
|
||||
g_string_append_c(out, 4);
|
||||
g_string_append_c(out, FORMAT_STYLE_ITALIC);
|
||||
}
|
||||
if ((flags & GUI_PRINT_FLAG_MONOSPACE) != (*last_flags & GUI_PRINT_FLAG_MONOSPACE)) {
|
||||
*last_flags ^= GUI_PRINT_FLAG_MONOSPACE;
|
||||
g_string_append_c(out, 4);
|
||||
g_string_append_c(out, FORMAT_STYLE_MONOSPACE);
|
||||
}
|
||||
if (flags & GUI_PRINT_FLAG_INDENT) {
|
||||
*last_flags ^= GUI_PRINT_FLAG_INDENT;
|
||||
g_string_append_c(out, 4);
|
||||
g_string_append_c(out, FORMAT_STYLE_INDENT);
|
||||
}
|
||||
}
|
||||
|
||||
static void read_settings(void)
|
||||
{
|
||||
timestamp_level = settings_get_bool("timestamps") ? MSGLEVEL_ALL : 0;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef 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/themes.h>
|
||||
|
||||
#define GUI_PRINT_FLAG_BOLD 0x0001
|
||||
#define GUI_PRINT_FLAG_REVERSE 0x0002
|
||||
|
|
@ -35,6 +36,7 @@ struct _FORMAT_REC {
|
|||
int paramtypes[MAX_FORMAT_PARAMS];
|
||||
};
|
||||
|
||||
/* clang-format off */
|
||||
#define PRINT_FLAG_SET_LINE_START 0x0001
|
||||
#define PRINT_FLAG_SET_LINE_START_IRSSI 0x0002
|
||||
#define PRINT_FLAG_UNSET_LINE_START 0x0040
|
||||
|
|
@ -45,6 +47,9 @@ struct _FORMAT_REC {
|
|||
#define PRINT_FLAG_SET_SERVERTAG 0x0010
|
||||
#define PRINT_FLAG_UNSET_SERVERTAG 0x0020
|
||||
|
||||
#define PRINT_FLAG_FORMAT 0x0080
|
||||
/* clang-format on */
|
||||
|
||||
typedef struct _HILIGHT_REC HILIGHT_REC;
|
||||
|
||||
typedef struct _TEXT_DEST_REC {
|
||||
|
|
@ -113,7 +118,7 @@ void format_create_dest_tag(TEXT_DEST_REC *dest, void *server,
|
|||
const char *server_tag, const char *target,
|
||||
int level, WINDOW_REC *window);
|
||||
|
||||
void format_newline(WINDOW_REC *window);
|
||||
void format_newline(TEXT_DEST_REC *dest);
|
||||
|
||||
/* Return how many characters in `str' must be skipped before `len'
|
||||
characters of text is skipped. */
|
||||
|
|
@ -126,6 +131,14 @@ char *strip_codes(const char *input);
|
|||
|
||||
/* send a fully parsed text string for GUI to print */
|
||||
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_EXT1 ('0'-2)
|
||||
|
|
@ -151,6 +164,8 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text);
|
|||
int format_expand_styles(GString *out, const char **format, int *flags);
|
||||
void format_ext_color(GString *out, int bg, int color);
|
||||
void format_24bit_color(GString *out, int bg, unsigned int color);
|
||||
void format_gui_flags(GString *out, int *last_fg, int *last_bg, int *last_flags, int fg, int bg,
|
||||
int flags);
|
||||
|
||||
void formats_init(void);
|
||||
void formats_deinit(void);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ static int signal_print_noformat;
|
|||
|
||||
static int sending_print_starting;
|
||||
|
||||
static void print_line(TEXT_DEST_REC *dest, const char *text);
|
||||
static void print_line(TEXT_DEST_REC *dest, const char *text, int formatted);
|
||||
|
||||
void printformat_module_dest_args(const char *module, TEXT_DEST_REC *dest,
|
||||
int formatnum, va_list va)
|
||||
|
|
@ -63,7 +63,6 @@ void printformat_module_dest_charargs(const char *module, TEXT_DEST_REC *dest,
|
|||
int formatnum, char **arglist)
|
||||
{
|
||||
THEME_REC *theme;
|
||||
char *str;
|
||||
|
||||
theme = window_get_theme(dest->window);
|
||||
|
||||
|
|
@ -75,11 +74,6 @@ void printformat_module_dest_charargs(const char *module, TEXT_DEST_REC *dest,
|
|||
|
||||
signal_emit_id(signal_print_format, 5, theme, module,
|
||||
dest, GINT_TO_POINTER(formatnum), arglist);
|
||||
|
||||
str = format_get_text_theme_charargs(theme, module, dest,
|
||||
formatnum, arglist);
|
||||
if (str != NULL && *str != '\0') print_line(dest, str);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
void printformat_module_dest(const char *module, TEXT_DEST_REC *dest,
|
||||
|
|
@ -164,29 +158,6 @@ void printformat_module_gui(const char *module, int formatnum, ...)
|
|||
va_end(va);
|
||||
}
|
||||
|
||||
static void print_line(TEXT_DEST_REC *dest, const char *text)
|
||||
{
|
||||
THEME_REC *theme;
|
||||
char *str, *tmp, *stripped;
|
||||
|
||||
g_return_if_fail(dest != NULL);
|
||||
g_return_if_fail(text != NULL);
|
||||
|
||||
theme = window_get_theme(dest->window);
|
||||
tmp = format_get_level_tag(theme, dest);
|
||||
str = !theme->info_eol ? format_add_linestart(text, tmp) :
|
||||
format_add_lineend(text, tmp);
|
||||
g_free_not_null(tmp);
|
||||
|
||||
/* send both the formatted + stripped (for logging etc.) */
|
||||
stripped = strip_codes(str);
|
||||
signal_emit_id(signal_print_text, 3, dest, str, stripped);
|
||||
g_free_and_null(dest->hilight_color);
|
||||
|
||||
g_free(str);
|
||||
g_free(stripped);
|
||||
}
|
||||
|
||||
/* append string to `out', expand newlines. */
|
||||
static void printtext_append_str(TEXT_DEST_REC *dest, GString *out,
|
||||
const char *str)
|
||||
|
|
@ -195,7 +166,7 @@ static void printtext_append_str(TEXT_DEST_REC *dest, GString *out,
|
|||
if (*str != '\n')
|
||||
g_string_append_c(out, *str);
|
||||
else {
|
||||
print_line(dest, out->str);
|
||||
print_line(dest, out->str, 0);
|
||||
g_string_truncate(out, 0);
|
||||
}
|
||||
str++;
|
||||
|
|
@ -314,9 +285,7 @@ static void printtext_dest_args(TEXT_DEST_REC *dest, const char *text, va_list v
|
|||
}
|
||||
|
||||
str = printtext_get_args(dest, text, va);
|
||||
signal_emit_id(signal_print_noformat, 2,
|
||||
dest, str);
|
||||
print_line(dest, str);
|
||||
print_line(dest, str, 0);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
|
|
@ -361,8 +330,8 @@ void printtext_string(void *server, const char *target, int level, const char *t
|
|||
}
|
||||
|
||||
str = printtext_expand_formats(text, &dest.flags);
|
||||
print_line(&dest, str);
|
||||
g_free(str);
|
||||
print_line(&dest, str, 0);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
/* Like printtext_window(), but don't handle %s etc. */
|
||||
|
|
@ -383,8 +352,8 @@ void printtext_string_window(WINDOW_REC *window, int level, const char *text)
|
|||
}
|
||||
|
||||
str = printtext_expand_formats(text, &dest.flags);
|
||||
print_line(&dest, str);
|
||||
g_free(str);
|
||||
print_line(&dest, str, 0);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
void printtext_window(WINDOW_REC *window, int level, const char *text, ...)
|
||||
|
|
@ -476,6 +445,51 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *text)
|
|||
signal_emit_id(signal_gui_print_text_finished, 1, dest->window);
|
||||
}
|
||||
|
||||
static void sig_print_format(THEME_REC *theme, const char *module, TEXT_DEST_REC *dest,
|
||||
void *formatnump, char **arglist)
|
||||
{
|
||||
int formatnum;
|
||||
char *str;
|
||||
|
||||
formatnum = GPOINTER_TO_INT(formatnump);
|
||||
str = format_get_text_theme_charargs(theme, module, dest, formatnum, arglist);
|
||||
if (str != NULL && *str != '\0')
|
||||
print_line(dest, str, 1);
|
||||
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
static void sig_print_noformat(TEXT_DEST_REC *dest, const char *text)
|
||||
{
|
||||
THEME_REC *theme;
|
||||
char *str, *tmp, *stripped;
|
||||
|
||||
theme = window_get_theme(dest->window);
|
||||
tmp = format_get_level_tag(theme, dest);
|
||||
str = !theme->info_eol ? format_add_linestart(text, tmp) : format_add_lineend(text, tmp);
|
||||
g_free_not_null(tmp);
|
||||
|
||||
/* send both the formatted + stripped (for logging etc.) */
|
||||
stripped = strip_codes(str);
|
||||
signal_emit_id(signal_print_text, 3, dest, str, stripped);
|
||||
|
||||
g_free_and_null(dest->hilight_color);
|
||||
|
||||
g_free(str);
|
||||
g_free(stripped);
|
||||
}
|
||||
|
||||
static void print_line(TEXT_DEST_REC *dest, const char *text, int formatted)
|
||||
{
|
||||
g_return_if_fail(dest != NULL);
|
||||
g_return_if_fail(text != NULL);
|
||||
|
||||
if (!formatted)
|
||||
signal_emit_id(signal_print_noformat, 2, dest, text);
|
||||
else
|
||||
sig_print_noformat(dest, text);
|
||||
}
|
||||
|
||||
void printtext_multiline(void *server, const char *target, int level,
|
||||
const char *format, const char *text)
|
||||
{
|
||||
|
|
@ -522,6 +536,8 @@ void printtext_init(void)
|
|||
|
||||
read_settings();
|
||||
signal_add("print text", (SIGNAL_FUNC) sig_print_text);
|
||||
signal_add("print format", (SIGNAL_FUNC) sig_print_format);
|
||||
signal_add("print noformat", (SIGNAL_FUNC) sig_print_noformat);
|
||||
signal_add("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
|
||||
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
}
|
||||
|
|
@ -529,6 +545,8 @@ void printtext_init(void)
|
|||
void printtext_deinit(void)
|
||||
{
|
||||
signal_remove("print text", (SIGNAL_FUNC) sig_print_text);
|
||||
signal_remove("print format", (SIGNAL_FUNC) sig_print_format);
|
||||
signal_remove("print noformat", (SIGNAL_FUNC) sig_print_noformat);
|
||||
signal_remove("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
|
||||
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue