mirror of
https://github.com/tmux/tmux.git
synced 2025-09-01 20:57:00 +00:00
Add a dedicated function to convert a line into a string and use it to simplify the search window function.
This commit is contained in:
51
window.c
51
window.c
@ -590,42 +590,21 @@ window_pane_mouse(
|
||||
char *
|
||||
window_pane_search(struct window_pane *wp, const char *searchstr)
|
||||
{
|
||||
const struct grid_cell *gc;
|
||||
const struct grid_utf8 *gu;
|
||||
char *buf, *s;
|
||||
size_t off;
|
||||
u_int i, j, k;
|
||||
struct screen *s = &wp->base;
|
||||
char *line, *ptr;
|
||||
u_int i;
|
||||
|
||||
buf = xmalloc(1);
|
||||
|
||||
for (j = 0; j < screen_size_y(&wp->base); j++) {
|
||||
off = 0;
|
||||
for (i = 0; i < screen_size_x(&wp->base); i++) {
|
||||
gc = grid_view_peek_cell(wp->base.grid, i, j);
|
||||
if (gc->flags & GRID_FLAG_UTF8) {
|
||||
gu = grid_view_peek_utf8(wp->base.grid, i, j);
|
||||
buf = xrealloc(buf, 1, off + 8);
|
||||
for (k = 0; k < UTF8_SIZE; k++) {
|
||||
if (gu->data[k] == 0xff)
|
||||
break;
|
||||
buf[off++] = gu->data[k];
|
||||
}
|
||||
} else {
|
||||
buf = xrealloc(buf, 1, off + 1);
|
||||
buf[off++] = gc->data;
|
||||
}
|
||||
}
|
||||
while (off > 0 && buf[off - 1] == ' ')
|
||||
off--;
|
||||
buf[off] = '\0';
|
||||
|
||||
if ((s = strstr(buf, searchstr)) != NULL) {
|
||||
s = section_string(buf, off, s - buf, 40);
|
||||
xfree(buf);
|
||||
return (s);
|
||||
}
|
||||
ptr = NULL;
|
||||
for (i = 0; i < screen_size_y(s); i++) {
|
||||
line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
|
||||
log_debug("XXX %s", line);
|
||||
if ((ptr = strstr(line, searchstr)) != NULL)
|
||||
break;
|
||||
xfree(line);
|
||||
}
|
||||
|
||||
xfree(buf);
|
||||
return (NULL);
|
||||
if (ptr != NULL) {
|
||||
ptr = section_string(line, strlen(ptr), ptr - line, 40);
|
||||
xfree(line);
|
||||
}
|
||||
return (ptr);
|
||||
}
|
||||
|
Reference in New Issue
Block a user