mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 04:13:32 +02:00
/SCROLLBACK REDRAW - redraw the contents of current window according to
active formats, ie. changing theme changes scrollback. It's still a bit buggy (can crash) with multiline formats, need to fix it as soon as I figure out where the problem is.. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@852 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
e3084d3ffa
commit
e923b1651a
12 changed files with 442 additions and 131 deletions
|
|
@ -162,7 +162,9 @@ void fe_common_core_finish_init(void)
|
|||
|
||||
signal_emit("irssi init read settings", 0);
|
||||
|
||||
#ifdef SIGPIPE
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
windows_restore();
|
||||
if (windows != NULL)
|
||||
|
|
|
|||
|
|
@ -461,7 +461,7 @@ static void sig_print_format(THEME_REC *theme, const char *module,
|
|||
|
||||
if (*str != '\0') {
|
||||
/* add the line start format */
|
||||
linestart = format_get_line_start(log_theme, dest);
|
||||
linestart = format_get_level_tag(log_theme, dest);
|
||||
tmp = str;
|
||||
str = format_add_linestart(tmp, linestart);
|
||||
g_free_not_null(linestart);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,27 @@
|
|||
static int signal_gui_print_text;
|
||||
static int hide_text_style;
|
||||
|
||||
static int timestamps, msgs_timestamps;
|
||||
static int timestamp_timeout;
|
||||
|
||||
int format_find_tag(const char *module, const char *tag)
|
||||
{
|
||||
FORMAT_REC *formats;
|
||||
int n;
|
||||
|
||||
formats = g_hash_table_lookup(default_formats, module);
|
||||
if (formats == NULL)
|
||||
return -1;
|
||||
|
||||
for (n = 0; formats[n].def != NULL; n++) {
|
||||
if (formats[n].tag != NULL &&
|
||||
g_strcasecmp(formats[n].tag, tag) == 0)
|
||||
return n;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int format_expand_styles(GString *out, char format, TEXT_DEST_REC *dest)
|
||||
{
|
||||
static const char *backs = "04261537";
|
||||
|
|
@ -286,11 +307,11 @@ char *format_get_text_theme_charargs(THEME_REC *theme, const char *module,
|
|||
char **args)
|
||||
{
|
||||
MODULE_THEME_REC *module_theme;
|
||||
FORMAT_REC *formats;
|
||||
char *text;
|
||||
|
||||
module_theme = g_hash_table_lookup(theme->modules, module);
|
||||
formats = g_hash_table_lookup(default_formats, module);
|
||||
if (module_theme == NULL)
|
||||
return NULL;
|
||||
|
||||
text = module_theme->expanded_formats[formatnum];
|
||||
return format_get_text_args(dest, text, args);
|
||||
|
|
@ -351,7 +372,7 @@ char *format_add_linestart(const char *text, const char *linestart)
|
|||
MSGLEVEL_ACTIONS | MSGLEVEL_NOTICES | MSGLEVEL_SNOTES | MSGLEVEL_CTCPS)
|
||||
|
||||
/* return the "-!- " text at the start of the line */
|
||||
char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest)
|
||||
char *format_get_level_tag(THEME_REC *theme, TEXT_DEST_REC *dest)
|
||||
{
|
||||
int format;
|
||||
|
||||
|
|
@ -365,6 +386,81 @@ char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest)
|
|||
return format_get_text_theme(theme, MODULE_NAME, dest, format);
|
||||
}
|
||||
|
||||
#define show_timestamp(level) \
|
||||
((level & (MSGLEVEL_NEVER|MSGLEVEL_LASTLOG)) == 0 && \
|
||||
(timestamps || (msgs_timestamps && ((level) & MSGLEVEL_MSGS))))
|
||||
|
||||
static char *get_timestamp(THEME_REC *theme, TEXT_DEST_REC *dest)
|
||||
{
|
||||
struct tm *tm;
|
||||
time_t t;
|
||||
int diff;
|
||||
|
||||
if (!show_timestamp(dest->level))
|
||||
return NULL;
|
||||
|
||||
t = time(NULL);
|
||||
|
||||
if (timestamp_timeout > 0) {
|
||||
diff = t - dest->window->last_timestamp;
|
||||
dest->window->last_timestamp = t;
|
||||
if (diff < timestamp_timeout)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tm = localtime(&t);
|
||||
return format_get_text_theme(theme, MODULE_NAME, dest, IRCTXT_TIMESTAMP,
|
||||
tm->tm_year+1900,
|
||||
tm->tm_mon+1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
}
|
||||
|
||||
static char *get_server_tag(THEME_REC *theme, TEXT_DEST_REC *dest)
|
||||
{
|
||||
SERVER_REC *server;
|
||||
int count = 0;
|
||||
|
||||
server = dest->server;
|
||||
|
||||
if (server == NULL || (dest->window->active != NULL &&
|
||||
dest->window->active->server == server))
|
||||
return NULL;
|
||||
|
||||
if (servers != NULL) {
|
||||
count++;
|
||||
if (servers->next != NULL)
|
||||
count++;
|
||||
}
|
||||
if (count == 2 || lookup_servers != NULL) {
|
||||
count++;
|
||||
if (lookup_servers->next != NULL)
|
||||
count++;
|
||||
}
|
||||
|
||||
return count < 2 ? NULL :
|
||||
format_get_text_theme(theme, MODULE_NAME, dest,
|
||||
IRCTXT_SERVERTAG, server->tag);
|
||||
}
|
||||
|
||||
char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest)
|
||||
{
|
||||
char *timestamp, *servertag;
|
||||
char *linestart;
|
||||
|
||||
timestamp = get_timestamp(theme, dest);
|
||||
servertag = get_server_tag(theme, dest);
|
||||
|
||||
if (timestamp == NULL && servertag == NULL)
|
||||
return NULL;
|
||||
|
||||
linestart = g_strconcat(timestamp != NULL ? timestamp : "",
|
||||
servertag, NULL);
|
||||
|
||||
g_free_not_null(timestamp);
|
||||
g_free_not_null(servertag);
|
||||
return linestart;
|
||||
}
|
||||
|
||||
void format_newline(WINDOW_REC *window)
|
||||
{
|
||||
window->lines++;
|
||||
|
|
@ -665,6 +761,9 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
|||
static void read_settings(void)
|
||||
{
|
||||
hide_text_style = settings_get_bool("hide_text_style");
|
||||
timestamps = settings_get_bool("timestamps");
|
||||
timestamp_timeout = settings_get_int("timestamp_timeout");
|
||||
msgs_timestamps = settings_get_bool("msgs_timestamps");
|
||||
}
|
||||
|
||||
void formats_init(void)
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ typedef struct {
|
|||
int level;
|
||||
} TEXT_DEST_REC;
|
||||
|
||||
int format_find_tag(const char *module, const char *tag);
|
||||
|
||||
char *format_get_text(const char *module, WINDOW_REC *window,
|
||||
void *server, const char *target,
|
||||
int formatnum, ...);
|
||||
|
|
@ -60,6 +62,9 @@ char *format_get_text_theme_charargs(THEME_REC *theme, const char *module,
|
|||
char *format_add_linestart(const char *text, const char *linestart);
|
||||
|
||||
/* return the "-!- " text at the start of the line */
|
||||
char *format_get_level_tag(THEME_REC *theme, TEXT_DEST_REC *dest);
|
||||
|
||||
/* return timestamp + server tag */
|
||||
char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ FORMAT_REC fecommon_core_formats[] = {
|
|||
/* ---- */
|
||||
{ NULL, "Windows", 0 },
|
||||
|
||||
{ "line_start", "{line_start} ", 0 },
|
||||
{ "line_start_irssi", "{line_start} {hilight Irssi:} ", 0 },
|
||||
{ "line_start", "{line_start}", 0 },
|
||||
{ "line_start_irssi", "{line_start}{hilight Irssi:} ", 0 },
|
||||
{ "timestamp", "$[-2.0]3:$[-2.0]4 ", 6, { 1, 1, 1, 1, 1, 1 } },
|
||||
{ "servertag", "[$0] ", 1, { 0 } },
|
||||
{ "daychange", "Day changed to $[-2.0]{0} $3 $2", 4, { 1, 1, 1, 0 } },
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@
|
|||
#include "printtext.h"
|
||||
|
||||
static int beep_msg_level, beep_when_away;
|
||||
static int timestamps, msgs_timestamps;
|
||||
static int timestamp_timeout;
|
||||
|
||||
static int signal_gui_print_text;
|
||||
static int signal_print_text_stripped;
|
||||
|
|
@ -120,7 +118,7 @@ static void print_line(TEXT_DEST_REC *dest, const char *text)
|
|||
g_return_if_fail(dest != NULL);
|
||||
g_return_if_fail(text != NULL);
|
||||
|
||||
tmp = format_get_line_start(current_theme, dest);
|
||||
tmp = format_get_level_tag(current_theme, dest);
|
||||
str = format_add_linestart(text, tmp);
|
||||
g_free_not_null(tmp);
|
||||
|
||||
|
|
@ -250,49 +248,6 @@ void printtext_window(WINDOW_REC *window, int level, const char *text, ...)
|
|||
g_free(str);
|
||||
}
|
||||
|
||||
#define show_timestamp(level) \
|
||||
((level & (MSGLEVEL_NEVER|MSGLEVEL_LASTLOG)) == 0 && \
|
||||
(timestamps || (msgs_timestamps && ((level) & MSGLEVEL_MSGS))))
|
||||
|
||||
static char *get_timestamp(TEXT_DEST_REC *dest)
|
||||
{
|
||||
struct tm *tm;
|
||||
time_t t;
|
||||
int diff;
|
||||
|
||||
if (!show_timestamp(dest->level))
|
||||
return NULL;
|
||||
|
||||
t = time(NULL);
|
||||
|
||||
if (timestamp_timeout > 0) {
|
||||
diff = t - dest->window->last_timestamp;
|
||||
dest->window->last_timestamp = t;
|
||||
if (diff < timestamp_timeout)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tm = localtime(&t);
|
||||
return format_get_text_theme(NULL, MODULE_NAME, dest, IRCTXT_TIMESTAMP,
|
||||
tm->tm_year+1900,
|
||||
tm->tm_mon+1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
}
|
||||
|
||||
static char *get_server_tag(TEXT_DEST_REC *dest)
|
||||
{
|
||||
SERVER_REC *server;
|
||||
|
||||
server = dest->server;
|
||||
|
||||
if (server == NULL || servers == NULL || servers->next == NULL ||
|
||||
(dest->window->active != NULL && dest->window->active->server == server))
|
||||
return NULL;
|
||||
|
||||
return format_get_text_theme(NULL, MODULE_NAME, dest,
|
||||
IRCTXT_SERVERTAG, server->tag);
|
||||
}
|
||||
|
||||
static void msg_beep_check(SERVER_REC *server, int level)
|
||||
{
|
||||
if (level != 0 && (level & MSGLEVEL_NOHILIGHT) == 0 &&
|
||||
|
|
@ -302,30 +257,9 @@ static void msg_beep_check(SERVER_REC *server, int level)
|
|||
}
|
||||
}
|
||||
|
||||
static char *fix_line_start(TEXT_DEST_REC *dest, const char *text)
|
||||
{
|
||||
char *timestamp, *servertag;
|
||||
char *linestart, *str;
|
||||
|
||||
timestamp = get_timestamp(dest);
|
||||
servertag = get_server_tag(dest);
|
||||
|
||||
if (timestamp == NULL && servertag == NULL)
|
||||
return g_strdup(text);
|
||||
|
||||
linestart = g_strconcat(timestamp != NULL ? timestamp : "",
|
||||
servertag, NULL);
|
||||
str = format_add_linestart(text, linestart);
|
||||
g_free(linestart);
|
||||
|
||||
g_free_not_null(timestamp);
|
||||
g_free_not_null(servertag);
|
||||
return str;
|
||||
}
|
||||
|
||||
static void sig_print_text(TEXT_DEST_REC *dest, const char *text)
|
||||
{
|
||||
char *str;
|
||||
char *str, *tmp;
|
||||
|
||||
g_return_if_fail(dest != NULL);
|
||||
g_return_if_fail(text != NULL);
|
||||
|
|
@ -335,7 +269,12 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *text)
|
|||
dest->window->last_line = time(NULL);
|
||||
format_newline(dest->window);
|
||||
|
||||
str = fix_line_start(dest, text);
|
||||
/* add timestamp/server tag here - if it's done in print_line()
|
||||
it would be written to log files too */
|
||||
tmp = format_get_line_start(current_theme, dest);
|
||||
str = format_add_linestart(text, tmp);
|
||||
g_free(tmp);
|
||||
|
||||
format_send_to_gui(dest, str);
|
||||
g_free(str);
|
||||
|
||||
|
|
@ -372,9 +311,6 @@ static void sig_gui_dialog(const char *type, const char *text)
|
|||
|
||||
static void read_settings(void)
|
||||
{
|
||||
timestamps = settings_get_bool("timestamps");
|
||||
timestamp_timeout = settings_get_int("timestamp_timeout");
|
||||
msgs_timestamps = settings_get_bool("msgs_timestamps");
|
||||
beep_msg_level = level2bits(settings_get_str("beep_on_msg"));
|
||||
beep_when_away = settings_get_bool("beep_when_away");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -459,25 +459,20 @@ static void theme_read_abstracts(CONFIG_REC *config, THEME_REC *theme)
|
|||
}
|
||||
|
||||
static void theme_set_format(THEME_REC *theme, MODULE_THEME_REC *rec,
|
||||
FORMAT_REC *formats,
|
||||
const char *module,
|
||||
const char *key, const char *value)
|
||||
{
|
||||
int n;
|
||||
int num;
|
||||
|
||||
for (n = 0; formats[n].def != NULL; n++) {
|
||||
if (formats[n].tag != NULL &&
|
||||
g_strcasecmp(formats[n].tag, key) == 0) {
|
||||
rec->formats[n] = g_strdup(value);
|
||||
rec->expanded_formats[n] =
|
||||
theme_format_expand(theme, value);
|
||||
break;
|
||||
}
|
||||
num = format_find_tag(module, key);
|
||||
if (num != -1) {
|
||||
rec->formats[num] = g_strdup(value);
|
||||
rec->expanded_formats[num] = theme_format_expand(theme, value);
|
||||
}
|
||||
}
|
||||
|
||||
static void theme_read_formats(THEME_REC *theme, const char *module,
|
||||
CONFIG_REC *config, FORMAT_REC *formats,
|
||||
MODULE_THEME_REC *rec)
|
||||
CONFIG_REC *config, MODULE_THEME_REC *rec)
|
||||
{
|
||||
CONFIG_NODE *node;
|
||||
GSList *tmp;
|
||||
|
|
@ -491,7 +486,7 @@ static void theme_read_formats(THEME_REC *theme, const char *module,
|
|||
node = tmp->data;
|
||||
|
||||
if (node->key != NULL && node->value != NULL) {
|
||||
theme_set_format(theme, rec, formats,
|
||||
theme_set_format(theme, rec, module,
|
||||
node->key, node->value);
|
||||
}
|
||||
}
|
||||
|
|
@ -510,7 +505,7 @@ static void theme_init_module(THEME_REC *theme, const char *module,
|
|||
rec = theme_module_create(theme, module);
|
||||
|
||||
if (config != NULL)
|
||||
theme_read_formats(theme, module, config, formats, rec);
|
||||
theme_read_formats(theme, module, config, rec);
|
||||
|
||||
/* expand the remaining formats */
|
||||
for (n = 0; n < rec->count; n++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue