#include "gui-windows.h"
#include "gui-printtext.h"
+#define DEFAULT_LASTLOG_BEFORE 3
+#define DEFAULT_LASTLOG_AFTER 3
#define MAX_LINES_WITHOUT_FORCE 1000
static void window_lastlog_clear(WINDOW_REC *window)
{
- TEXT_BUFFER_VIEW_REC *view;
- GList *tmp, *next;
+ TEXT_BUFFER_VIEW_REC *view;
+ LINE_REC *line, *next;
- screen_refresh_freeze();
+ term_refresh_freeze();
view = WINDOW_GUI(window)->view;
- for (tmp = textbuffer_view_get_lines(view); tmp != NULL; tmp = next) {
- LINE_REC *line = tmp->data;
+ line = textbuffer_view_get_lines(view);
- next = tmp->next;
- if (line->info.level & MSGLEVEL_LASTLOG)
+ while (line != NULL) {
+ next = line->next;
+
+ if (line->info.level & MSGLEVEL_LASTLOG)
textbuffer_view_remove_line(view, line);
+ line = next;
}
textbuffer_view_redraw(view);
- screen_refresh_thaw();
+ term_refresh_thaw();
}
/* Only unknown keys in `optlist' should be levels.
GList *list, *tmp;
GString *line;
char *str;
- int level, len;
+ int level, before, after, len;
level = cmd_options_get_level("lastlog", optlist);
if (level == -1) return; /* error in options */
else
startline = NULL;
- if (startline == NULL) {
- list = textbuffer_view_get_lines(WINDOW_GUI(window)->view);
- startline = list == NULL ? NULL : list->data;
+ if (startline == NULL)
+ startline = textbuffer_view_get_lines(WINDOW_GUI(window)->view);
+
+ str = g_hash_table_lookup(optlist, "#");
+ if (str != NULL) {
+ before = after = atoi(str);
+ } else {
+ str = g_hash_table_lookup(optlist, "before");
+ before = str == NULL ? 0 : *str != '\0' ?
+ atoi(str) : DEFAULT_LASTLOG_BEFORE;
+
+ str = g_hash_table_lookup(optlist, "after");
+ if (str == NULL) str = g_hash_table_lookup(optlist, "a");
+ after = str == NULL ? 0 : *str != '\0' ?
+ atoi(str) : DEFAULT_LASTLOG_AFTER;
}
list = textbuffer_find_text(WINDOW_GUI(window)->view->buffer, startline,
level, MSGLEVEL_LASTLOG,
- searchtext,
+ searchtext, before, after,
g_hash_table_lookup(optlist, "regexp") != NULL,
g_hash_table_lookup(optlist, "word") != NULL,
g_hash_table_lookup(optlist, "case") != NULL);
if (count <= 0)
tmp = list;
else {
- int pos = len-count;
-
+ int pos = len-count-start;
if (pos < 0) pos = 0;
- pos += start;
tmp = pos > len ? NULL : g_list_nth(list, pos);
len = g_list_length(tmp);
}
+ if (g_hash_table_lookup(optlist, "count") != NULL) {
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ TXT_LASTLOG_COUNT, len);
+ g_list_free(list);
+ return;
+ }
+
if (len > MAX_LINES_WITHOUT_FORCE && fhandle == -1 &&
g_hash_table_lookup(optlist, "force") == NULL) {
- printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ printformat_window(active_win,
+ MSGLEVEL_CLIENTNOTICE|MSGLEVEL_LASTLOG,
TXT_LASTLOG_TOO_LONG, len);
g_list_free(list);
return;
while (tmp != NULL && (count < 0 || count > 0)) {
LINE_REC *rec = tmp->data;
+ if (rec == NULL) {
+ if (tmp->next == NULL)
+ break;
+ if (fhandle != -1) {
+ write(fhandle, "--\n", 3);
+ } else {
+ printformat_window(active_win,
+ MSGLEVEL_LASTLOG,
+ TXT_LASTLOG_SEPARATOR);
+ }
+ tmp = tmp->next;
+ continue;
+ }
+
/* get the line text */
textbuffer_line2text(rec, fhandle == -1, line);
if (!settings_get_bool("timestamps")) {
g_list_free(list);
}
-/* SYNTAX: LASTLOG [-] [-file <filename>] [-clear] [-<level> -<level...>]
- [-new | -away] [-regexp | -word] [-case]
- [-window <ref#|name>] [<pattern>] [<count> [<start>]] */
+/* SYNTAX: LASTLOG [-] [-file <filename>] [-window <ref#|name>] [-new | -away]
+ [-<level> -<level...>] [-clear] [-count] [-case]
+ [-regexp | -word] [-before [<#>]] [-after [<#>]]
+ [-<# before+after>] [<pattern>] [<count> [<start>]] */
static void cmd_lastlog(const char *data)
{
GHashTable *optlist;
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))
+ 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;
+ if (*start == '\0' && is_numeric(text, 0) && *text != '0' &&
+ (*countstr == '\0' || is_numeric(countstr, 0))) {
+ start = countstr;
countstr = text;
text = "";
}
{
command_bind("lastlog", NULL, (SIGNAL_FUNC) cmd_lastlog);
- command_set_options("lastlog", "!- force clear -file -window new away word regexp case");
+ command_set_options("lastlog", "!- # force clear -file -window new away word regexp case count @a @after @before");
}
void lastlog_deinit(void)