summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Bouthenot <kolter@openics.org>2005-11-13 16:59:40 +0000
committerEmmanuel Bouthenot <kolter@openics.org>2005-11-13 16:59:40 +0000
commit8cab953c6f7d96b9c0b10fc1294b351adb5ed56b (patch)
tree11285d1d4698c6280539cd3a118812fdbb69f777
parentb81fa36a5c9be46c952a2dd40b5c013dd023123c (diff)
downloadweechat-8cab953c6f7d96b9c0b10fc1294b351adb5ed56b.zip
add command /history
-rw-r--r--src/common/command.c46
-rw-r--r--src/common/command.h1
-rw-r--r--src/common/completion.c10
-rw-r--r--src/common/history.c128
-rw-r--r--src/common/weeconfig.c5
-rw-r--r--src/common/weeconfig.h1
-rw-r--r--src/gui/gui-action.c19
-rw-r--r--weechat/src/common/command.c46
-rw-r--r--weechat/src/common/command.h1
-rw-r--r--weechat/src/common/completion.c10
-rw-r--r--weechat/src/common/history.c128
-rw-r--r--weechat/src/common/weeconfig.c5
-rw-r--r--weechat/src/common/weeconfig.h1
-rw-r--r--weechat/src/gui/gui-action.c19
14 files changed, 302 insertions, 118 deletions
diff --git a/src/common/command.c b/src/common/command.c
index 57b8f47a9..fb83a89ef 100644
--- a/src/common/command.c
+++ b/src/common/command.c
@@ -73,6 +73,12 @@ t_weechat_command weechat_commands[] =
{ "help", N_("display help about commands"),
N_("[command]"), N_("command: name of a WeeChat or IRC command"),
0, 1, weechat_cmd_help, NULL },
+ { "history", N_("show buffer command history"),
+ N_("[clear | value]"),
+ N_("clear: clear history\n"
+ "value: number of history entries to show"
+ ),
+ 0, 1, weechat_cmd_history, NULL },
{ "ignore", N_("ignore IRC messages and/or hosts"),
N_("[mask [[type | command] [channel [server]]]]"),
N_(" mask: nick or host mask to ignore\n"
@@ -1585,6 +1591,46 @@ weechat_cmd_help (int argc, char **argv)
}
/*
+ * weechat_cmd_history: display current buffer history
+ */
+
+int
+weechat_cmd_history (int argc, char **argv) {
+
+ t_history *p;
+ int n;
+ int n_total;
+ int n_user = cfg_history_display_default;
+
+ if (argc == 1)
+ {
+ if (ascii_strcasecmp (argv[0], "clear") == 0)
+ {
+ history_buffer_free (gui_current_window->buffer);
+ return 0;
+ }
+ else
+ n_user = atoi (argv[0]);
+ }
+
+ if (gui_current_window->buffer->history != NULL)
+ {
+ for(n_total = 1, p = gui_current_window->buffer->history; p->next_history != NULL; p = p->next_history, n_total++);
+ for(n=0; p != NULL; p=p->prev_history, n++)
+ {
+ if (n_user > 0 && (n_total-n_user) > n)
+ continue;
+ irc_display_prefix (NULL, gui_current_window->buffer,
+ PREFIX_INFO);
+ gui_printf_nolog (gui_current_window->buffer,
+ "%s\n", p->text);
+ }
+ }
+
+ return 0;
+}
+
+/*
* weechat_cmd_ignore_display: display an ignore entry
*/
diff --git a/src/common/command.h b/src/common/command.h
index cfac06ebf..4369a4251 100644
--- a/src/common/command.h
+++ b/src/common/command.h
@@ -71,6 +71,7 @@ extern int weechat_cmd_connect (int, char **);
extern int weechat_cmd_debug (int, char **);
extern int weechat_cmd_disconnect (int, char **);
extern int weechat_cmd_help (int, char **);
+extern int weechat_cmd_history (int, char **);
extern void weechat_cmd_ignore_display (char *, t_irc_ignore *);
extern int weechat_cmd_ignore (int, char **);
extern int weechat_cmd_key (char *);
diff --git a/src/common/completion.c b/src/common/completion.c
index f4fa2a286..22f7f868a 100644
--- a/src/common/completion.c
+++ b/src/common/completion.c
@@ -230,6 +230,16 @@ completion_build_list (t_completion *completion, void *channel)
#endif
return;
}
+ if (ascii_strcasecmp (completion->base_command, "history") == 0)
+ {
+ if (completion->base_command_arg == 1)
+ weelist_add (&completion->completion_list,
+ &completion->last_completion,
+ "clear");
+ else
+ completion_stop (completion);
+ return;
+ }
if (ascii_strcasecmp (completion->base_command, "ignore") == 0)
{
/* arg 1: nicks of current channel and "*" */
diff --git a/src/common/history.c b/src/common/history.c
index 980b0d1e5..4f1113eec 100644
--- a/src/common/history.c
+++ b/src/common/history.c
@@ -73,67 +73,77 @@ void
history_add (void *buffer, char *string)
{
t_history *new_history, *ptr_history;
-
- /* add history to global history */
- new_history = (t_history *)malloc (sizeof (t_history));
- if (new_history)
- {
- new_history->text = strdup (string);
- if (cfg_log_hide_nickserv_pwd)
- history_hide_password (new_history->text);
-
- if (history_global)
- history_global->prev_history = new_history;
- else
- history_global_last = new_history;
- new_history->next_history = history_global;
- new_history->prev_history = NULL;
- history_global = new_history;
- num_history_global++;
-
- /* remove one command if necessary */
- if ((cfg_history_max_commands > 0)
- && (num_history_global > cfg_history_max_commands))
- {
- ptr_history = history_global_last->prev_history;
- history_global_last->prev_history->next_history = NULL;
- if (history_global_last->text)
- free (history_global_last->text);
- free (history_global_last);
- history_global_last = ptr_history;
- num_history_global--;
- }
+
+ if ( !history_global
+ || ( history_global
+ && ascii_strcasecmp (history_global->text, string) != 0))
+ {
+ /* add history to global history */
+ new_history = (t_history *)malloc (sizeof (t_history));
+ if (new_history)
+ {
+ new_history->text = strdup (string);
+ if (cfg_log_hide_nickserv_pwd)
+ history_hide_password (new_history->text);
+
+ if (history_global)
+ history_global->prev_history = new_history;
+ else
+ history_global_last = new_history;
+ new_history->next_history = history_global;
+ new_history->prev_history = NULL;
+ history_global = new_history;
+ num_history_global++;
+
+ /* remove one command if necessary */
+ if ((cfg_history_max_commands > 0)
+ && (num_history_global > cfg_history_max_commands))
+ {
+ ptr_history = history_global_last->prev_history;
+ history_global_last->prev_history->next_history = NULL;
+ if (history_global_last->text)
+ free (history_global_last->text);
+ free (history_global_last);
+ history_global_last = ptr_history;
+ num_history_global--;
+ }
+ }
}
- /* add history to local history */
- new_history = (t_history *)malloc (sizeof (t_history));
- if (new_history)
- {
- new_history->text = strdup (string);
- if (cfg_log_hide_nickserv_pwd)
- history_hide_password (new_history->text);
-
- if (((t_gui_buffer *)(buffer))->history)
- ((t_gui_buffer *)(buffer))->history->prev_history = new_history;
- else
- ((t_gui_buffer *)(buffer))->last_history = new_history;
- new_history->next_history = ((t_gui_buffer *)(buffer))->history;
- new_history->prev_history = NULL;
- ((t_gui_buffer *)buffer)->history = new_history;
- ((t_gui_buffer *)(buffer))->num_history++;
-
- /* remove one command if necessary */
- if ((cfg_history_max_commands > 0)
- && (((t_gui_buffer *)(buffer))->num_history > cfg_history_max_commands))
- {
- ptr_history = ((t_gui_buffer *)buffer)->last_history->prev_history;
- ((t_gui_buffer *)buffer)->last_history->prev_history->next_history = NULL;
- if (((t_gui_buffer *)buffer)->last_history->text)
- free (((t_gui_buffer *)buffer)->last_history->text);
- free (((t_gui_buffer *)buffer)->last_history);
- ((t_gui_buffer *)buffer)->last_history = ptr_history;
- ((t_gui_buffer *)(buffer))->num_history++;
- }
+ if ( !((t_gui_buffer *)(buffer))->history
+ || ( ((t_gui_buffer *)(buffer))->history
+ && ascii_strcasecmp (((t_gui_buffer *)(buffer))->history->text, string) != 0))
+ {
+ /* add history to local history */
+ new_history = (t_history *)malloc (sizeof (t_history));
+ if (new_history)
+ {
+ new_history->text = strdup (string);
+ if (cfg_log_hide_nickserv_pwd)
+ history_hide_password (new_history->text);
+
+ if (((t_gui_buffer *)(buffer))->history)
+ ((t_gui_buffer *)(buffer))->history->prev_history = new_history;
+ else
+ ((t_gui_buffer *)(buffer))->last_history = new_history;
+ new_history->next_history = ((t_gui_buffer *)(buffer))->history;
+ new_history->prev_history = NULL;
+ ((t_gui_buffer *)buffer)->history = new_history;
+ ((t_gui_buffer *)(buffer))->num_history++;
+
+ /* remove one command if necessary */
+ if ((cfg_history_max_commands > 0)
+ && (((t_gui_buffer *)(buffer))->num_history > cfg_history_max_commands))
+ {
+ ptr_history = ((t_gui_buffer *)buffer)->last_history->prev_history;
+ ((t_gui_buffer *)buffer)->last_history->prev_history->next_history = NULL;
+ if (((t_gui_buffer *)buffer)->last_history->text)
+ free (((t_gui_buffer *)buffer)->last_history->text);
+ free (((t_gui_buffer *)buffer)->last_history);
+ ((t_gui_buffer *)buffer)->last_history = ptr_history;
+ ((t_gui_buffer *)(buffer))->num_history++;
+ }
+ }
}
}
diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c
index f04b9c967..14c26a141 100644
--- a/src/common/weeconfig.c
+++ b/src/common/weeconfig.c
@@ -571,6 +571,7 @@ t_config_option weechat_options_colors[] =
int cfg_history_max_lines;
int cfg_history_max_commands;
+int cfg_history_display_default;
t_config_option weechat_options_history[] =
{ { "history_max_lines", N_("max lines in history (per window)"),
@@ -582,6 +583,10 @@ t_config_option weechat_options_history[] =
N_("maximum number of user commands in history (0 = unlimited)"),
OPTION_TYPE_INT, 0, INT_MAX, 100,
NULL, NULL, &cfg_history_max_commands, NULL, &config_change_noop },
+ { "history_display_default", N_("max commands to display"),
+ N_("maximum number of commands to display by default in history listing (0 = unlimited)"),
+ OPTION_TYPE_INT, 0, INT_MAX, 5,
+ NULL, NULL, &cfg_history_display_default, NULL, &config_change_noop },
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
};
diff --git a/src/common/weeconfig.h b/src/common/weeconfig.h
index a269d6b68..b0413c3e1 100644
--- a/src/common/weeconfig.h
+++ b/src/common/weeconfig.h
@@ -169,6 +169,7 @@ extern int cfg_col_dcc_aborted;
extern int cfg_history_max_lines;
extern int cfg_history_max_commands;
+extern int cfg_history_display_default;
extern int cfg_log_auto_server;
extern int cfg_log_auto_channel;
diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c
index 3ada510c8..14ec2b90c 100644
--- a/src/gui/gui-action.c
+++ b/src/gui/gui-action.c
@@ -688,6 +688,25 @@ gui_action_up (t_gui_window *window)
window->buffer->history;
if (window->buffer->ptr_history)
{
+ /* bash/readline like use of history */
+ if (window->buffer->ptr_history->prev_history == NULL)
+ {
+ if (window->buffer->input_buffer_size > 0)
+ {
+ window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
+ history_add (window->buffer, window->buffer->input_buffer);
+ }
+ }
+ else
+ {
+ if (window->buffer->input_buffer_size > 0)
+ {
+ window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
+ if (window->buffer->ptr_history->prev_history->text)
+ free(window->buffer->ptr_history->prev_history->text);
+ window->buffer->ptr_history->prev_history->text = strdup (window->buffer->input_buffer);
+ }
+ }
window->buffer->input_buffer_size =
strlen (window->buffer->ptr_history->text);
window->buffer->input_buffer_length =
diff --git a/weechat/src/common/command.c b/weechat/src/common/command.c
index 57b8f47a9..fb83a89ef 100644
--- a/weechat/src/common/command.c
+++ b/weechat/src/common/command.c
@@ -73,6 +73,12 @@ t_weechat_command weechat_commands[] =
{ "help", N_("display help about commands"),
N_("[command]"), N_("command: name of a WeeChat or IRC command"),
0, 1, weechat_cmd_help, NULL },
+ { "history", N_("show buffer command history"),
+ N_("[clear | value]"),
+ N_("clear: clear history\n"
+ "value: number of history entries to show"
+ ),
+ 0, 1, weechat_cmd_history, NULL },
{ "ignore", N_("ignore IRC messages and/or hosts"),
N_("[mask [[type | command] [channel [server]]]]"),
N_(" mask: nick or host mask to ignore\n"
@@ -1585,6 +1591,46 @@ weechat_cmd_help (int argc, char **argv)
}
/*
+ * weechat_cmd_history: display current buffer history
+ */
+
+int
+weechat_cmd_history (int argc, char **argv) {
+
+ t_history *p;
+ int n;
+ int n_total;
+ int n_user = cfg_history_display_default;
+
+ if (argc == 1)
+ {
+ if (ascii_strcasecmp (argv[0], "clear") == 0)
+ {
+ history_buffer_free (gui_current_window->buffer);
+ return 0;
+ }
+ else
+ n_user = atoi (argv[0]);
+ }
+
+ if (gui_current_window->buffer->history != NULL)
+ {
+ for(n_total = 1, p = gui_current_window->buffer->history; p->next_history != NULL; p = p->next_history, n_total++);
+ for(n=0; p != NULL; p=p->prev_history, n++)
+ {
+ if (n_user > 0 && (n_total-n_user) > n)
+ continue;
+ irc_display_prefix (NULL, gui_current_window->buffer,
+ PREFIX_INFO);
+ gui_printf_nolog (gui_current_window->buffer,
+ "%s\n", p->text);
+ }
+ }
+
+ return 0;
+}
+
+/*
* weechat_cmd_ignore_display: display an ignore entry
*/
diff --git a/weechat/src/common/command.h b/weechat/src/common/command.h
index cfac06ebf..4369a4251 100644
--- a/weechat/src/common/command.h
+++ b/weechat/src/common/command.h
@@ -71,6 +71,7 @@ extern int weechat_cmd_connect (int, char **);
extern int weechat_cmd_debug (int, char **);
extern int weechat_cmd_disconnect (int, char **);
extern int weechat_cmd_help (int, char **);
+extern int weechat_cmd_history (int, char **);
extern void weechat_cmd_ignore_display (char *, t_irc_ignore *);
extern int weechat_cmd_ignore (int, char **);
extern int weechat_cmd_key (char *);
diff --git a/weechat/src/common/completion.c b/weechat/src/common/completion.c
index f4fa2a286..22f7f868a 100644
--- a/weechat/src/common/completion.c
+++ b/weechat/src/common/completion.c
@@ -230,6 +230,16 @@ completion_build_list (t_completion *completion, void *channel)
#endif
return;
}
+ if (ascii_strcasecmp (completion->base_command, "history") == 0)
+ {
+ if (completion->base_command_arg == 1)
+ weelist_add (&completion->completion_list,
+ &completion->last_completion,
+ "clear");
+ else
+ completion_stop (completion);
+ return;
+ }
if (ascii_strcasecmp (completion->base_command, "ignore") == 0)
{
/* arg 1: nicks of current channel and "*" */
diff --git a/weechat/src/common/history.c b/weechat/src/common/history.c
index 980b0d1e5..4f1113eec 100644
--- a/weechat/src/common/history.c
+++ b/weechat/src/common/history.c
@@ -73,67 +73,77 @@ void
history_add (void *buffer, char *string)
{
t_history *new_history, *ptr_history;
-
- /* add history to global history */
- new_history = (t_history *)malloc (sizeof (t_history));
- if (new_history)
- {
- new_history->text = strdup (string);
- if (cfg_log_hide_nickserv_pwd)
- history_hide_password (new_history->text);
-
- if (history_global)
- history_global->prev_history = new_history;
- else
- history_global_last = new_history;
- new_history->next_history = history_global;
- new_history->prev_history = NULL;
- history_global = new_history;
- num_history_global++;
-
- /* remove one command if necessary */
- if ((cfg_history_max_commands > 0)
- && (num_history_global > cfg_history_max_commands))
- {
- ptr_history = history_global_last->prev_history;
- history_global_last->prev_history->next_history = NULL;
- if (history_global_last->text)
- free (history_global_last->text);
- free (history_global_last);
- history_global_last = ptr_history;
- num_history_global--;
- }
+
+ if ( !history_global
+ || ( history_global
+ && ascii_strcasecmp (history_global->text, string) != 0))
+ {
+ /* add history to global history */
+ new_history = (t_history *)malloc (sizeof (t_history));
+ if (new_history)
+ {
+ new_history->text = strdup (string);
+ if (cfg_log_hide_nickserv_pwd)
+ history_hide_password (new_history->text);
+
+ if (history_global)
+ history_global->prev_history = new_history;
+ else
+ history_global_last = new_history;
+ new_history->next_history = history_global;
+ new_history->prev_history = NULL;
+ history_global = new_history;
+ num_history_global++;
+
+ /* remove one command if necessary */
+ if ((cfg_history_max_commands > 0)
+ && (num_history_global > cfg_history_max_commands))
+ {
+ ptr_history = history_global_last->prev_history;
+ history_global_last->prev_history->next_history = NULL;
+ if (history_global_last->text)
+ free (history_global_last->text);
+ free (history_global_last);
+ history_global_last = ptr_history;
+ num_history_global--;
+ }
+ }
}
- /* add history to local history */
- new_history = (t_history *)malloc (sizeof (t_history));
- if (new_history)
- {
- new_history->text = strdup (string);
- if (cfg_log_hide_nickserv_pwd)
- history_hide_password (new_history->text);
-
- if (((t_gui_buffer *)(buffer))->history)
- ((t_gui_buffer *)(buffer))->history->prev_history = new_history;
- else
- ((t_gui_buffer *)(buffer))->last_history = new_history;
- new_history->next_history = ((t_gui_buffer *)(buffer))->history;
- new_history->prev_history = NULL;
- ((t_gui_buffer *)buffer)->history = new_history;
- ((t_gui_buffer *)(buffer))->num_history++;
-
- /* remove one command if necessary */
- if ((cfg_history_max_commands > 0)
- && (((t_gui_buffer *)(buffer))->num_history > cfg_history_max_commands))
- {
- ptr_history = ((t_gui_buffer *)buffer)->last_history->prev_history;
- ((t_gui_buffer *)buffer)->last_history->prev_history->next_history = NULL;
- if (((t_gui_buffer *)buffer)->last_history->text)
- free (((t_gui_buffer *)buffer)->last_history->text);
- free (((t_gui_buffer *)buffer)->last_history);
- ((t_gui_buffer *)buffer)->last_history = ptr_history;
- ((t_gui_buffer *)(buffer))->num_history++;
- }
+ if ( !((t_gui_buffer *)(buffer))->history
+ || ( ((t_gui_buffer *)(buffer))->history
+ && ascii_strcasecmp (((t_gui_buffer *)(buffer))->history->text, string) != 0))
+ {
+ /* add history to local history */
+ new_history = (t_history *)malloc (sizeof (t_history));
+ if (new_history)
+ {
+ new_history->text = strdup (string);
+ if (cfg_log_hide_nickserv_pwd)
+ history_hide_password (new_history->text);
+
+ if (((t_gui_buffer *)(buffer))->history)
+ ((t_gui_buffer *)(buffer))->history->prev_history = new_history;
+ else
+ ((t_gui_buffer *)(buffer))->last_history = new_history;
+ new_history->next_history = ((t_gui_buffer *)(buffer))->history;
+ new_history->prev_history = NULL;
+ ((t_gui_buffer *)buffer)->history = new_history;
+ ((t_gui_buffer *)(buffer))->num_history++;
+
+ /* remove one command if necessary */
+ if ((cfg_history_max_commands > 0)
+ && (((t_gui_buffer *)(buffer))->num_history > cfg_history_max_commands))
+ {
+ ptr_history = ((t_gui_buffer *)buffer)->last_history->prev_history;
+ ((t_gui_buffer *)buffer)->last_history->prev_history->next_history = NULL;
+ if (((t_gui_buffer *)buffer)->last_history->text)
+ free (((t_gui_buffer *)buffer)->last_history->text);
+ free (((t_gui_buffer *)buffer)->last_history);
+ ((t_gui_buffer *)buffer)->last_history = ptr_history;
+ ((t_gui_buffer *)(buffer))->num_history++;
+ }
+ }
}
}
diff --git a/weechat/src/common/weeconfig.c b/weechat/src/common/weeconfig.c
index f04b9c967..14c26a141 100644
--- a/weechat/src/common/weeconfig.c
+++ b/weechat/src/common/weeconfig.c
@@ -571,6 +571,7 @@ t_config_option weechat_options_colors[] =
int cfg_history_max_lines;
int cfg_history_max_commands;
+int cfg_history_display_default;
t_config_option weechat_options_history[] =
{ { "history_max_lines", N_("max lines in history (per window)"),
@@ -582,6 +583,10 @@ t_config_option weechat_options_history[] =
N_("maximum number of user commands in history (0 = unlimited)"),
OPTION_TYPE_INT, 0, INT_MAX, 100,
NULL, NULL, &cfg_history_max_commands, NULL, &config_change_noop },
+ { "history_display_default", N_("max commands to display"),
+ N_("maximum number of commands to display by default in history listing (0 = unlimited)"),
+ OPTION_TYPE_INT, 0, INT_MAX, 5,
+ NULL, NULL, &cfg_history_display_default, NULL, &config_change_noop },
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
};
diff --git a/weechat/src/common/weeconfig.h b/weechat/src/common/weeconfig.h
index a269d6b68..b0413c3e1 100644
--- a/weechat/src/common/weeconfig.h
+++ b/weechat/src/common/weeconfig.h
@@ -169,6 +169,7 @@ extern int cfg_col_dcc_aborted;
extern int cfg_history_max_lines;
extern int cfg_history_max_commands;
+extern int cfg_history_display_default;
extern int cfg_log_auto_server;
extern int cfg_log_auto_channel;
diff --git a/weechat/src/gui/gui-action.c b/weechat/src/gui/gui-action.c
index 3ada510c8..14ec2b90c 100644
--- a/weechat/src/gui/gui-action.c
+++ b/weechat/src/gui/gui-action.c
@@ -688,6 +688,25 @@ gui_action_up (t_gui_window *window)
window->buffer->history;
if (window->buffer->ptr_history)
{
+ /* bash/readline like use of history */
+ if (window->buffer->ptr_history->prev_history == NULL)
+ {
+ if (window->buffer->input_buffer_size > 0)
+ {
+ window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
+ history_add (window->buffer, window->buffer->input_buffer);
+ }
+ }
+ else
+ {
+ if (window->buffer->input_buffer_size > 0)
+ {
+ window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
+ if (window->buffer->ptr_history->prev_history->text)
+ free(window->buffer->ptr_history->prev_history->text);
+ window->buffer->ptr_history->prev_history->text = strdup (window->buffer->input_buffer);
+ }
+ }
window->buffer->input_buffer_size =
strlen (window->buffer->ptr_history->text);
window->buffer->input_buffer_length =