mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
config: add ‘[default].word-delimiters’
This option lets the user configure which characters act as word delimiters when selecting text. This affects both “double clicking”, and ‘ctrl-w’ in scrollback search mode. Closes #156
This commit is contained in:
parent
8aba25a477
commit
49f4b3da64
8 changed files with 36 additions and 20 deletions
19
config.c
19
config.c
|
|
@ -570,6 +570,21 @@ parse_section_main(const char *key, const char *value, struct config *conf,
|
|||
conf->render_worker_count = count;
|
||||
}
|
||||
|
||||
else if (strcmp(key, "word-delimiters") == 0) {
|
||||
size_t chars = mbstowcs(NULL, value, 0);
|
||||
if (chars == (size_t)-1) {
|
||||
LOG_AND_NOTIFY_ERR(
|
||||
"%s:%d: [default]: word-delimiters: invalid string: %s",
|
||||
path, lineno, value);
|
||||
return false;
|
||||
}
|
||||
|
||||
free(conf->word_delimiters);
|
||||
|
||||
conf->word_delimiters = xmalloc((chars + 1) * sizeof(wchar_t));
|
||||
mbstowcs(conf->word_delimiters, value, chars + 1);
|
||||
}
|
||||
|
||||
else if (strcmp(key, "scrollback") == 0) {
|
||||
LOG_WARN("deprecated: %s:%d: [default]: scrollback: use 'scrollback.lines' instead'", path, lineno);
|
||||
|
||||
|
|
@ -648,7 +663,7 @@ parse_section_scrollback(const char *key, const char *value, struct config *conf
|
|||
}
|
||||
|
||||
conf->scrollback.indicator.text = xcalloc(len + 1, sizeof(wchar_t));
|
||||
mbstowcs(conf->scrollback.indicator.text, value, len);
|
||||
mbstowcs(conf->scrollback.indicator.text, value, len + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1872,6 +1887,7 @@ config_load(struct config *conf, const char *conf_path,
|
|||
.shell = get_shell(),
|
||||
.title = xstrdup("foot"),
|
||||
.app_id = xstrdup("foot"),
|
||||
.word_delimiters = xwcsdup(L",│`|:\"'()[]{}<>"),
|
||||
.size = {
|
||||
.type = CONF_SIZE_PX,
|
||||
.px = {
|
||||
|
|
@ -2024,6 +2040,7 @@ config_free(struct config conf)
|
|||
free(conf.shell);
|
||||
free(conf.title);
|
||||
free(conf.app_id);
|
||||
free(conf.word_delimiters);
|
||||
free(conf.scrollback.indicator.text);
|
||||
tll_foreach(conf.fonts, it)
|
||||
config_font_destroy(&it->item);
|
||||
|
|
|
|||
1
config.h
1
config.h
|
|
@ -53,6 +53,7 @@ struct config {
|
|||
char *shell;
|
||||
char *title;
|
||||
char *app_id;
|
||||
wchar_t *word_delimiters;
|
||||
bool login_shell;
|
||||
|
||||
struct {
|
||||
|
|
|
|||
|
|
@ -110,6 +110,10 @@ in this order:
|
|||
|
||||
Default: _none_.
|
||||
|
||||
*word-delimiters*
|
||||
String of characters that act as word delimiters when selecting
|
||||
text. Default: _,│`|:"'()[]{}<>_
|
||||
|
||||
|
||||
# SECTION: scrollback
|
||||
|
||||
|
|
|
|||
1
foot.ini
1
foot.ini
|
|
@ -10,6 +10,7 @@
|
|||
# login-shell=no
|
||||
# workers=<number of logical CPUs>
|
||||
# bell=none
|
||||
# word-delimiters=,│`|:"'()[]{}<>
|
||||
|
||||
[scrollback]
|
||||
# lines=1000
|
||||
|
|
|
|||
17
misc.c
17
misc.c
|
|
@ -3,22 +3,13 @@
|
|||
#include <wctype.h>
|
||||
|
||||
bool
|
||||
isword(wchar_t wc, bool spaces_only)
|
||||
isword(wchar_t wc, bool spaces_only, const wchar_t *delimiters)
|
||||
{
|
||||
if (spaces_only)
|
||||
return iswgraph(wc);
|
||||
|
||||
switch (wc) {
|
||||
default: return iswgraph(wc);
|
||||
|
||||
case L'(': case L')':
|
||||
case L'[': case L']':
|
||||
case L'{': case L'}':
|
||||
case L'<': case L'>':
|
||||
case L'│': case L'|':
|
||||
case L',':
|
||||
case L'`': case L'"': case L'\'':
|
||||
case L':':
|
||||
if (wcschr(delimiters, wc) != NULL)
|
||||
return false;
|
||||
}
|
||||
|
||||
return iswgraph(wc);
|
||||
}
|
||||
|
|
|
|||
2
misc.h
2
misc.h
|
|
@ -3,4 +3,4 @@
|
|||
#include <stdbool.h>
|
||||
#include <wchar.h>
|
||||
|
||||
bool isword(wchar_t wc, bool spaces_only);
|
||||
bool isword(wchar_t wc, bool spaces_only, const wchar_t *delimiters);
|
||||
|
|
|
|||
3
search.c
3
search.c
|
|
@ -10,6 +10,7 @@
|
|||
#define LOG_MODULE "search"
|
||||
#define LOG_ENABLE_DBG 0
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
#include "grid.h"
|
||||
#include "input.h"
|
||||
#include "misc.h"
|
||||
|
|
@ -368,7 +369,7 @@ search_match_to_end_of_word(struct terminal *term, bool spaces_only)
|
|||
bool done = false;
|
||||
for (; end_col < term->cols; end_col++) {
|
||||
wchar_t wc = row->cells[end_col].wc;
|
||||
if (wc == 0 || (!first && !isword(wc, spaces_only))) {
|
||||
if (wc == 0 || (!first && !isword(wc, spaces_only, term->conf->word_delimiters))) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include "log.h"
|
||||
|
||||
#include "async.h"
|
||||
#include "config.h"
|
||||
#include "extract.h"
|
||||
#include "grid.h"
|
||||
#include "misc.h"
|
||||
|
|
@ -725,7 +726,7 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row,
|
|||
const struct row *r = grid_row_in_view(term->grid, start.row);
|
||||
wchar_t c = r->cells[start.col].wc;
|
||||
|
||||
if (!(c == 0 || !isword(c, spaces_only))) {
|
||||
if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) {
|
||||
while (true) {
|
||||
int next_col = start.col - 1;
|
||||
int next_row = start.row;
|
||||
|
|
@ -740,7 +741,7 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row,
|
|||
const struct row *row = grid_row_in_view(term->grid, next_row);
|
||||
|
||||
c = row->cells[next_col].wc;
|
||||
if (c == 0 || !isword(c, spaces_only))
|
||||
if (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))
|
||||
break;
|
||||
|
||||
start.col = next_col;
|
||||
|
|
@ -751,7 +752,7 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row,
|
|||
r = grid_row_in_view(term->grid, end.row);
|
||||
c = r->cells[end.col].wc;
|
||||
|
||||
if (!(c == 0 || !isword(c, spaces_only))) {
|
||||
if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) {
|
||||
while (true) {
|
||||
int next_col = end.col + 1;
|
||||
int next_row = end.row;
|
||||
|
|
@ -766,7 +767,7 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row,
|
|||
const struct row *row = grid_row_in_view(term->grid, next_row);
|
||||
|
||||
c = row->cells[next_col].wc;
|
||||
if (c == '\0' || !isword(c, spaces_only))
|
||||
if (c == '\0' || !isword(c, spaces_only, term->conf->word_delimiters))
|
||||
break;
|
||||
|
||||
end.col = next_col;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue