Add options and arguments to display-menu to set menu border style

pull/3649/head
Alexis Hildebrandt 2023-07-27 00:04:38 +02:00
parent 1ab76d68e3
commit b6aa4d7c1d
10 changed files with 83 additions and 31 deletions

View File

@ -38,10 +38,15 @@ const struct cmd_entry cmd_display_menu_entry = {
.name = "display-menu",
.alias = "menu",
.args = { "c:t:s:S:OT:x:y:", 1, -1, cmd_display_menu_args_parse },
.usage = "[-O] [-c target-client] [-s style] [-S starting-choice] "
CMD_TARGET_PANE_USAGE " [-T title] [-x position] "
"[-y position] name key command ...",
.args = { "c:C:t:s:S:OT:x:y:", 1, -1, cmd_display_menu_args_parse },
/* TODO: For consistency with display-popup the -S flag could be used
* to specify the border-style rather than the selection choice.
* Yet this can be considered a breaking change, which might not be
* acceptable.
*/
.usage = "[-O] [-c target-client] [-C starting-choice] "
"[-s style] [-S border-style] " CMD_TARGET_PANE_USAGE
"[-T title] [-x position] [-y position] name key command ...",
.target = { 't', CMD_FIND_PANE, 0 },
@ -290,6 +295,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
struct menu_item menu_item;
const char *key, *name;
const char *style = args_get(args, 's');
const char *border_style = args_get(args, 'S');
char *title, *cause;
int flags = 0, starting_choice = 0;
u_int px, py, i, count = args_count(args);
@ -297,11 +303,11 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
if (tc->overlay_draw != NULL)
return (CMD_RETURN_NORMAL);
if (args_has(args, 'S')) {
if (strcmp(args_get(args, 'S'), "-") == 0)
if (args_has(args, 'C')) {
if (strcmp(args_get(args, 'C'), "-") == 0)
starting_choice = -1;
else {
starting_choice = args_strtonum(args, 'S', 0, UINT_MAX,
starting_choice = args_strtonum(args, 'C', 0, UINT_MAX,
&cause);
if (cause != NULL) {
cmdq_error(item, "starting choice %s", cause);
@ -358,7 +364,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
if (!event->m.valid)
flags |= MENU_NOMOUSE;
if (menu_display(menu, flags, starting_choice, item, px, py, tc, style,
target, NULL, NULL) != 0)
border_style, target, NULL, NULL) != 0)
return (CMD_RETURN_NORMAL);
return (CMD_RETURN_WAIT);
}

23
menu.c
View File

@ -28,6 +28,7 @@ struct menu_data {
int flags;
struct grid_cell style;
struct grid_cell border_style;
struct cmd_find_state fs;
struct screen s;
@ -205,7 +206,8 @@ menu_draw_cb(struct client *c, void *data,
screen_write_start(&ctx, s);
screen_write_clearscreen(&ctx, 8);
screen_write_menu(&ctx, menu, md->choice, &md->style, &gc);
screen_write_menu(&ctx, menu, md->choice, &md->style, &md->border_style,
&gc);
screen_write_stop(&ctx);
for (i = 0; i < screen_size_y(&md->s); i++) {
@ -433,7 +435,8 @@ chosen:
struct menu_data *
menu_prepare(struct menu *menu, int flags, int starting_choice,
struct cmdq_item *item, u_int px, u_int py, struct client *c,
const char *style, struct cmd_find_state *fs, menu_choice_cb cb, void *data)
const char *style, const char *border_style, struct cmd_find_state *fs,
menu_choice_cb cb, void *data)
{
struct menu_data *md;
int choice;
@ -463,6 +466,17 @@ menu_prepare(struct menu *menu, int flags, int starting_choice,
}
md->style.attr = 0;
memcpy(&md->border_style, &grid_default_cell, sizeof md->border_style);
style_apply(&md->border_style, o, "menu-border-style", NULL);
if (border_style != NULL) {
style_set(&sytmp, &grid_default_cell);
if (style_parse(&sytmp, &md->border_style, border_style) == 0) {
md->border_style.fg = sytmp.gc.fg;
md->border_style.bg = sytmp.gc.bg;
}
}
md->border_style.attr = 0;
if (fs != NULL)
cmd_find_copy_state(&md->fs, fs);
screen_init(&md->s, menu->width + 4, menu->count + 2, 0);
@ -515,12 +529,13 @@ menu_prepare(struct menu *menu, int flags, int starting_choice,
int
menu_display(struct menu *menu, int flags, int starting_choice,
struct cmdq_item *item, u_int px, u_int py, struct client *c,
const char *style, struct cmd_find_state *fs, menu_choice_cb cb, void *data)
const char *style, const char *border_style, struct cmd_find_state *fs,
menu_choice_cb cb, void *data)
{
struct menu_data *md;
md = menu_prepare(menu, flags, starting_choice, item, px, py, c, style,
fs, cb, data);
border_style, fs, cb, data);
if (md == NULL)
return (-1);
server_client_set_overlay(c, 0, NULL, menu_mode_cb, menu_draw_cb,

View File

@ -962,7 +962,7 @@ mode_tree_display_menu(struct mode_tree_data *mtd, struct client *c, u_int x,
x -= (menu->width + 4) / 2;
else
x = 0;
if (menu_display(menu, 0, 0, NULL, x, y, c, NULL, NULL,
if (menu_display(menu, 0, 0, NULL, x, y, c, NULL, NULL, NULL,
mode_tree_menu_callback, mtm) != 0)
menu_free(menu);
}

View File

@ -335,6 +335,15 @@ const struct options_table_entry options_table[] = {
.text = "Default style of menu."
},
{ .name = "menu-border-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Default style of menu borders."
},
{ .name = "message-limit",
.type = OPTIONS_TABLE_NUMBER,
.scope = OPTIONS_TABLE_SERVER,

View File

@ -575,7 +575,7 @@ menu:
else
x = 0;
pd->md = menu_prepare(pd->menu, 0, 0, NULL, x, m->y, c, NULL, NULL,
popup_menu_done, pd);
NULL, popup_menu_done, pd);
c->flags |= CLIENT_REDRAWOVERLAY;
out:

View File

@ -30,6 +30,8 @@ static void screen_write_collect_clear(struct screen_write_ctx *, u_int,
static void screen_write_collect_scroll(struct screen_write_ctx *, u_int);
static void screen_write_collect_flush(struct screen_write_ctx *, int,
const char *);
static void screen_write_box_border_set(enum box_lines, int,
struct grid_cell *);
static int screen_write_overwrite(struct screen_write_ctx *,
struct grid_cell *, u_int);
@ -595,10 +597,10 @@ screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src,
/* Draw a horizontal line on screen. */
void
screen_write_hline(struct screen_write_ctx *ctx, u_int nx, int left, int right,
const struct grid_cell *menu_gc)
const struct grid_cell *menu_gc, const struct grid_cell *border_gc)
{
struct screen *s = ctx->s;
struct grid_cell gc;
struct grid_cell gc, edge_gc;
u_int cx, cy, i;
cx = s->cx;
@ -608,10 +610,14 @@ screen_write_hline(struct screen_write_ctx *ctx, u_int nx, int left, int right,
sizeof gc);
gc.attr |= GRID_ATTR_CHARSET;
screen_write_putc(ctx, &gc, left ? 't' : 'q');
memcpy(&edge_gc, (border_gc != NULL) ? border_gc : &grid_default_cell,
sizeof edge_gc);
edge_gc.attr |= GRID_ATTR_CHARSET;
screen_write_putc(ctx, &edge_gc, left ? 't' : 'q');
for (i = 1; i < nx - 1; i++)
screen_write_putc(ctx, &gc, 'q');
screen_write_putc(ctx, &gc, right ? 'u' : 'q');
screen_write_putc(ctx, &edge_gc, right ? 'u' : 'q');
screen_write_set_cursor(ctx, cx, cy);
}
@ -644,7 +650,8 @@ screen_write_vline(struct screen_write_ctx *ctx, u_int ny, int top, int bottom)
/* Draw a menu on screen. */
void
screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice,
const struct grid_cell *menu_gc, const struct grid_cell *choice_gc)
const struct grid_cell *menu_gc, const struct grid_cell *border_gc,
const struct grid_cell *choice_gc)
{
struct screen *s = ctx->s;
struct grid_cell default_gc;
@ -658,7 +665,7 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice,
memcpy(&default_gc, menu_gc, sizeof default_gc);
screen_write_box(ctx, menu->width + 4, menu->count + 2,
BOX_LINES_DEFAULT, &default_gc, menu->title);
BOX_LINES_DEFAULT, border_gc, menu->title);
for (i = 0; i < menu->count; i++) {
name = menu->items[i].name;
@ -666,7 +673,11 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice,
/* Draw separator line */
screen_write_cursormove(ctx, cx, cy + 1 + i, 0);
screen_write_hline(ctx, menu->width + 4, 1, 1,
&default_gc);
// TODO: Are separator lines considered to be part
// of the menu or rather the menu border? In the
// latter case they need be drawn with border_gc
// rather than &default_gc?
&default_gc, border_gc);
continue;
}

View File

@ -1765,7 +1765,7 @@ status_prompt_complete_list_menu(struct client *c, char **list, u_int size,
offset = 0;
if (menu_display(menu, MENU_NOMOUSE|MENU_TAB, 0, NULL, offset,
py, c, NULL, NULL, status_prompt_menu_callback, spm) != 0) {
py, c, NULL, NULL, NULL, status_prompt_menu_callback, spm) != 0) {
menu_free(menu);
free(spm);
return (0);
@ -1858,7 +1858,7 @@ status_prompt_complete_window_menu(struct client *c, struct session *s,
offset = 0;
if (menu_display(menu, MENU_NOMOUSE|MENU_TAB, 0, NULL, offset,
py, c, NULL, NULL, status_prompt_menu_callback, spm) != 0) {
py, c, NULL, NULL, NULL, status_prompt_menu_callback, spm) != 0) {
menu_free(menu);
free(spm);
return (NULL);

16
tmux.1
View File

@ -4083,6 +4083,13 @@ See the
section on how to specify
.Ar style .
Attributes are ignored.
.It Ic menu-border-style Ar style
Set the menu border style.
See the
.Sx STYLES
section on how to specify
.Ar style .
Attributes are ignored.
.It Ic message-command-style Ar style
Set status line message command style.
This is used for the command prompt with
@ -6038,8 +6045,9 @@ the default is
.Op Fl O
.Op Fl c Ar target-client
.Op Fl s Ar style
.Op Fl S Ar style
.Op Fl t Ar target-pane
.Op Fl S Ar starting-choice
.Op Fl C Ar starting-choice
.Op Fl T Ar title
.Op Fl x Ar position
.Op Fl y Ar position
@ -6067,14 +6075,16 @@ The name may be empty for a separator line, in which case both the key and
command should be omitted.
.Pp
.Fl s
sets the style for the menu (see
sets the style for the menu and
.Fl S
sets the style for the menu border (see
.Sx STYLES ) .
.Pp
.Fl T
is a format for the menu title (see
.Sx FORMATS ) .
.Pp
.Fl S
.Fl C
sets the menu item selected by default, if the menu is not bound to a mouse key
binding.
.Pp

9
tmux.h
View File

@ -2895,10 +2895,11 @@ void screen_write_putc(struct screen_write_ctx *, const struct grid_cell *,
void screen_write_fast_copy(struct screen_write_ctx *, struct screen *,
u_int, u_int, u_int, u_int);
void screen_write_hline(struct screen_write_ctx *, u_int, int, int,
const struct grid_cell *);
const struct grid_cell *, const struct grid_cell *);
void screen_write_vline(struct screen_write_ctx *, u_int, int, int);
void screen_write_menu(struct screen_write_ctx *, struct menu *, int,
const struct grid_cell *, const struct grid_cell *);
const struct grid_cell *, const struct grid_cell *,
const struct grid_cell *);
void screen_write_box(struct screen_write_ctx *, u_int, u_int,
enum box_lines, const struct grid_cell *, const char *);
void screen_write_preview(struct screen_write_ctx *, struct screen *, u_int,
@ -3311,10 +3312,10 @@ void menu_add_item(struct menu *, const struct menu_item *,
struct cmd_find_state *);
void menu_free(struct menu *);
struct menu_data *menu_prepare(struct menu *, int, int, struct cmdq_item *,
u_int, u_int, struct client *, const char *,
u_int, u_int, struct client *, const char *, const char *,
struct cmd_find_state *, menu_choice_cb, void *);
int menu_display(struct menu *, int, int, struct cmdq_item *,
u_int, u_int, struct client *, const char *,
u_int, u_int, struct client *, const char *, const char *,
struct cmd_find_state *, menu_choice_cb, void *);
struct screen *menu_mode_cb(struct client *, void *, u_int *, u_int *);
void menu_check_cb(struct client *, void *, u_int, u_int, u_int,

View File

@ -242,7 +242,7 @@ window_client_draw(__unused void *modedata, void *itemdata,
screen_write_cursormove(ctx, cx, cy + 2, 0);
else
screen_write_cursormove(ctx, cx, cy + sy - 1 - lines, 0);
screen_write_hline(ctx, sx, 0, 0, NULL);
screen_write_hline(ctx, sx, 0, 0, NULL, NULL);
if (at != 0)
screen_write_cursormove(ctx, cx, cy, 0);