all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 74854@debbugs.gnu.org
Subject: bug#74854: [PATCH] Improve menu separator display on ttys slightly
Date: Fri, 13 Dec 2024 18:24:24 +0100	[thread overview]
Message-ID: <m2jzc3zebb.fsf@gmail.com> (raw)
In-Reply-To: <8634iry2vg.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 13 Dec 2024 18:16:51 +0200")

[-- Attachment #1: Type: text/plain, Size: 127 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> How about using alloca with 'width' as its argument?

Good point, new patch attached.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-menu-separator-display-on-ttys-slightly-bug-.patch --]
[-- Type: text/x-patch, Size: 3424 bytes --]

From 6c7c4623674646c33a7b4738de3533ccaa65c9ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <gerd@gnu.org>
Date: Fri, 13 Dec 2024 15:54:21 +0100
Subject: [PATCH] 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 1bfc4bb1797..bbe4210d734 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -27249,6 +27249,35 @@ 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,
+   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
@@ -27323,6 +27352,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 +27363,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


  reply	other threads:[~2024-12-13 17:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-13 15:09 bug#74854: [PATCH] Improve menu separator display on ttys slightly Gerd Möllmann
2024-12-13 16:16 ` Eli Zaretskii
2024-12-13 17:24   ` Gerd Möllmann [this message]
2024-12-14  7:15     ` Eli Zaretskii
2024-12-14  7:25       ` Gerd Möllmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2jzc3zebb.fsf@gmail.com \
    --to=gerd.moellmann@gmail.com \
    --cc=74854@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.