Add -T to set a popup title, from Alexis Hildebrandt in GitHub issue 2941.

This commit is contained in:
nicm
2021-10-20 09:50:40 +00:00
parent f26b8c57ff
commit 8a9bfd0cdd
6 changed files with 37 additions and 20 deletions

View File

@ -646,9 +646,7 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu,
memcpy(&default_gc, &grid_default_cell, sizeof default_gc);
screen_write_box(ctx, menu->width + 4, menu->count + 2,
BOX_LINES_DEFAULT, NULL);
screen_write_cursormove(ctx, cx + 2, cy, 0);
format_draw(ctx, &default_gc, menu->width, menu->title, NULL);
BOX_LINES_DEFAULT, &default_gc, menu->title);
for (i = 0; i < menu->count; i++) {
name = menu->items[i].name;
@ -714,7 +712,7 @@ screen_write_box_border_set(enum box_lines box_lines, int cell_type,
/* Draw a box on screen. */
void
screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny,
enum box_lines l, const struct grid_cell *gcp)
enum box_lines lines, const struct grid_cell *gcp, const char *title)
{
struct screen *s = ctx->s;
struct grid_cell gc;
@ -727,30 +725,31 @@ screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny,
memcpy(&gc, gcp, sizeof gc);
else
memcpy(&gc, &grid_default_cell, sizeof gc);
gc.attr |= GRID_ATTR_CHARSET;
gc.flags |= GRID_FLAG_NOPALETTE;
/* Draw top border */
screen_write_box_border_set(l, CELL_TOPLEFT, &gc);
screen_write_box_border_set(lines, CELL_TOPLEFT, &gc);
screen_write_cell(ctx, &gc);
screen_write_box_border_set(l, CELL_LEFTRIGHT, &gc);
screen_write_box_border_set(lines, CELL_LEFTRIGHT, &gc);
for (i = 1; i < nx - 1; i++)
screen_write_cell(ctx, &gc);
screen_write_box_border_set(l, CELL_TOPRIGHT, &gc);
screen_write_box_border_set(lines, CELL_TOPRIGHT, &gc);
screen_write_cell(ctx, &gc);
/* Draw bottom border */
screen_write_set_cursor(ctx, cx, cy + ny - 1);
screen_write_box_border_set(l, CELL_BOTTOMLEFT, &gc);
screen_write_box_border_set(lines, CELL_BOTTOMLEFT, &gc);
screen_write_cell(ctx, &gc);
screen_write_box_border_set(l, CELL_LEFTRIGHT, &gc);
screen_write_box_border_set(lines, CELL_LEFTRIGHT, &gc);
for (i = 1; i < nx - 1; i++)
screen_write_cell(ctx, &gc);
screen_write_box_border_set(l, CELL_BOTTOMRIGHT, &gc);
screen_write_box_border_set(lines, CELL_BOTTOMRIGHT, &gc);
screen_write_cell(ctx, &gc);
/* Draw sides */
screen_write_box_border_set(l, CELL_TOPBOTTOM, &gc);
screen_write_box_border_set(lines, CELL_TOPBOTTOM, &gc);
for (i = 1; i < ny - 1; i++) {
/* left side */
screen_write_set_cursor(ctx, cx, cy + i);
@ -760,6 +759,12 @@ screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny,
screen_write_cell(ctx, &gc);
}
if (title != NULL) {
gc.attr &= ~GRID_ATTR_CHARSET;
screen_write_cursormove(ctx, cx + 2, cy, 0);
format_draw(ctx, &gc, nx - 4, title, NULL);
}
screen_write_set_cursor(ctx, cx, cy);
}