mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-09 10:06:20 -05:00
commit
b308e09261
12 changed files with 55 additions and 27 deletions
|
|
@ -29,6 +29,8 @@
|
|||
to add support for this. The value `set-urgency` was chosen for
|
||||
forward-compatibility, in the hopes that this proposal eventualizes
|
||||
(https://codeberg.org/dnkl/foot/issues/157).
|
||||
* **word-delimiters** option to `foot.ini`
|
||||
(https://codeberg.org/dnkl/foot/issues/156).
|
||||
|
||||
|
||||
### Changed
|
||||
|
|
|
|||
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,11 @@ in this order:
|
|||
|
||||
Default: _none_.
|
||||
|
||||
*word-delimiters*
|
||||
String of characters that act as word delimiters when selecting
|
||||
text. Note that whitespace characters are _always_ word
|
||||
delimiters, regardless of this setting. 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
|
||||
|
|
|
|||
14
main.c
14
main.c
|
|
@ -352,6 +352,13 @@ main(int argc, char *const *argv)
|
|||
LOG_INFO("arch: %s/%zu-bit, ", name.machine, sizeof(void *) * 8);
|
||||
}
|
||||
|
||||
setlocale(LC_CTYPE, "");
|
||||
LOG_INFO("locale: %s", setlocale(LC_CTYPE, NULL));
|
||||
if (!locale_is_utf8()) {
|
||||
LOG_ERR("locale is not UTF-8");
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct config conf = {NULL};
|
||||
if (!config_load(&conf, conf_path, &user_notifications, check_config)) {
|
||||
config_free(conf);
|
||||
|
|
@ -365,13 +372,6 @@ main(int argc, char *const *argv)
|
|||
|
||||
fcft_set_scaling_filter(conf.tweak.fcft_filter);
|
||||
|
||||
setlocale(LC_CTYPE, "");
|
||||
LOG_INFO("locale: %s", setlocale(LC_CTYPE, NULL));
|
||||
if (!locale_is_utf8()) {
|
||||
LOG_ERR("locale is not UTF-8");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (conf_term != NULL) {
|
||||
free(conf.term);
|
||||
conf.term = xstrdup(conf_term);
|
||||
|
|
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <syslog.h>
|
||||
#include "xmalloc.h"
|
||||
|
||||
|
|
@ -54,6 +55,12 @@ xstrdup(const char *str)
|
|||
return check_alloc(strdup(str));
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
xwcsdup(const wchar_t *str)
|
||||
{
|
||||
return check_alloc(wcsdup(str));
|
||||
}
|
||||
|
||||
char *
|
||||
xstrndup(const char *str, size_t n)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <wchar.h>
|
||||
#include "macros.h"
|
||||
|
||||
void *xmalloc(size_t size) XMALLOC;
|
||||
|
|
@ -9,3 +10,4 @@ void *xrealloc(void *ptr, size_t size);
|
|||
char *xstrdup(const char *str) XSTRDUP;
|
||||
char *xstrndup(const char *str, size_t n) XSTRDUP;
|
||||
char *xasprintf(const char *format, ...) PRINTF(1) XMALLOC;
|
||||
wchar_t *xwcsdup(const wchar_t *str) XSTRDUP;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue