mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-15 22:05:24 -05:00
Merge branch 'search-box-no-non-printables'
This commit is contained in:
commit
0397e91eaa
2 changed files with 17 additions and 4 deletions
|
|
@ -60,6 +60,7 @@
|
|||
size (https://codeberg.org/dnkl/foot/issues/281).
|
||||
* Extending a word/line-wise selection now uses the original selection
|
||||
mode instead of switching to character-wise.
|
||||
* The scrollback search box no longer accepts non-printable characters.
|
||||
|
||||
|
||||
### Deprecated
|
||||
|
|
|
|||
20
search.c
20
search.c
|
|
@ -354,14 +354,28 @@ search_find_next(struct terminal *term)
|
|||
void
|
||||
search_add_chars(struct terminal *term, const char *src, size_t count)
|
||||
{
|
||||
const char *_src = src;
|
||||
mbstate_t ps = {0};
|
||||
size_t wchars = mbsnrtowcs(NULL, &src, count, 0, &ps);
|
||||
size_t wchars = mbsnrtowcs(NULL, &_src, count, 0, &ps);
|
||||
|
||||
if (wchars == -1) {
|
||||
LOG_ERRNO("failed to convert %.*s to wchars", (int)count, src);
|
||||
return;
|
||||
}
|
||||
|
||||
_src = src;
|
||||
ps = (mbstate_t){0};
|
||||
wchar_t wcs[wchars + 1];
|
||||
mbsnrtowcs(wcs, &_src, count, wchars, &ps);
|
||||
|
||||
/* Strip non-printable characters */
|
||||
for (size_t i = 0, j = 0, orig_wchars = wchars; i < orig_wchars; i++) {
|
||||
if (iswprint(wcs[i]))
|
||||
wcs[j++] = wcs[i];
|
||||
else
|
||||
wchars--;
|
||||
}
|
||||
|
||||
if (!search_ensure_size(term, term->search.len + wchars))
|
||||
return;
|
||||
|
||||
|
|
@ -371,9 +385,7 @@ search_add_chars(struct terminal *term, const char *src, size_t count)
|
|||
&term->search.buf[term->search.cursor],
|
||||
(term->search.len - term->search.cursor) * sizeof(wchar_t));
|
||||
|
||||
memset(&ps, 0, sizeof(ps));
|
||||
mbsnrtowcs(&term->search.buf[term->search.cursor], &src, count,
|
||||
wchars, &ps);
|
||||
memcpy(&term->search.buf[term->search.cursor], wcs, wchars * sizeof(wchar_t));
|
||||
|
||||
term->search.len += wchars;
|
||||
term->search.cursor += wchars;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue