1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Merge pull request #1048 from vague666/set_list_section

Make it possible to list specific section with /set
This commit is contained in:
ailin-nemui 2019-06-10 12:33:28 +02:00 committed by GitHub
commit 0ffc515264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 5 deletions

View File

@ -7,6 +7,7 @@
-clear: Removes the setting's value from the configuration. -clear: Removes the setting's value from the configuration.
-default: Restore the setting to its default value. -default: Restore the setting to its default value.
-section: Print settings under the specified section
The setting and the value; if no value is given, the list of settings that The setting and the value; if no value is given, the list of settings that
matched will be returned. If no arguments are given, all the settings will matched will be returned. If no arguments are given, all the settings will
@ -27,6 +28,7 @@
/SET -clear nick /SET -clear nick
/SET log_timestamp %%H:%%H:%%S /SET log_timestamp %%H:%%H:%%S
/SET -default log_timestamp /SET -default log_timestamp
/SET -section lookandfeel
/SET close /SET close
%9See also:%9 SAVE, TOGGLE %9See also:%9 SAVE, TOGGLE

View File

@ -69,6 +69,29 @@ static void set_print_pattern(const char *pattern)
g_slist_free(sets); g_slist_free(sets);
} }
static void set_print_section(const char *pattern)
{
GSList *sets, *tmp;
const char *last_section;
last_section = "";
sets = settings_get_sorted();
for (tmp = sets; tmp != NULL; tmp = tmp->next) {
SETTINGS_REC *rec = tmp->data;
if (stristr(rec->section, pattern) != NULL) {
if (g_strcmp0(last_section, rec->section) != 0) {
/* print section */
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
TXT_SET_TITLE, rec->section);
last_section = rec->section;
}
set_print(rec);
}
}
g_slist_free(sets);
}
static void set_boolean(const char *key, const char *value) static void set_boolean(const char *key, const char *value)
{ {
char *stripped_value; char *stripped_value;
@ -123,13 +146,13 @@ static void set_choice(const char *key, const char *value)
g_free(stripped_value); g_free(stripped_value);
} }
/* SYNTAX: SET [-clear | -default] [<key> [<value>]] */ /* SYNTAX: SET [-clear | -default | -section] [<key> [<value>]] */
static void cmd_set(char *data) static void cmd_set(char *data)
{ {
GHashTable *optlist; GHashTable *optlist;
char *key, *value; char *key, *value;
void *free_arg; void *free_arg;
int clear, set_default; int clear, set_default, list_section;
SETTINGS_REC *rec; SETTINGS_REC *rec;
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST |
@ -139,11 +162,14 @@ static void cmd_set(char *data)
clear = g_hash_table_lookup(optlist, "clear") != NULL; clear = g_hash_table_lookup(optlist, "clear") != NULL;
set_default = g_hash_table_lookup(optlist, "default") != NULL; set_default = g_hash_table_lookup(optlist, "default") != NULL;
list_section = g_hash_table_lookup(optlist, "section") != NULL;
if (*key == '\0') if (*key == '\0')
clear = set_default = FALSE; clear = set_default = list_section = FALSE;
if (!(clear || set_default || *value != '\0')) if (list_section)
set_print_section(key);
else if (!(clear || set_default || *value != '\0'))
set_print_pattern(key); set_print_pattern(key);
else { else {
rec = settings_get_record(key); rec = settings_get_record(key);
@ -408,7 +434,7 @@ void fe_settings_init(void)
command_bind("unalias", NULL, (SIGNAL_FUNC) cmd_unalias); command_bind("unalias", NULL, (SIGNAL_FUNC) cmd_unalias);
command_bind("reload", NULL, (SIGNAL_FUNC) cmd_reload); command_bind("reload", NULL, (SIGNAL_FUNC) cmd_reload);
command_bind("save", NULL, (SIGNAL_FUNC) cmd_save); command_bind("save", NULL, (SIGNAL_FUNC) cmd_save);
command_set_options("set", "clear default"); command_set_options("set", "clear default section");
signal_add("settings errors", (SIGNAL_FUNC) sig_settings_errors); signal_add("settings errors", (SIGNAL_FUNC) sig_settings_errors);
} }