Make adding mode formats a function pointer as well.

This commit is contained in:
nicm 2019-03-07 19:01:21 +00:00
parent 5cdd578906
commit 7f093fcddc
3 changed files with 17 additions and 17 deletions

View File

@ -1552,7 +1552,8 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
format_add(ft, "scroll_region_upper", "%u", wp->base.rupper);
format_add(ft, "scroll_region_lower", "%u", wp->base.rlower);
window_copy_add_formats(wp, ft);
if (wp->mode != NULL && wp->mode->formats != NULL)
wp->mode->formats(wp, ft);
format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0);
format_add(ft, "alternate_saved_x", "%u", wp->saved_cx);

4
tmux.h
View File

@ -43,6 +43,7 @@ struct cmdq_item;
struct cmdq_list;
struct environ;
struct format_job_tree;
struct format_tree;
struct input_ctx;
struct job;
struct mode_tree_data;
@ -707,6 +708,7 @@ struct window_mode {
void (*command)(struct window_pane *, struct client *,
struct session *, struct winlink *, struct args *,
struct mouse_event *);
void (*formats)(struct window_pane *, struct format_tree *);
};
#define WINDOW_MODE_TIMEOUT 180
@ -2304,8 +2306,6 @@ void printflike(2, 3) window_copy_add(struct window_pane *, const char *, ...);
void window_copy_vadd(struct window_pane *, const char *, va_list);
void window_copy_pageup(struct window_pane *, int);
void window_copy_start_drag(struct client *, struct mouse_event *);
void window_copy_add_formats(struct window_pane *,
struct format_tree *);
/* names.c */
void check_window_name(struct window *);

View File

@ -31,10 +31,11 @@ static void window_copy_command(struct window_pane *, struct client *,
static struct screen *window_copy_init(struct window_pane *,
struct cmd_find_state *, struct args *);
static void window_copy_free(struct window_pane *);
static void window_copy_resize(struct window_pane *, u_int, u_int);
static void window_copy_formats(struct window_pane *, struct format_tree *);
static int window_copy_pagedown(struct window_pane *, int, int);
static void window_copy_next_paragraph(struct window_pane *);
static void window_copy_previous_paragraph(struct window_pane *);
static void window_copy_resize(struct window_pane *, u_int, u_int);
static void window_copy_redraw_selection(struct window_pane *, u_int);
static void window_copy_redraw_lines(struct window_pane *, u_int, u_int);
@ -113,6 +114,7 @@ const struct window_mode window_copy_mode = {
.resize = window_copy_resize,
.key_table = window_copy_key_table,
.command = window_copy_command,
.formats = window_copy_formats,
};
enum {
@ -472,6 +474,16 @@ window_copy_next_paragraph(struct window_pane *wp)
window_copy_scroll_to(wp, ox, oy);
}
static void
window_copy_formats(struct window_pane *wp, struct format_tree *ft)
{
struct window_copy_mode_data *data = wp->modedata;
format_add(ft, "selection_present", "%d", data->screen.sel != NULL);
format_add(ft, "scroll_position", "%d", data->oy);
format_add(ft, "rectangle_toggle", "%d", data->rectflag);
}
static void
window_copy_resize(struct window_pane *wp, u_int sx, u_int sy)
{
@ -2447,19 +2459,6 @@ window_copy_scroll_down(struct window_pane *wp, u_int ny)
screen_write_stop(&ctx);
}
void
window_copy_add_formats(struct window_pane *wp, struct format_tree *ft)
{
struct window_copy_mode_data *data = wp->modedata;
if (wp->mode != &window_copy_mode)
return;
format_add(ft, "selection_present", "%d", data->screen.sel != NULL);
format_add(ft, "scroll_position", "%d", data->oy);
format_add(ft, "rectangle_toggle", "%d", data->rectflag);
}
static void
window_copy_rectangle_toggle(struct window_pane *wp)
{