From 18e01b73e72b8aa36bd995d29317e9834c53f868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= Date: Fri, 13 Dec 2024 15:54:21 +0100 Subject: [PATCH] Improve menu separator display on ttys slightly * src/xdisp.c (display_tty_menu_separator): New function displaying separators with '-', '=', or ' '. (display_tty_menu_item): Use it. --- src/xdisp.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/xdisp.c b/src/xdisp.c index 1bfc4bb1797..e9f9fcc16f6 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -27249,6 +27249,34 @@ deep_copy_glyph_row (struct frame *f, struct glyph_row *to, struct glyph_row *fr fill_up_frame_row_with_spaces (f, 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, we could draw actual horizontal lines of + different styles on ttys, maybe optionally using Unicode + characters via display table entries. Patches very welcome. */ + +static void +display_tty_menu_separator (struct it *it, const char *label, int width) +{ + static char sep[200]; + char c; + if (strcmp (label, "--space") == 0) + c = ' '; + else if (strcmp (label, "--double-line") == 0) + c = '='; + else + c = '-'; + memset (sep, c, sizeof sep); + sep[sizeof sep - 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); +} + /* 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 @@ -27323,6 +27351,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) { @@ -27333,20 +27362,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; -- 2.47.1