mirror of
https://github.com/irssi/irssi.git
synced 2025-01-03 14:56:47 -05:00
Merge pull request #217 from Lohhari/lastlog-date
Added a -date parameter to /lastlog to prepend each row with the ...
This commit is contained in:
commit
ac5aebb91f
@ -14,6 +14,7 @@
|
|||||||
-clear: Removes the previous results from the active window.
|
-clear: Removes the previous results from the active window.
|
||||||
-count: Displays how many lines match.
|
-count: Displays how many lines match.
|
||||||
-case: Performs a case-sensitive matching.
|
-case: Performs a case-sensitive matching.
|
||||||
|
-date: Prepends each row with the message's date
|
||||||
-regexp: The given text pattern is a regular expression.
|
-regexp: The given text pattern is a regular expression.
|
||||||
-word: The text must match full words.
|
-word: The text must match full words.
|
||||||
-force: Forces to display the lastlog, even if it exceeds 1000 lines.
|
-force: Forces to display the lastlog, even if it exceeds 1000 lines.
|
||||||
|
@ -74,6 +74,25 @@ int cmd_options_get_level(const char *cmd, GHashTable *optlist)
|
|||||||
return retlevel;
|
return retlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void prepend_date(WINDOW_REC *window, LINE_REC *rec, GString *line)
|
||||||
|
{
|
||||||
|
THEME_REC *theme = NULL;
|
||||||
|
TEXT_DEST_REC dest = {0};
|
||||||
|
char *format = NULL, datestamp[20] = {0};
|
||||||
|
struct tm *tm = localtime(&rec->info.time);
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
theme = window->theme != NULL ? window->theme : current_theme;
|
||||||
|
format_create_dest(&dest, NULL, NULL, MSGLEVEL_LASTLOG, window);
|
||||||
|
format = format_get_text_theme(theme, MODULE_NAME, &dest, TXT_LASTLOG_DATE);
|
||||||
|
|
||||||
|
ret = strftime(datestamp, sizeof(datestamp), format, tm);
|
||||||
|
g_free(format);
|
||||||
|
if (ret <= 0) return;
|
||||||
|
|
||||||
|
g_string_prepend(line, datestamp);
|
||||||
|
}
|
||||||
|
|
||||||
static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
||||||
int start, int count, FILE *fhandle)
|
int start, int count, FILE *fhandle)
|
||||||
{
|
{
|
||||||
@ -82,7 +101,7 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
GList *list, *tmp;
|
GList *list, *tmp;
|
||||||
GString *line;
|
GString *line;
|
||||||
char *str;
|
char *str;
|
||||||
int level, before, after, len;
|
int level, before, after, len, date = FALSE;
|
||||||
|
|
||||||
level = cmd_options_get_level("lastlog", optlist);
|
level = cmd_options_get_level("lastlog", optlist);
|
||||||
if (level == -1) return; /* error in options */
|
if (level == -1) return; /* error in options */
|
||||||
@ -132,6 +151,9 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
atoi(str) : DEFAULT_LASTLOG_AFTER;
|
atoi(str) : DEFAULT_LASTLOG_AFTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_hash_table_lookup(optlist, "date") != NULL)
|
||||||
|
date = TRUE;
|
||||||
|
|
||||||
list = textbuffer_find_text(WINDOW_GUI(window)->view->buffer, startline,
|
list = textbuffer_find_text(WINDOW_GUI(window)->view->buffer, startline,
|
||||||
level, MSGLEVEL_LASTLOG,
|
level, MSGLEVEL_LASTLOG,
|
||||||
searchtext, before, after,
|
searchtext, before, after,
|
||||||
@ -199,6 +221,9 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
g_string_prepend(line, timestamp);
|
g_string_prepend(line, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (date == TRUE)
|
||||||
|
prepend_date(window, rec, line);
|
||||||
|
|
||||||
/* write to file/window */
|
/* write to file/window */
|
||||||
if (fhandle != NULL) {
|
if (fhandle != NULL) {
|
||||||
fwrite(line->str, line->len, 1, fhandle);
|
fwrite(line->str, line->len, 1, fhandle);
|
||||||
@ -223,7 +248,7 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* SYNTAX: LASTLOG [-] [-file <filename>] [-window <ref#|name>] [-new | -away]
|
/* SYNTAX: LASTLOG [-] [-file <filename>] [-window <ref#|name>] [-new | -away]
|
||||||
[-<level> -<level...>] [-clear] [-count] [-case]
|
[-<level> -<level...>] [-clear] [-count] [-case] [-date]
|
||||||
[-regexp | -word] [-before [<#>]] [-after [<#>]]
|
[-regexp | -word] [-before [<#>]] [-after [<#>]]
|
||||||
[-<# before+after>] [<pattern>] [<count> [<start>]] */
|
[-<# before+after>] [<pattern>] [<count> [<start>]] */
|
||||||
static void cmd_lastlog(const char *data)
|
static void cmd_lastlog(const char *data)
|
||||||
@ -285,7 +310,7 @@ void lastlog_init(void)
|
|||||||
{
|
{
|
||||||
command_bind("lastlog", NULL, (SIGNAL_FUNC) cmd_lastlog);
|
command_bind("lastlog", NULL, (SIGNAL_FUNC) cmd_lastlog);
|
||||||
|
|
||||||
command_set_options("lastlog", "!- # force clear -file -window new away word regexp case count @a @after @before");
|
command_set_options("lastlog", "!- # force clear -file -window new away word regexp case count date @a @after @before");
|
||||||
}
|
}
|
||||||
|
|
||||||
void lastlog_deinit(void)
|
void lastlog_deinit(void)
|
||||||
|
@ -33,6 +33,7 @@ FORMAT_REC gui_text_formats[] =
|
|||||||
{ "lastlog_start", "{hilight Lastlog}:", 0 },
|
{ "lastlog_start", "{hilight Lastlog}:", 0 },
|
||||||
{ "lastlog_end", "{hilight End of Lastlog}", 0 },
|
{ "lastlog_end", "{hilight End of Lastlog}", 0 },
|
||||||
{ "lastlog_separator", "--", 0 },
|
{ "lastlog_separator", "--", 0 },
|
||||||
|
{ "lastlog_date", "%%F ", 0 },
|
||||||
|
|
||||||
/* ---- */
|
/* ---- */
|
||||||
{ NULL, "Windows", 0 },
|
{ NULL, "Windows", 0 },
|
||||||
|
@ -10,6 +10,7 @@ enum {
|
|||||||
TXT_LASTLOG_START,
|
TXT_LASTLOG_START,
|
||||||
TXT_LASTLOG_END,
|
TXT_LASTLOG_END,
|
||||||
TXT_LASTLOG_SEPARATOR,
|
TXT_LASTLOG_SEPARATOR,
|
||||||
|
TXT_LASTLOG_DATE,
|
||||||
|
|
||||||
TXT_FILL_2,
|
TXT_FILL_2,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user