bug-readline
[Top][All Lists]
Advanced

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

[Bug-readline] [PATCH] add modechar to the last line of multi line promp


From: Ivan Radanov Ivanov
Subject: [Bug-readline] [PATCH] add modechar to the last line of multi line prompts
Date: Mon, 4 May 2015 19:08:18 +0300

---

When editing-mode is set to 'vi', show-mode-in-prompt is set to 'on', and the
promt consists of multiple lines, the modechar is displayed on the first line
and does not get updated when switching between normal and input mode. This
patch makes readline add it to the last line of the prompt (which is better in
my opinion, since it's easier to spot) and avoids this problem.

 display.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/display.c b/display.c
index 4df1f73..dcb5b70 100644
--- a/display.c
+++ b/display.c
@@ -267,9 +267,9 @@ prompt_modechar ()
    \002 are assumed to be `visible'. */        
 
 static char *
-expand_prompt (pmt, lp, lip, niflp, vlp)
+expand_prompt (pmt, lp, lip, niflp, vlp, mch)
      char *pmt;
-     int *lp, *lip, *niflp, *vlp;
+     int *lp, *lip, *niflp, *vlp, mch;
 {
   char *r, *ret, *p, *igstart;
   int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars;
@@ -277,7 +277,7 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
   /* Short-circuit if we can. */
   if ((MB_CUR_MAX <= 1 || rl_byte_oriented) && strchr (pmt, 
RL_PROMPT_START_IGNORE) == 0)
     {
-      if (pmt == rl_prompt && _rl_show_mode_in_prompt)
+      if (mch && _rl_show_mode_in_prompt)
         {
           l = strlen (pmt);
           r = (char *)xmalloc (l + 2);
@@ -302,7 +302,7 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
   r = ret = (char *)xmalloc (l + 2);
 
   rl = physchars = 0;  /* move up here so mode show can set them */
-  if (pmt == rl_prompt && _rl_show_mode_in_prompt)
+  if (mch && _rl_show_mode_in_prompt)
     {
       *r++ = prompt_modechar ();
       rl = physchars = 1;
@@ -397,7 +397,7 @@ _rl_strip_prompt (pmt)
 {
   char *ret;
 
-  ret = expand_prompt (pmt, (int *)NULL, (int *)NULL, (int *)NULL, (int 
*)NULL);
+  ret = expand_prompt (pmt, (int *)NULL, (int *)NULL, (int *)NULL, (int 
*)NULL, 0);
   return ret;
 }
 
@@ -450,7 +450,8 @@ rl_expand_prompt (prompt)
       local_prompt = expand_prompt (prompt, &prompt_visible_length,
                                            &prompt_last_invisible,
                                            &prompt_invis_chars_first_line,
-                                           &prompt_physical_chars);
+                                           &prompt_physical_chars,
+                                           1);
       local_prompt_prefix = (char *)0;
       local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
       return (prompt_visible_length);
@@ -462,14 +463,16 @@ rl_expand_prompt (prompt)
       local_prompt = expand_prompt (p, &prompt_visible_length,
                                       &prompt_last_invisible,
                                       &prompt_invis_chars_first_line,
-                                      &prompt_physical_chars);
+                                      &prompt_physical_chars,
+                                      1);
       c = *t; *t = '\0';
       /* The portion of the prompt string up to and including the
         final newline is now null-terminated. */
       local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length,
                                                   (int *)NULL,
                                                   (int *)NULL,
-                                                  (int *)NULL);
+                                                  (int *)NULL,
+                                                  0);
       *t = c;
       local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
       return (prompt_prefix_length);
@@ -2282,7 +2285,8 @@ rl_message (va_alist)
   local_prompt = expand_prompt (msg_buf, &prompt_visible_length,
                                         &prompt_last_invisible,
                                         &prompt_invis_chars_first_line,
-                                        &prompt_physical_chars);
+                                        &prompt_physical_chars,
+                                        0);
   local_prompt_prefix = (char *)NULL;
   local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
   (*rl_redisplay_function) ();
@@ -2315,7 +2319,8 @@ rl_message (format, arg1, arg2)
   local_prompt = expand_prompt (msg_buf, &prompt_visible_length,
                                         &prompt_last_invisible,
                                         &prompt_invis_chars_first_line,
-                                        &prompt_physical_chars);
+                                        &prompt_physical_chars,
+                                        0);
   local_prompt_prefix = (char *)NULL;
   local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
   (*rl_redisplay_function) ();
@@ -2621,7 +2626,8 @@ redraw_prompt (t)
   local_prompt = expand_prompt (t, &prompt_visible_length,
                                   &prompt_last_invisible,
                                   &prompt_invis_chars_first_line,
-                                  &prompt_physical_chars);
+                                  &prompt_physical_chars,
+                                  1);
   local_prompt_prefix = (char *)NULL;
   local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
 
-- 
2.1.4




reply via email to

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