config: move url-mode related options to a dedicated section, ‘url’

This commit is contained in:
Daniel Eklöf 2021-05-20 17:56:56 +02:00
parent 28d27f49bf
commit 0f483d65ce
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 140 additions and 51 deletions

View file

@ -40,9 +40,10 @@
* Unicode 13 characters U+1FB70 - U+1FB8B to list of box drawing
characters rendered by foot itself (rather than using font glyphs)
(https://codeberg.org/dnkl/foot/issues/471).
* Dedicated bell section in config, supporting multiple actions and
a new `command` action to run an arbitrary command.
* Dedicated `[bell]` section to config, supporting multiple actions
and a new `command` action to run an arbitrary command.
(https://codeberg.org/dnkl/foot/pulls/483)
* Dedicated `[url]` section to config.
* Support for setting the full 256 color palette in foot.ini
(https://codeberg.org/dnkl/foot/issues/489)
* XDG activation support, will be used by `[bell].urgent` when
@ -83,7 +84,14 @@
### Deprecated
* **bell** option in `foot.ini`; set actions in **[bell]** section instead.
* `bell` option in `foot.ini`; set actions in the `[bell]` section
instead.
* `url-launch` option in `foot.ini`; use `launch` in the `[url]`
section instead.
* `jump-label-letters` option in `foot.ini`; use `label-letters` in
the `[url]` section instead.
* `osc8-underline` option in `foot.ini`; use `osc8-underline` in the
`[url]` section instead.
### Removed

100
config.c
View file

@ -530,6 +530,26 @@ str_to_spawn_template(struct config *conf,
return true;
}
static void
deprecated_url_option(struct config *conf,
const char *old_name, const char *new_name,
const char *path, unsigned lineno)
{
LOG_WARN(
"deprecated: %s:%d: [default]: %s: use '%s' in section '[url]' instead",
path, lineno, old_name, new_name);
const char fmt[] =
"%s:%d: \033[1m%s\033[22m, use \033[1m%s\033[22m in the \033[1m[url]\033[22m section instead";
char *text = xasprintf(fmt, path, lineno, old_name, new_name);
struct user_notification deprecation = {
.kind = USER_NOTIFICATION_DEPRECATED,
.text = text,
};
tll_push_back(conf->notifications, deprecation);
}
static bool
parse_section_main(const char *key, const char *value, struct config *conf,
const char *path, unsigned lineno)
@ -773,14 +793,17 @@ parse_section_main(const char *key, const char *value, struct config *conf,
}
else if (strcmp(key, "jump-label-letters") == 0) {
deprecated_url_option(
conf, "jump-label-letters", "label-letters", path, lineno);
wchar_t *letters;
if (!str_to_wchars(value, &letters, conf, path, lineno,
"default", "jump-label-letters"))
"default", "label-letters"))
{
return false;
}
free(conf->jump_label_letters);
conf->jump_label_letters = letters;
free(conf->url.label_letters);
conf->url.label_letters = letters;
}
else if (strcmp(key, "notify") == 0) {
@ -792,7 +815,10 @@ parse_section_main(const char *key, const char *value, struct config *conf,
}
else if (strcmp(key, "url-launch") == 0) {
if (!str_to_spawn_template(conf, value, &conf->url_launch, path, lineno,
deprecated_url_option(
conf, "url-launch", "launch", path, lineno);
if (!str_to_spawn_template(conf, value, &conf->url.launch, path, lineno,
"default", "url-launch"))
{
return false;
@ -822,10 +848,13 @@ parse_section_main(const char *key, const char *value, struct config *conf,
}
else if (strcmp(key, "osc8-underline") == 0) {
deprecated_url_option(
conf, "osc8-underline", "osc8-underline", path, lineno);
if (strcmp(value, "url-mode") == 0)
conf->osc8_underline = OSC8_UNDERLINE_URL_MODE;
conf->url.osc8_underline = OSC8_UNDERLINE_URL_MODE;
else if (strcmp(value, "always") == 0)
conf->osc8_underline = OSC8_UNDERLINE_ALWAYS;
conf->url.osc8_underline = OSC8_UNDERLINE_ALWAYS;
else {
LOG_AND_NOTIFY_ERR(
"%s:%u: [default]: %s: invalid 'osc8-underline'; "
@ -938,6 +967,48 @@ parse_section_scrollback(const char *key, const char *value, struct config *conf
return true;
}
static bool
parse_section_url(const char *key, const char *value, struct config *conf,
const char *path, unsigned lineno)
{
if (strcmp(key, "launch") == 0) {
if (!str_to_spawn_template(conf, value, &conf->url.launch, path, lineno,
"url", "launch"))
{
return false;
}
}
else if (strcmp(key, "label-letters") == 0) {
wchar_t *letters;
if (!str_to_wchars(value, &letters, conf, path, lineno, "url", "letters"))
return false;
free(conf->url.label_letters);
conf->url.label_letters = letters;
}
else if (strcmp(key, "osc8-underline") == 0) {
if (strcmp(value, "url-mode") == 0)
conf->url.osc8_underline = OSC8_UNDERLINE_URL_MODE;
else if (strcmp(value, "always") == 0)
conf->url.osc8_underline = OSC8_UNDERLINE_ALWAYS;
else {
LOG_AND_NOTIFY_ERR(
"%s:%u: [url]: %s: invalid 'osc8-underline'; "
"must be one of 'url-mode', or 'always'", path, lineno, value);
return false;
}
}
else {
LOG_AND_NOTIFY_ERR("%s:%d: [url]: %s: invalid key", path, lineno, key);
return false;
}
return true;
}
static bool
parse_section_colors(const char *key, const char *value, struct config *conf,
const char *path, unsigned lineno)
@ -1962,6 +2033,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar
SECTION_MAIN,
SECTION_BELL,
SECTION_SCROLLBACK,
SECTION_URL,
SECTION_COLORS,
SECTION_CURSOR,
SECTION_MOUSE,
@ -1986,6 +2058,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar
[SECTION_MAIN] = {&parse_section_main, "main"},
[SECTION_BELL] = {&parse_section_bell, "bell"},
[SECTION_SCROLLBACK] = {&parse_section_scrollback, "scrollback"},
[SECTION_URL] = {&parse_section_url, "url"},
[SECTION_COLORS] = {&parse_section_colors, "colors"},
[SECTION_CURSOR] = {&parse_section_cursor, "cursor"},
[SECTION_MOUSE] = {&parse_section_mouse, "mouse"},
@ -2301,7 +2374,6 @@ config_load(struct config *conf, const char *conf_path,
.title = xstrdup("foot"),
.app_id = xstrdup("foot"),
.word_delimiters = xwcsdup(L",│`|:\"'()[]{}<>"),
.jump_label_letters = xwcsdup(L"sadfjklewcmpgh"),
.size = {
.type = CONF_SIZE_PX,
.width = 700,
@ -2331,6 +2403,10 @@ config_load(struct config *conf, const char *conf_path,
},
.command_focused = false,
},
.url = {
.label_letters = xwcsdup(L"sadfjklewcmpgh"),
.osc8_underline = OSC8_UNDERLINE_URL_MODE,
},
.scrollback = {
.lines = 1000,
.indicator = {
@ -2403,8 +2479,6 @@ config_load(struct config *conf, const char *conf_path,
.argv = NULL,
},
.osc8_underline = OSC8_UNDERLINE_URL_MODE,
.tweak = {
.fcft_filter = FCFT_SCALING_FILTER_LANCZOS3,
.allow_overflowing_double_width_glyphs = true,
@ -2450,8 +2524,8 @@ config_load(struct config *conf, const char *conf_path,
"notify-send -a foot -i foot ${title} ${body}");
tokenize_cmdline(conf->notify.raw_cmd, &conf->notify.argv);
conf->url_launch.raw_cmd = xstrdup("xdg-open ${url}");
tokenize_cmdline(conf->url_launch.raw_cmd, &conf->url_launch.argv);
conf->url.launch.raw_cmd = xstrdup("xdg-open ${url}");
tokenize_cmdline(conf->url.launch.raw_cmd, &conf->url.launch.argv);
tll_foreach(*initial_user_notifications, it) {
tll_push_back(conf->notifications, it->item);
@ -2557,11 +2631,9 @@ config_free(struct config conf)
free(conf.title);
free(conf.app_id);
free(conf.word_delimiters);
free(conf.jump_label_letters);
free_spawn_template(&conf.bell.command);
free(conf.scrollback.indicator.text);
free_spawn_template(&conf.notify);
free_spawn_template(&conf.url_launch);
for (size_t i = 0; i < ALEN(conf.fonts); i++) {
tll_foreach(conf.fonts[i], it) {
config_font_destroy(&it->item);
@ -2570,6 +2642,8 @@ config_free(struct config conf)
}
free(conf.server_socket_path);
free(conf.url.label_letters);
free_spawn_template(&conf.url.launch);
key_binding_list_free(&conf.bindings.key);
key_binding_list_free(&conf.bindings.search);
key_binding_list_free(&conf.bindings.url);

View file

@ -65,7 +65,6 @@ struct config {
char *title;
char *app_id;
wchar_t *word_delimiters;
wchar_t *jump_label_letters;
bool login_shell;
bool no_wait;
@ -128,6 +127,16 @@ struct config {
double multiplier;
} scrollback;
struct {
wchar_t *label_letters;
struct config_spawn_template launch;
enum {
OSC8_UNDERLINE_URL_MODE,
OSC8_UNDERLINE_ALWAYS,
} osc8_underline;
} url;
struct {
uint32_t fg;
uint32_t bg;
@ -213,12 +222,6 @@ struct config {
} selection_target;
struct config_spawn_template notify;
struct config_spawn_template url_launch;
enum {
OSC8_UNDERLINE_URL_MODE,
OSC8_UNDERLINE_ALWAYS,
} osc8_underline;
struct {
enum fcft_scaling_filter fcft_filter;

View file

@ -216,10 +216,6 @@ in this order:
text. Note that whitespace characters are _always_ word
delimiters, regardless of this setting. Default: _,│`|:"'()[]{}<>_
*jump-label-letters*
String of characters that will be when generating key sequences
for URL jump labels. Default: _sadfjklewcmpgh_.
*notify*
Command to execute to display a notification. _${title}_ and
_${body}_ will be replaced with the notification's actual _title_
@ -234,10 +230,6 @@ in this order:
Default: _notify-send -a foot -i foot ${title} ${body}_.
*url-launch*
Command to execute when opening URLs. _${url}_ will be replaced
with the actual URL. Default: _xdg-open ${url}_.
*selection-target*
Clipboard target to automatically copy selected text to. One of
*none*, *primary*, *clipboard* or *both*. Default: _primary_.
@ -248,19 +240,6 @@ in this order:
(including SMT). Note that this is not always the best value. In
some cases, the number of physical _cores_ is better.
*osc8-underline*
When to underline OSC-8 URLs. Possible values are *url-mode* and
*always*.
When set to *url-mode*, OSC-8 URLs are only highlighted in URL
mode, just like auto-detected URLs.
When set to *always*, OSC-8 URLs are always highlighted,
regardless of their other attributes (bold, italic etc). Note that
this does _not_ make them clickable.
Default: _url-mode_
# SECTION: bell
@ -321,6 +300,29 @@ in this order:
*indicator-position=none*. Default: _empty string_.
# SECTION: url
*launch*
Command to execute when opening URLs. _${url}_ will be replaced
with the actual URL. Default: _xdg-open ${url}_.
*osc8-underline*
When to underline OSC-8 URLs. Possible values are *url-mode* and
*always*.
When set to *url-mode*, OSC-8 URLs are only highlighted in URL
mode, just like auto-detected URLs.
When set to *always*, OSC-8 URLs are always highlighted,
regardless of their other attributes (bold, italic etc). Note that
this does _not_ make them clickable.
Default: _url-mode_
*label-letters*
String of characters to use when generating key sequences for URL
jump labels. Default: _sadfjklewcmpgh_.
# SECTION: cursor
This section controls the cursor style and color. Note that
@ -360,6 +362,7 @@ applications can change these at runtime.
Default: _font underline thickness_.
# SECTION: mouse
*hide-when-typing*

View file

@ -22,15 +22,12 @@
# resize-delay-ms=100
# notify=notify-send -a foot -i foot ${title} ${body}
# url-launch=xdg-open ${url}
# bold-text-in-bright=no
# bell=none
# word-delimiters=,│`|:"'()[]{}<>
# jump-label-letters=sadfjklewcmpgh
# selection-target=primary
# workers=<number of logical CPUs>
# osc8-underline=url-mode
[bell]
# urgent=no
@ -44,6 +41,10 @@
# indicator-position=relative
# indicator-format=
[url]
# launch=xdg-open ${url}
# label-letters=sadfjklewcmpgh
# osc8-underline=url-mode
[cursor]
# style=block
# color=111111 dcdccc

View file

@ -3089,7 +3089,7 @@ term_osc8_close(struct terminal *term)
struct row *row = term->grid->rows[r];
switch (term->conf->osc8_underline) {
switch (term->conf->url.osc8_underline) {
case OSC8_UNDERLINE_ALWAYS:
for (int c = start_col; c <= end_col; c++)
row->cells[c].attrs.url = true;

View file

@ -93,7 +93,7 @@ activate_url(struct seat *seat, struct terminal *term, const struct url *url)
}
if (spawn_expand_template(
&term->conf->url_launch, 1,
&term->conf->url.launch, 1,
(const char *[]){"url"},
(const char *[]){url_string},
&argc, &argv))
@ -405,7 +405,7 @@ osc8_uris(const struct terminal *term, enum url_action action, url_list_t *urls)
{
bool dont_touch_url_attr = false;
switch (term->conf->osc8_underline) {
switch (term->conf->url.osc8_underline) {
case OSC8_UNDERLINE_URL_MODE:
dont_touch_url_attr = false;
break;
@ -484,7 +484,7 @@ static void
generate_key_combos(const struct config *conf,
size_t count, wchar_t *combos[static count])
{
const wchar_t *alphabet = conf->jump_label_letters;
const wchar_t *alphabet = conf->url.label_letters;
const size_t alphabet_len = wcslen(alphabet);
size_t hints_count = 1;