aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'window.c')
-rw-r--r--window.c70
1 files changed, 48 insertions, 22 deletions
diff --git a/window.c b/window.c
index 1b30c793..e90c4e09 100644
--- a/window.c
+++ b/window.c
@@ -22,6 +22,7 @@
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
+#include <regex.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
@@ -802,6 +803,8 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->pipe_event = NULL;
wp->saved_grid = NULL;
+ wp->saved_cx = UINT_MAX;
+ wp->saved_cy = UINT_MAX;
style_set(&wp->style, &grid_default_cell);
@@ -963,10 +966,25 @@ window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc,
struct screen *s = &wp->base;
u_int sx, sy;
- if (wp->saved_grid == NULL)
- return;
if (!options_get_number(wp->window->options, "alternate-screen"))
return;
+
+ /*
+ * Restore the cursor position and cell. This happens even if not
+ * currently in the alternate screen.
+ */
+ if (cursor && wp->saved_cx != UINT_MAX && wp->saved_cy != UINT_MAX) {
+ s->cx = wp->saved_cx;
+ if (s->cx > screen_size_x(s) - 1)
+ s->cx = screen_size_x(s) - 1;
+ s->cy = wp->saved_cy;
+ if (s->cy > screen_size_y(s) - 1)
+ s->cy = screen_size_y(s) - 1;
+ memcpy(gc, &wp->saved_cell, sizeof *gc);
+ }
+
+ if (wp->saved_grid == NULL)
+ return;
sx = screen_size_x(s);
sy = screen_size_y(s);
@@ -977,17 +995,8 @@ window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc,
if (sy > wp->saved_grid->sy)
screen_resize(s, sx, wp->saved_grid->sy, 1);
- /* Restore the grid, cursor position and cell. */
+ /* Restore the saved grid. */
grid_duplicate_lines(s->grid, screen_hsize(s), wp->saved_grid, 0, sy);
- if (cursor)
- s->cx = wp->saved_cx;
- if (s->cx > screen_size_x(s) - 1)
- s->cx = screen_size_x(s) - 1;
- if (cursor)
- s->cy = wp->saved_cy;
- if (s->cy > screen_size_y(s) - 1)
- s->cy = screen_size_y(s) - 1;
- memcpy(gc, &wp->saved_cell, sizeof *gc);
/*
* Turn history back on (so resize can use it) and then resize back to
@@ -1137,7 +1146,7 @@ window_pane_reset_mode(struct window_pane *wp)
} else {
log_debug("%s: next mode is %s", __func__, next->mode->name);
wp->screen = next->screen;
- if (next != NULL && next->mode->resize != NULL)
+ if (next->mode->resize != NULL)
next->mode->resize(next, wp->sx, wp->sy);
}
wp->flags |= (PANE_REDRAW|PANE_CHANGED);
@@ -1199,24 +1208,41 @@ window_pane_visible(struct window_pane *wp)
}
u_int
-window_pane_search(struct window_pane *wp, const char *searchstr)
+window_pane_search(struct window_pane *wp, const char *term, int regex,
+ int ignore)
{
struct screen *s = &wp->base;
- char *newsearchstr, *line;
+ regex_t r;
+ char *new = NULL, *line;
u_int i;
+ int flags = 0, found;
- xasprintf(&newsearchstr, "*%s*", searchstr);
+ if (!regex) {
+ if (ignore)
+ flags |= FNM_CASEFOLD;
+ xasprintf(&new, "*%s*", term);
+ } else {
+ if (ignore)
+ flags |= REG_ICASE;
+ if (regcomp(&r, term, flags|REG_EXTENDED) != 0)
+ return (0);
+ }
for (i = 0; i < screen_size_y(s); i++) {
line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
- if (fnmatch(newsearchstr, line, 0) == 0) {
- free(line);
- break;
- }
+ if (!regex)
+ found = (fnmatch(new, line, 0) == 0);
+ else
+ found = (regexec(&r, line, 0, NULL, 0) == 0);
free(line);
+ if (found)
+ break;
}
+ if (!regex)
+ free(new);
+ else
+ regfree(&r);
- free(newsearchstr);
if (i == screen_size_y(s))
return (0);
return (i + 1);
@@ -1487,7 +1513,7 @@ window_pane_input_callback(struct client *c, int closed, void *data)
c->stdin_callback = NULL;
server_client_unref(c);
- cdata->item->flags &= ~CMDQ_WAITING;
+ cmdq_continue(cdata->item);
free(cdata);
return;