mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 20:33:46 +02:00
Moved /LASTLOG handling to lastlog.c. Added options -file <filename>
for writing lastlog to file, -window <ref#|name> for specifying which window's lastlog to print (output is always to active window) and -clear option to remove all lastlog lines from window. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1255 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
1191bc2c2c
commit
6b4a838813
8 changed files with 384 additions and 250 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
gui-textwidget.c : irssi
|
||||
|
||||
Copyright (C) 1999 Timo Sirainen
|
||||
Copyright (C) 1999-2001 Timo Sirainen
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -19,234 +19,15 @@
|
|||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "module-formats.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "misc.h"
|
||||
#include "levels.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "irc-servers.h"
|
||||
#include "fe-windows.h"
|
||||
#include "servers.h"
|
||||
#include "printtext.h"
|
||||
|
||||
#include "screen.h"
|
||||
#include "gui-windows.h"
|
||||
|
||||
static gchar *gui_window_line2text(LINE_REC *line)
|
||||
{
|
||||
GString *str;
|
||||
gint color;
|
||||
gchar *ret, *ptr, *tmp;
|
||||
|
||||
g_return_val_if_fail(line != NULL, NULL);
|
||||
|
||||
str = g_string_new(NULL);
|
||||
|
||||
color = 0;
|
||||
for (ptr = line->text; ; ptr++)
|
||||
{
|
||||
if (*ptr != 0)
|
||||
{
|
||||
g_string_append_c(str, *ptr);
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
if ((*ptr & 0x80) == 0)
|
||||
{
|
||||
/* set color */
|
||||
color = *ptr;
|
||||
g_string_sprintfa(str, "\004%c%c", (color & 0x0f)+'0',
|
||||
((color & 0xf0) >> 4)+'0');
|
||||
}
|
||||
else switch ((guchar) *ptr)
|
||||
{
|
||||
case LINE_CMD_EOL:
|
||||
case LINE_CMD_FORMAT:
|
||||
ret = str->str;
|
||||
g_string_free(str, FALSE);
|
||||
return ret;
|
||||
case LINE_CMD_CONTINUE:
|
||||
memcpy(&tmp, ptr+1, sizeof(gchar *));
|
||||
ptr = tmp-1;
|
||||
break;
|
||||
case LINE_CMD_UNDERLINE:
|
||||
g_string_append_c(str, 31);
|
||||
break;
|
||||
case LINE_CMD_COLOR0:
|
||||
g_string_sprintfa(str, "\004%c%c",
|
||||
'0', ((color & 0xf0) >> 4)+'0');
|
||||
break;
|
||||
case LINE_CMD_COLOR8:
|
||||
g_string_sprintfa(str, "\004%c%c",
|
||||
'8', ((color & 0xf0) >> 4)+'0');
|
||||
color &= 0xfff0;
|
||||
color |= 8|ATTR_COLOR8;
|
||||
break;
|
||||
case LINE_CMD_BLINK:
|
||||
color |= 0x80;
|
||||
g_string_sprintfa(str, "\004%c%c", (color & 0x0f)+'0',
|
||||
((color & 0xf0) >> 4)+'0');
|
||||
break;
|
||||
case LINE_CMD_INDENT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define LASTLOG_FLAG_NEW_LAST 0x01
|
||||
#define LASTLOG_FLAG_NEW_AWAY 0x02
|
||||
#define LASTLOG_FLAG_NOHEADERS 0x04
|
||||
#define LASTLOG_FLAG_WORD 0x08
|
||||
#define LASTLOG_FLAG_REGEXP 0x10
|
||||
|
||||
static int lastlog_parse_options(GHashTable *options, int *flags)
|
||||
{
|
||||
GSList *list, *tmp;
|
||||
int level, optlevel;
|
||||
|
||||
/* move all keys from `options' to linked list */
|
||||
list = hashtable_get_keys(options);
|
||||
|
||||
/* level can be specified in arguments.. */
|
||||
level = 0; *flags = 0;
|
||||
for (tmp = list; tmp != NULL; tmp = tmp->next) {
|
||||
char *opt = tmp->data;
|
||||
|
||||
if (strcmp(opt, "-") == 0)
|
||||
*flags |= LASTLOG_FLAG_NOHEADERS;
|
||||
else if (g_strcasecmp(opt, "new") == 0)
|
||||
*flags |= LASTLOG_FLAG_NEW_LAST;
|
||||
else if (g_strcasecmp(opt, "away") == 0)
|
||||
*flags |= LASTLOG_FLAG_NEW_AWAY;
|
||||
else if (g_strcasecmp(opt, "word") == 0)
|
||||
*flags |= LASTLOG_FLAG_WORD;
|
||||
else if (g_strcasecmp(opt, "regexp") == 0)
|
||||
*flags |= LASTLOG_FLAG_REGEXP;
|
||||
else {
|
||||
optlevel = level2bits(opt);
|
||||
if (optlevel != 0)
|
||||
level |= optlevel;
|
||||
else {
|
||||
signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN), opt);
|
||||
level = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (level == 0) level = MSGLEVEL_ALL;
|
||||
|
||||
g_slist_free(list);
|
||||
return level;
|
||||
}
|
||||
|
||||
#define lastlog_match(line, level) \
|
||||
(((line)->level & level) != 0 && ((line)->level & MSGLEVEL_LASTLOG) == 0)
|
||||
|
||||
static GList *lastlog_find_startline(GList *list, int count, int start, int level)
|
||||
{
|
||||
GList *tmp;
|
||||
|
||||
if (count <= 0) return list;
|
||||
|
||||
for (tmp = g_list_last(list); tmp != NULL; tmp = tmp->prev) {
|
||||
LINE_REC *rec = tmp->data;
|
||||
|
||||
if (!lastlog_match(rec, level))
|
||||
continue;
|
||||
|
||||
if (start > 0) {
|
||||
start--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (--count == 0)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/* SYNTAX: LASTLOG [-] [-new | -away] [-regexp | -word] [-<levels>]
|
||||
[<pattern>] [<count> [<start>]] */
|
||||
static void cmd_lastlog(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
GList *startline, *list, *tmp;
|
||||
char *str, *text, *countstr, *start;
|
||||
void *free_arg;
|
||||
struct tm *tm;
|
||||
int level, flags, count;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS,
|
||||
"lastlog", &optlist, &text, &countstr, &start))
|
||||
return;
|
||||
|
||||
if (*start == '\0' && is_numeric(text, 0)) {
|
||||
if (is_numeric(countstr, 0))
|
||||
start = countstr;
|
||||
countstr = text;
|
||||
text = "";
|
||||
}
|
||||
count = atoi(countstr);
|
||||
if (count == 0) count = -1;
|
||||
|
||||
level = lastlog_parse_options(optlist, &flags);
|
||||
if (level == -1) {
|
||||
/* error in options */
|
||||
cmd_params_free(free_arg);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((flags & LASTLOG_FLAG_NOHEADERS) == 0)
|
||||
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_START);
|
||||
|
||||
if (flags & LASTLOG_FLAG_NEW_LAST)
|
||||
startline = WINDOW_GUI(active_win)->lastlog_last_check;
|
||||
else if (flags & LASTLOG_FLAG_NEW_AWAY)
|
||||
startline = WINDOW_GUI(active_win)->lastlog_last_away;
|
||||
else
|
||||
startline = NULL;
|
||||
if (startline == NULL) startline = WINDOW_GUI(active_win)->lines;
|
||||
|
||||
list = gui_window_find_text(active_win, text, startline, flags & LASTLOG_FLAG_REGEXP, flags & LASTLOG_FLAG_WORD);
|
||||
tmp = lastlog_find_startline(list, count, atoi(start), level);
|
||||
|
||||
for (; tmp != NULL && (count < 0 || count > 0); tmp = tmp->next) {
|
||||
LINE_REC *rec = tmp->data;
|
||||
|
||||
if (!lastlog_match(rec, level))
|
||||
continue;
|
||||
count--;
|
||||
|
||||
text = gui_window_line2text(rec);
|
||||
if (settings_get_bool("timestamps"))
|
||||
printtext(NULL, NULL, MSGLEVEL_LASTLOG, "%s", text);
|
||||
else {
|
||||
tm = localtime(&rec->time);
|
||||
|
||||
str = g_strdup_printf("[%02d:%02d] %s", tm->tm_hour, tm->tm_min, text);
|
||||
printtext(NULL, NULL, MSGLEVEL_LASTLOG, "%s", str);
|
||||
g_free(str);
|
||||
}
|
||||
g_free(text);
|
||||
}
|
||||
|
||||
if ((flags & LASTLOG_FLAG_NOHEADERS) == 0)
|
||||
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_END);
|
||||
|
||||
WINDOW_GUI(active_win)->lastlog_last_check =
|
||||
g_list_last(WINDOW_GUI(active_win)->bottom_startline);
|
||||
|
||||
g_list_free(list);
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
static void cmd_scrollback(gchar *data, SERVER_REC *server, WI_ITEM_REC *item)
|
||||
{
|
||||
command_runsub("scrollback", data, server, item);
|
||||
|
|
@ -461,7 +242,7 @@ static void cmd_scrollback_status(void)
|
|||
total_lines, total_kb);
|
||||
}
|
||||
|
||||
static void sig_away_changed(IRC_SERVER_REC *server)
|
||||
static void sig_away_changed(SERVER_REC *server)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
|
|
@ -478,7 +259,6 @@ static void sig_away_changed(IRC_SERVER_REC *server)
|
|||
|
||||
void gui_textwidget_init(void)
|
||||
{
|
||||
command_bind("lastlog", NULL, (SIGNAL_FUNC) cmd_lastlog);
|
||||
command_bind("scrollback", NULL, (SIGNAL_FUNC) cmd_scrollback);
|
||||
command_bind("scrollback clear", NULL, (SIGNAL_FUNC) cmd_scrollback_clear);
|
||||
command_bind("scrollback goto", NULL, (SIGNAL_FUNC) cmd_scrollback_goto);
|
||||
|
|
@ -486,14 +266,12 @@ void gui_textwidget_init(void)
|
|||
command_bind("scrollback end", NULL, (SIGNAL_FUNC) cmd_scrollback_end);
|
||||
command_bind("scrollback redraw", NULL, (SIGNAL_FUNC) cmd_scrollback_redraw);
|
||||
command_bind("scrollback status", NULL, (SIGNAL_FUNC) cmd_scrollback_status);
|
||||
command_set_options("lastlog", "!- new away word regexp");
|
||||
|
||||
signal_add("away mode changed", (SIGNAL_FUNC) sig_away_changed);
|
||||
}
|
||||
|
||||
void gui_textwidget_deinit(void)
|
||||
{
|
||||
command_unbind("lastlog", (SIGNAL_FUNC) cmd_lastlog);
|
||||
command_unbind("scrollback", (SIGNAL_FUNC) cmd_scrollback);
|
||||
command_unbind("scrollback clear", (SIGNAL_FUNC) cmd_scrollback_clear);
|
||||
command_unbind("scrollback goto", (SIGNAL_FUNC) cmd_scrollback_goto);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue