From 943a08b17c9c26a9e3af873d0b87346747b6bffd Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 7 Jun 2017 14:37:30 +0000 Subject: Add simple searching (C-s and n) to the various choose modes: by name for client and tree, and by name and content for buffer. --- usr.bin/tmux/window-buffer.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'usr.bin/tmux/window-buffer.c') diff --git a/usr.bin/tmux/window-buffer.c b/usr.bin/tmux/window-buffer.c index 0782227cc96..9ef3ea86106 100644 --- a/usr.bin/tmux/window-buffer.c +++ b/usr.bin/tmux/window-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-buffer.c,v 1.3 2017/05/31 17:56:48 nicm Exp $ */ +/* $OpenBSD: window-buffer.c,v 1.4 2017/06/07 14:37:30 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott @@ -227,6 +227,22 @@ window_buffer_draw(__unused void *modedata, void *itemdata, u_int sx, u_int sy) return (&s); } +static int +window_buffer_search(__unused void *modedata, void *itemdata, const char *ss) +{ + struct window_buffer_itemdata *item = itemdata; + struct paste_buffer *pb; + const char *bufdata; + size_t bufsize; + + if ((pb = paste_get_name(item->name)) == NULL) + return (0); + if (strstr(item->name, ss) != NULL) + return (0); + bufdata = paste_buffer_data(pb, &bufsize); + return (memmem(bufdata, bufsize, ss, strlen(ss)) != NULL); +} + static struct screen * window_buffer_init(struct window_pane *wp, __unused struct cmd_find_state *fs, struct args *args) @@ -242,8 +258,8 @@ window_buffer_init(struct window_pane *wp, __unused struct cmd_find_state *fs, data->command = xstrdup(args->argv[0]); data->data = mode_tree_start(wp, window_buffer_build, - window_buffer_draw, data, window_buffer_sort_list, - nitems(window_buffer_sort_list), &s); + window_buffer_draw, window_buffer_search, data, + window_buffer_sort_list, nitems(window_buffer_sort_list), &s); mode_tree_build(data->data); mode_tree_draw(data->data); @@ -312,7 +328,7 @@ window_buffer_key(struct window_pane *wp, struct client *c, * Enter = paste buffer */ - finished = mode_tree_key(data->data, &key, m); + finished = mode_tree_key(data->data, c, &key, m); switch (key) { case 'd': item = mode_tree_get_current(data->data); -- cgit v1.2.3-59-g8ed1b