emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master b6807a7ddce: Improve menu separator display on ttys slightly (bug


From: Gerd Moellmann
Subject: master b6807a7ddce: Improve menu separator display on ttys slightly (bug#74854)
Date: Sat, 14 Dec 2024 02:25:05 -0500 (EST)

branch: master
commit b6807a7ddce41e99d320be5f23972f218af004a8
Author: Gerd Möllmann <gerd@gnu.org>
Commit: Gerd Möllmann <gerd@gnu.org>

    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.
---
 src/xdisp.c | 45 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/src/xdisp.c b/src/xdisp.c
index 7b0e2644078..e5fc4a12263 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;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]