diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-06-11 19:43:35 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-06-11 19:43:35 +0000 |
commit | 8ded41f4dce6cca9ba06b21d71a5d91a207dc45e (patch) | |
tree | 853c006863e290cababda6eaee1bece7b0e9a6ef | |
parent | 96fe3476dc8d86b7171b8a0b8b3f55d7acb58cf2 (diff) |
Add some formats for search in copy mode (search_present, search_match).
GitHub issue 2268.
-rw-r--r-- | usr.bin/tmux/format.c | 9 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 4 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 | ||||
-rw-r--r-- | usr.bin/tmux/window-copy.c | 63 |
4 files changed, 56 insertions, 23 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index a7f709b5fef..160bf6adf18 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.257 2020/06/01 19:39:25 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.258 2020/06/11 19:43:34 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1156,6 +1156,13 @@ format_merge(struct format_tree *ft, struct format_tree *from) } } +/* Get format pane. */ +struct window_pane * +format_get_pane(struct format_tree *ft) +{ + return (ft->wp); +} + /* Add item bits to tree. */ static void format_create_add_item(struct format_tree *ft, struct cmdq_item *item) diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 5b692193a39..f572f8b7a2f 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.781 2020/06/11 09:55:47 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.782 2020/06/11 19:43:34 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -4749,6 +4749,8 @@ The following variables are available, where appropriate: .It Li "scroll_position" Ta "" Ta "Scroll position in copy mode" .It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane" .It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane" +.It Li "search_present" Ta "" Ta "1 if search started in copy mode" +.It Li "search_match" Ta "" Ta "Search match if any" .It Li "selection_active" Ta "" Ta "1 if selection started and changes with the cursor in copy mode" .It Li "selection_end_x" Ta "" Ta "X position of the end of the selection" .It Li "selection_end_y" Ta "" Ta "Y position of the end of the selection" diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 8a9a2d8ee8c..a3f9ab2473d 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1067 2020/06/11 09:55:47 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1068 2020/06/11 19:43:34 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1922,6 +1922,7 @@ struct format_tree *format_create(struct client *, struct cmdq_item *, int, int); void format_free(struct format_tree *); void format_merge(struct format_tree *, struct format_tree *); +struct window_pane *format_get_pane(struct format_tree *); void printflike(3, 4) format_add(struct format_tree *, const char *, const char *, ...); void format_add_tv(struct format_tree *, const char *, diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 2e5552e47ed..0b15007665b 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.298 2020/06/05 07:44:42 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.299 2020/06/11 19:43:34 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -26,6 +26,8 @@ #include "tmux.h" +struct window_copy_mode_data; + static const char *window_copy_key_table(struct window_mode_entry *); static void window_copy_command(struct window_mode_entry *, struct client *, struct session *, struct winlink *, struct args *, @@ -42,7 +44,6 @@ static void window_copy_pageup1(struct window_mode_entry *, int); static int window_copy_pagedown(struct window_mode_entry *, int, int); static void window_copy_next_paragraph(struct window_mode_entry *); static void window_copy_previous_paragraph(struct window_mode_entry *); - static void window_copy_redraw_selection(struct window_mode_entry *, u_int); static void window_copy_redraw_lines(struct window_mode_entry *, u_int, u_int); @@ -51,7 +52,7 @@ static void window_copy_write_line(struct window_mode_entry *, struct screen_write_ctx *, u_int); static void window_copy_write_lines(struct window_mode_entry *, struct screen_write_ctx *, u_int, u_int); - +static char *window_copy_match_at_cursor(struct window_copy_mode_data *); static void window_copy_scroll_to(struct window_mode_entry *, u_int, u_int, int); static int window_copy_search_compare(struct grid *, u_int, u_int, @@ -60,13 +61,13 @@ static int window_copy_search_lr(struct grid *, struct grid *, u_int *, u_int, u_int, u_int, int); static int window_copy_search_rl(struct grid *, struct grid *, u_int *, u_int, u_int, u_int, int); -static int window_copy_last_regex(struct grid *gd, u_int py, u_int first, - u_int last, u_int len, u_int *ppx, u_int *psx, - const char *buf, const regex_t *preg, int eflags); +static int window_copy_last_regex(struct grid *, u_int, u_int, u_int, + u_int, u_int *, u_int *, const char *, const regex_t *, + int); static char *window_copy_stringify(struct grid *, u_int, u_int, u_int, char *, u_int *); -static void window_copy_cstrtocellpos(struct grid *, u_int, u_int *, u_int *, - const char *str); +static void window_copy_cstrtocellpos(struct grid *, u_int, u_int *, + u_int *, const char *); static int window_copy_search_marks(struct window_mode_entry *, struct screen *, int, int); static void window_copy_clear_marks(struct window_mode_entry *); @@ -702,12 +703,40 @@ window_copy_get_line(struct window_pane *wp, u_int y) return (format_grid_line(gd, gd->hsize + y)); } +static char * +window_copy_cursor_word_cb(struct format_tree *ft) +{ + struct window_pane *wp = format_get_pane(ft); + struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes); + struct window_copy_mode_data *data = wme->data; + + return (window_copy_get_word(wp, data->cx, data->cy)); +} + +static char * +window_copy_cursor_line_cb(struct format_tree *ft) +{ + struct window_pane *wp = format_get_pane(ft); + struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes); + struct window_copy_mode_data *data = wme->data; + + return (window_copy_get_line(wp, data->cy)); +} + +static char * +window_copy_search_match_cb(struct format_tree *ft) +{ + struct window_pane *wp = format_get_pane(ft); + struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes); + struct window_copy_mode_data *data = wme->data; + + return (window_copy_match_at_cursor(data)); +} + static void window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft) { struct window_copy_mode_data *data = wme->data; - struct grid *gd = data->screen.grid; - char *s; format_add(ft, "scroll_position", "%d", data->oy); format_add(ft, "rectangle_toggle", "%d", data->rectflag); @@ -726,17 +755,11 @@ window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft) } else format_add(ft, "selection_active", "%d", 0); - s = format_grid_word(gd, data->cx, gd->hsize + data->cy); - if (s != NULL) { - format_add(ft, "copy_cursor_word", "%s", s); - free(s); - } + format_add(ft, "search_present", "%d", data->searchmark != NULL); + format_add_cb(ft, "search_match", window_copy_search_match_cb); - s = format_grid_line(gd, gd->hsize + data->cy); - if (s != NULL) { - format_add(ft, "copy_cursor_line", "%s", s); - free(s); - } + format_add_cb(ft, "copy_cursor_word", window_copy_cursor_word_cb); + format_add_cb(ft, "copy_cursor_line", window_copy_cursor_line_cb); } static void |