summaryrefslogtreecommitdiff
path: root/src/fe-common/core
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2017-10-06 15:02:15 +0200
committerailin-nemui <ailin-nemui@users.noreply.github.com>2017-10-06 15:02:15 +0200
commit16d68a86ca75b73c53aa81fe6d3d36361cb35b99 (patch)
tree8f77446d85f71067876beb32658ddd47d1b22ecc /src/fe-common/core
parent1fd285dccfd43b740e88f7f4e168132387d39843 (diff)
downloadirssi-16d68a86ca75b73c53aa81fe6d3d36361cb35b99.zip
add two XSFuncs to manipulate command history entries
it is possible to use Irssi::UI::Window::get_history_entries to save the history entries, load_history_entries to load entries into the command history and delete_history_entries to remove history entries (for example to remove history selectively)
Diffstat (limited to 'src/fe-common/core')
-rw-r--r--src/fe-common/core/command-history.c55
-rw-r--r--src/fe-common/core/command-history.h2
2 files changed, 57 insertions, 0 deletions
diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c
index 5de76969..a6a800d3 100644
--- a/src/fe-common/core/command-history.c
+++ b/src/fe-common/core/command-history.c
@@ -168,6 +168,61 @@ HISTORY_REC *command_history_find_name(const char *name)
return NULL;
}
+static int history_entry_after_time_sort(const HISTORY_ENTRY_REC *a, const HISTORY_ENTRY_REC *b)
+{
+ return a->time == b->time ? 1 : a->time - b->time;
+}
+
+void command_history_load_entry(time_t history_time, HISTORY_REC *history, const char *text)
+{
+ HISTORY_ENTRY_REC *entry;
+
+ g_return_if_fail(history != NULL);
+ g_return_if_fail(text != NULL);
+
+ entry = g_new0(HISTORY_ENTRY_REC, 1);
+ entry->text = g_strdup(text);
+ entry->history = history;
+ entry->time = history_time;
+
+ history->lines++;
+
+ history_entries = g_list_insert_sorted(history_entries, entry, (GCompareFunc)history_entry_after_time_sort);
+}
+
+static int history_entry_find_func(const HISTORY_ENTRY_REC *data, const HISTORY_ENTRY_REC *user_data)
+{
+ if ((user_data->time == -1 || (data->time == user_data->time)) &&
+ (user_data->history == NULL || (data->history == user_data->history)) &&
+ g_strcmp0(data->text, user_data->text) == 0) {
+ return 0;
+ } else {
+ return -1;
+ }
+}
+
+gboolean command_history_delete_entry(time_t history_time, HISTORY_REC *history, const char *text)
+{
+ GList *link;
+ HISTORY_ENTRY_REC entry;
+
+ g_return_val_if_fail(history != NULL, FALSE);
+ g_return_val_if_fail(text != NULL, FALSE);
+
+ entry.text = text;
+ entry.history = history;
+ entry.time = history_time;
+
+ link = g_list_find_custom(history_entries, &entry, (GCompareFunc)history_entry_find_func);
+ if (link != NULL) {
+ ((HISTORY_ENTRY_REC *)link->data)->history->lines--;
+ history_list_delete_link_and_destroy(link);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
HISTORY_REC *command_history_current(WINDOW_REC *window)
{
HISTORY_REC *rec;
diff --git a/src/fe-common/core/command-history.h b/src/fe-common/core/command-history.h
index ddc8f5e6..dc4d46da 100644
--- a/src/fe-common/core/command-history.h
+++ b/src/fe-common/core/command-history.h
@@ -28,6 +28,8 @@ void command_history_init(void);
void command_history_deinit(void);
void command_history_add(HISTORY_REC *history, const char *text);
+void command_history_load_entry(time_t time, HISTORY_REC *history, const char *text);
+gboolean command_history_delete_entry(time_t history_time, HISTORY_REC *history, const char *text);
GList *command_history_list_last(HISTORY_REC *history);
GList *command_history_list_first(HISTORY_REC *history);