summaryrefslogtreecommitdiffstats
path: root/window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-06-24 22:04:18 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-06-24 22:04:18 +0000
commit096cbf2ea558c0f66ee7bdaa8316e85c3e55ee69 (patch)
tree391e8a760c20119718ef422026d3713f752ce730 /window.c
parentf4b8f00255eb4e5d1e7b5e989d8dd48f34716c46 (diff)
Add a dedicated function to convert a line into a string and use it to simplify the search window function.
Diffstat (limited to 'window.c')
-rw-r--r--window.c53
1 files changed, 16 insertions, 37 deletions
diff --git a/window.c b/window.c
index b3dcd0f1..91606f53 100644
--- a/window.c
+++ b/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;
-
- 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);
- }
+ struct screen *s = &wp->base;
+ char *line, *ptr;
+ u_int i;
+
+ 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);
}