xC: revise configuration options

This commit constitutes a breaking change to old configurations.

All behaviour.* options have now become general.*, with the following
few renames as exceptions:

 - editor_command -> editor
 - backlog_helper -> pager
 - backlog_helper_strip_formatting -> pager_strip_formatting
This commit is contained in:
Přemysl Eric Janouch 2022-08-26 03:43:32 +02:00
parent a32916ffcf
commit dc002a2db4
Signed by: p
GPG Key ID: A0420B94F92B9493
4 changed files with 110 additions and 104 deletions

6
NEWS
View File

@ -1,6 +1,10 @@
Unreleased
* xC: improved backlog helper integration capabilities
* xC: all behaviour.* configuration options have been renamed to general.*,
with the exception of editor_command/editor, backlog_helper/pager,
and backlog_helper_strip_formatting/pager_strip_formatting
* xC: improved pager integration capabilities
* xC: made it show WALLOPS messages, as PRIVMSG for the server buffer

View File

@ -161,9 +161,9 @@ black-on-white and white-on-black terminals, or anything wild in between.
Assuming that your build supports Lua plugins, and that you have a decent,
properly set-up terminal emulator, it suffices to run:
/set behaviour.backlog_helper = Press Tab here and change +Gb to +Gb1d
/set behaviour.date_change_line = "%a %e %b %Y"
/set behaviour.plugin_autoload += "fancy-prompt.lua"
/set general.pager = Press Tab here and change +Gb to +Gb1d
/set general.date_change_line = "%a %e %b %Y"
/set general.plugin_autoload += "fancy-prompt.lua"
/set attributes.userhost = "\x1b[38;5;109m"
/set attributes.join = "\x1b[38;5;108m"
/set attributes.part = "\x1b[38;5;138m"

View File

@ -105,7 +105,7 @@ _~/.config/xC/xC.conf_::
as the */set* command, to make changes in it.
_~/.local/share/xC/logs/_::
When enabled by *behaviour.logging*, log files are stored here.
When enabled by *general.logging*, log files are stored here.
_~/.local/share/xC/plugins/_::
_/usr/local/share/xC/plugins/_::

200
xC.c
View File

@ -2085,7 +2085,7 @@ struct app_context
bool in_bracketed_paste; ///< User is pasting some content
struct str input_buffer; ///< Buffered pasted content
bool running_backlog_helper; ///< Running a backlog helper
bool running_pager; ///< Running a pager for buffer history
bool running_editor; ///< Running editor for the input
char *editor_filename; ///< The file being edited by user
int terminal_suspended; ///< Terminal suspension level
@ -2420,18 +2420,65 @@ static struct config_schema g_config_server[] =
{}
};
static struct config_schema g_config_behaviour[] =
static struct config_schema g_config_general[] =
{
{ .name = "save_on_quit",
.comment = "Save configuration before quitting",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "on" },
{ .name = "debug_mode",
.comment = "Produce some debugging output",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "off",
.on_change = on_config_debug_mode_change },
{ .name = "logging",
.comment = "Log buffer contents to file",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "off",
.on_change = on_config_logging_change },
{ .name = "plugin_autoload",
.comment = "Plugins to automatically load on start",
.type = CONFIG_ITEM_STRING_ARRAY,
.validate = config_validate_nonjunk_string },
// Buffer history:
{ .name = "backlog_limit",
.comment = "Maximum number of lines stored in the backlog",
.type = CONFIG_ITEM_INTEGER,
.validate = config_validate_nonnegative,
.default_ = "1000",
.on_change = on_config_backlog_limit_change },
{ .name = "pager",
.comment = "Shell command to page buffer history (args: name [path])",
.type = CONFIG_ITEM_STRING,
.default_ = "`name=$(echo \"$1\" | sed 's/[%?:.]/\\\\&/g'); "
"prompt='?f%F:'$name'. ?db- page %db?L of %D. .(?eEND:?PB%PB\\%..)'; "
"LESSSECURE=1 less +Gb -Ps\"$prompt\" \"${2:--R}\"`" },
{ .name = "pager_strip_formatting",
.comment = "Strip terminal formatting from pager input",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "off" },
// Output adjustments:
{ .name = "beep_on_highlight",
.comment = "Ring the bell when highlighted or on a new invisible PM",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "on",
.on_change = on_config_beep_on_highlight_change },
{ .name = "date_change_line",
.comment = "Input to strftime(3) for the date change line",
.type = CONFIG_ITEM_STRING,
.default_ = "\"%F\"" },
{ .name = "isolate_buffers",
.comment = "Don't leak messages from the server and global buffers",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "off",
.on_change = on_config_isolate_buffers_change },
{ .name = "beep_on_highlight",
.comment = "Beep when highlighted or on a new invisible PM",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "on",
.on_change = on_config_beep_on_highlight_change },
{ .name = "read_marker_char",
.comment = "The character to use for the read marker line",
.type = CONFIG_ITEM_STRING,
.default_ = "\"-\"",
.validate = config_validate_nonjunk_string },
{ .name = "show_all_prefixes",
.comment = "Show all prefixes in front of nicknames",
.type = CONFIG_ITEM_BOOLEAN,
@ -2442,7 +2489,9 @@ static struct config_schema g_config_behaviour[] =
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "on",
.on_change = on_config_word_wrapping_change },
{ .name = "editor_command",
// User input:
{ .name = "editor",
.comment = "VIM: \"vim +%Bgo %F\", Emacs: \"emacs -nw +%L:%C %F\", "
"nano/micro/kakoune: \"nano/micro/kak +%L:%C %F\"",
.type = CONFIG_ITEM_STRING },
@ -2450,58 +2499,8 @@ static struct config_schema g_config_behaviour[] =
.comment = "Normalize newlines and quote the command prefix in pastes",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "on" },
{ .name = "date_change_line",
.comment = "Input to strftime(3) for the date change line",
.type = CONFIG_ITEM_STRING,
.default_ = "\"%F\"" },
{ .name = "read_marker_char",
.comment = "The character to use for the read marker line",
.type = CONFIG_ITEM_STRING,
.default_ = "\"-\"",
.validate = config_validate_nonjunk_string },
{ .name = "logging",
.comment = "Log buffer contents to file",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "off",
.on_change = on_config_logging_change },
{ .name = "save_on_quit",
.comment = "Save configuration before quitting",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "on" },
{ .name = "debug_mode",
.comment = "Produce some debugging output",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "off",
.on_change = on_config_debug_mode_change },
{ .name = "backlog_limit",
.comment = "Maximum number of lines stored in the backlog",
.type = CONFIG_ITEM_INTEGER,
.validate = config_validate_nonnegative,
.default_ = "1000",
.on_change = on_config_backlog_limit_change },
{ .name = "backlog_helper",
.comment = "Shell command to page buffer history (args: name [path])",
.type = CONFIG_ITEM_STRING,
.default_ = "`name=$(echo \"$1\" | sed 's/[%?:.]/\\\\&/g'); "
"prompt='?f%F:'$name'. ?db- page %db?L of %D. .(?eEND:?PB%PB\\%..)'; "
"LESSSECURE=1 less +Gb -Ps\"$prompt\" \"${2:--R}\"`" },
{ .name = "backlog_helper_strip_formatting",
.comment = "Strip formatting from backlog helper input",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "off" },
{ .name = "reconnect_delay_growing",
.comment = "Growing factor for reconnect delay",
.type = CONFIG_ITEM_INTEGER,
.validate = config_validate_nonnegative,
.default_ = "2" },
{ .name = "reconnect_delay_max",
.comment = "Maximum reconnect delay in seconds",
.type = CONFIG_ITEM_INTEGER,
.validate = config_validate_nonnegative,
.default_ = "600" },
// Pan-server configuration:
{ .name = "autoaway_message",
.comment = "Automated away message",
.type = CONFIG_ITEM_STRING,
@ -2511,11 +2510,16 @@ static struct config_schema g_config_behaviour[] =
.type = CONFIG_ITEM_INTEGER,
.validate = config_validate_nonnegative,
.default_ = "1800" },
{ .name = "plugin_autoload",
.comment = "Plugins to automatically load on start",
.type = CONFIG_ITEM_STRING_ARRAY,
.validate = config_validate_nonjunk_string },
{ .name = "reconnect_delay_growing",
.comment = "Growth factor for the reconnect delay",
.type = CONFIG_ITEM_INTEGER,
.validate = config_validate_nonnegative,
.default_ = "2" },
{ .name = "reconnect_delay_max",
.comment = "Maximum reconnect delay in seconds",
.type = CONFIG_ITEM_INTEGER,
.validate = config_validate_nonnegative,
.default_ = "600" },
{}
};
@ -2531,9 +2535,9 @@ static struct config_schema g_config_attributes[] =
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void
load_config_behaviour (struct config_item *subtree, void *user_data)
load_config_general (struct config_item *subtree, void *user_data)
{
config_schema_apply_to_object (g_config_behaviour, subtree, user_data);
config_schema_apply_to_object (g_config_general, subtree, user_data);
}
static void
@ -2550,7 +2554,7 @@ register_config_modules (struct app_context *ctx)
config_register_module (config, "servers", NULL, NULL);
config_register_module (config, "aliases", NULL, NULL);
config_register_module (config, "plugins", NULL, NULL);
config_register_module (config, "behaviour", load_config_behaviour, ctx);
config_register_module (config, "general", load_config_general, ctx);
config_register_module (config, "attributes", load_config_attributes, ctx);
}
@ -3923,7 +3927,7 @@ buffer_update_time (struct app_context *ctx, time_t now, FILE *stream,
char buf[64] = "";
const char *format =
get_config_string (ctx->config.root, "behaviour.date_change_line");
get_config_string (ctx->config.root, "general.date_change_line");
if (!strftime (buf, sizeof buf, format, &current))
{
print_error ("%s: %s", "strftime", strerror (errno));
@ -4300,8 +4304,8 @@ buffer_print_read_marker (struct app_context *ctx, FILE *stream, int flush_opts)
{
struct formatter f = formatter_make (ctx, NULL);
const int timestamp_width = 8; // hardcoded to %T right now, simple
const char *marker_char = get_config_string (ctx->config.root,
"behaviour.read_marker_char");
const char *marker_char =
get_config_string (ctx->config.root, "general.read_marker_char");
// We could turn this off on FLUSH_OPT_NOWRAP, however our default pager
// wraps lines for us even if we don't do it ourselves, and thus there's
@ -4911,8 +4915,8 @@ static int64_t
irc_get_reconnect_delay (struct server *s)
{
int64_t delay = get_config_integer (s->config, "reconnect_delay");
int64_t delay_factor = get_config_integer (s->ctx->config.root,
"behaviour.reconnect_delay_growing");
int64_t delay_factor = get_config_integer
(s->ctx->config.root, "general.reconnect_delay_growing");
for (unsigned i = 0; i < s->reconnect_attempt; i++)
{
if (delay_factor && delay > INT64_MAX / delay_factor)
@ -4920,8 +4924,8 @@ irc_get_reconnect_delay (struct server *s)
delay *= delay_factor;
}
int64_t delay_max = get_config_integer (s->ctx->config.root,
"behaviour.reconnect_delay_max");
int64_t delay_max =
get_config_integer (s->ctx->config.root, "general.reconnect_delay_max");
return MIN (delay, delay_max);
}
@ -10992,8 +10996,8 @@ plugin_unload (struct app_context *ctx, const char *name)
static void
load_plugins (struct app_context *ctx)
{
const char *plugins = get_config_string
(ctx->config.root, "behaviour.plugin_autoload");
const char *plugins =
get_config_string (ctx->config.root, "general.plugin_autoload");
if (plugins)
{
struct strv v = strv_make ();
@ -13233,8 +13237,7 @@ static struct strv
build_editor_command (struct app_context *ctx, const char *filename)
{
struct strv argv = strv_make ();
const char *editor = get_config_string
(ctx->config.root, "behaviour.editor_command");
const char *editor = get_config_string (ctx->config.root, "general.editor");
if (!editor)
{
const char *command;
@ -13242,8 +13245,8 @@ build_editor_command (struct app_context *ctx, const char *filename)
&& !(command = getenv ("EDITOR")))
command = "vi";
// Although most visual editors support a "+LINE" argument (every
// editor mentioned in the default value of behaviour.editor_command,
// Although most visual editors support a "+LINE" argument
// (every editor mentioned in the default value of general.editor,
// plus vi, mcedit, vis, ...), it isn't particularly useful by itself.
// We need to be able to specify the column number.
//
@ -13403,28 +13406,27 @@ input_editor_cleanup (struct app_context *ctx)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void
launch_backlog_helper (struct app_context *ctx, int backlog_fd,
const char *name, const char *path)
launch_pager (struct app_context *ctx,
int fd, const char *name, const char *path)
{
hard_assert (!ctx->running_backlog_helper);
hard_assert (!ctx->running_pager);
switch (spawn_helper_child (ctx))
{
case 0:
dup2 (backlog_fd, STDIN_FILENO);
dup2 (fd, STDIN_FILENO);
char *localized_name =
iconv_xstrdup (ctx->term_from_utf8, (char *) name, -1, NULL);
execl ("/bin/sh", "/bin/sh", "-c",
get_config_string (ctx->config.root, "behaviour.backlog_helper"),
get_config_string (ctx->config.root, "general.pager"),
PROGRAM_NAME, localized_name, path, NULL);
print_error ("%s: %s",
"Failed to launch backlog helper", strerror (errno));
print_error ("%s: %s", "Failed to launch pager", strerror (errno));
_exit (EXIT_FAILURE);
case -1:
log_global_error (ctx, "#s: #l",
"Failed to launch backlog helper", strerror (errno));
"Failed to launch pager", strerror (errno));
break;
default:
ctx->running_backlog_helper = true;
ctx->running_pager = true;
}
}
@ -13440,7 +13442,7 @@ display_backlog (struct app_context *ctx, int flush_opts)
}
if (!get_config_boolean (ctx->config.root,
"behaviour.backlog_helper_strip_formatting"))
"general.pager_strip_formatting"))
flush_opts |= FLUSH_OPT_RAW;
struct buffer *buffer = ctx->current_buffer;
@ -13460,7 +13462,7 @@ display_backlog (struct app_context *ctx, int flush_opts)
rewind (backlog);
set_cloexec (fileno (backlog));
launch_backlog_helper (ctx, fileno (backlog), buffer->name, NULL);
launch_pager (ctx, fileno (backlog), buffer->name, NULL);
fclose (backlog);
return true;
}
@ -13504,7 +13506,7 @@ on_display_full_log (int count, int key, void *user_data)
(void) fflush (buffer->log_file);
set_cloexec (fileno (full_log));
launch_backlog_helper (ctx, fileno (full_log), buffer->name, path);
launch_pager (ctx, fileno (full_log), buffer->name, path);
fclose (full_log);
free (path);
return true;
@ -13967,7 +13969,7 @@ static const char *g_first_time_help[] =
"",
"To get a list of all commands, type \x02/help\x02. To obtain",
"more information on a command or option, simply add it as",
"a parameter, e.g. \x02/help set\x02 or \x02/help behaviour.logging\x02.",
"a parameter, e.g. \x02/help set\x02 or \x02/help general.logging\x02.",
"",
"To switch between buffers, press \x02"
"F5/Ctrl-P\x02 or \x02" "F6/Ctrl-N\x02.",
@ -14174,8 +14176,8 @@ try_reap_child (struct app_context *ctx)
return true;
}
if (ctx->running_backlog_helper)
ctx->running_backlog_helper = false;
if (ctx->running_pager)
ctx->running_pager = false;
else if (!ctx->running_editor)
{
log_global_debug (ctx, "An unknown child has died");
@ -14292,7 +14294,7 @@ done:
static bool
insert_paste (struct app_context *ctx, char *paste, size_t len)
{
if (!get_config_boolean (ctx->config.root, "behaviour.process_pasted_text"))
if (!get_config_boolean (ctx->config.root, "general.process_pasted_text"))
return CALL_ (ctx->input, insert, paste);
// Without ICRNL, which Editline keeps but Readline doesn't,
@ -14379,7 +14381,7 @@ reset_autoaway (struct app_context *ctx)
// And potentially start a new auto-away timer
int64_t delay = get_config_integer
(ctx->config.root, "behaviour.autoaway_delay");
(ctx->config.root, "general.autoaway_delay");
if (delay)
poller_timer_set (&ctx->autoaway_tmr, delay * 1000);
}
@ -14389,7 +14391,7 @@ on_autoaway_timer (struct app_context *ctx)
{
// An empty message would unset any away status, so let's ignore that
const char *message = get_config_string
(ctx->config.root, "behaviour.autoaway_message");
(ctx->config.root, "general.autoaway_message");
if (!message || !*message)
return;
@ -14746,7 +14748,7 @@ main (int argc, char *argv[])
CALL (ctx.input, stop);
if (get_config_boolean (ctx.config.root, "behaviour.save_on_quit"))
if (get_config_boolean (ctx.config.root, "general.save_on_quit"))
save_configuration (&ctx);
app_context_free (&ctx);