From: Gerd Möllmann Date: Fri, 13 Dec 2024 14:54:21 +0000 (+0100) Subject: Improve menu separator display on ttys slightly (bug#74854) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=400058a2f2c928cf2dedc1c52af88a76c5beeb64;p=emacs.git Improve menu separator display on ttys slightly (bug#74854) * src/xdisp.c (display_tty_menu_separator): New function displaying separators with '-', '=', or ' '. (display_tty_menu_item): Use it. (cherry picked from commit b6807a7ddce41e99d320be5f23972f218af004a8) --- diff --git a/src/xdisp.c b/src/xdisp.c index f02e6056253..0c9c9ea9b5b 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -27256,6 +27256,35 @@ deep_copy_glyph_row (struct glyph_row *to, struct glyph_row *from) fill_up_frame_row_with_spaces (to, to_used); } +/* Produce glyphs for a menu separator on a tty. + + FIXME: This is only a "good enough for now" implementation of menu + separators as described in the Elisp info manual. We should probably + ignore menu separators when computing the width of a menu. Secondly, + optionally using Unicode characters via display table entries would + be nice. Patches very welcome. */ + +static void +display_tty_menu_separator (struct it *it, const char *label, int width) +{ + USE_SAFE_ALLOCA; + char c; + if (strcmp (label, "--space") == 0) + c = ' '; + else if (strcmp (label, "--double-line") == 0) + c = '='; + else + c = '-'; + char *sep = SAFE_ALLOCA (width); + memset (sep, c, width - 1); + sep[width - 1] = 0; + display_string (sep, Qnil, Qnil, 0, 0, it, width - 1, width - 1, + FRAME_COLS (it->f) - 1, -1); + display_string (" ", Qnil, Qnil, 0, 0, it, 1, 0, + FRAME_COLS (it->f) - 1, -1); + SAFE_FREE (); +} + /* Display one menu item on a TTY, by overwriting the glyphs in the frame F's desired glyph matrix with glyphs produced from the menu item text. Called from term.c to display TTY drop-down menus one @@ -27330,6 +27359,7 @@ display_tty_menu_item (const char *item_text, int width, int face_id, /* Pad with a space on the left. */ display_string (" ", Qnil, Qnil, 0, 0, &it, 1, 0, FRAME_COLS (f) - 1, -1); width--; + /* Display the menu item, pad with spaces to WIDTH. */ if (submenu) { @@ -27340,20 +27370,13 @@ display_tty_menu_item (const char *item_text, int width, int face_id, display_string (" >", Qnil, Qnil, 0, 0, &it, width, 0, FRAME_COLS (f) - 1, -1); } - else if (menu_separator_name_p (item_text)) + else if (menu_separator_name_p (item_text)) { - /* FIXME: This is only a "good enough for now" implementation of - menu separators as described in the Elisp info manual. We - should probably ignore menu separators when computing the width - of a menu. Secondly, we could draw actual horizontal lines of - different styles on ttys, maybe optionally using Unicode - characters via display table entries. Patches very welcome. */ - display_string ("--", Qnil, Qnil, 0, 0, &it, width, 0, - FRAME_COLS (f) - 1, -1); + display_tty_menu_separator (&it, item_text, width); } else - display_string (item_text, Qnil, Qnil, 0, 0, &it, - width, 0, FRAME_COLS (f) - 1, -1); + display_string (item_text, Qnil, Qnil, 0, 0, &it, width, 0, + FRAME_COLS (f) - 1, -1); row->used[TEXT_AREA] = max (saved_used, row->used[TEXT_AREA]); row->truncated_on_right_p = saved_truncated;