Hello everyone,

I am sending this because of an issue I had with a ported version of
your ksh(1) on Linux (you can find the port at
https://github.com/ibara/oksh), but everything I say here are also
tested on a VM running OpenBSD 6.8.

When using the 6.8 version I noticed that (in vi editing mode) hitting
Ctrl+L (^L) attempts to clear the screen, both in normal and insert
mode. The problem is that it clears the screen and then it prints
only the last line of the prompt (PS1). The problem is when a multiline
PS1 is in use, in which case the prompt is not printed as expected.

It seems reasonable to me that this behviour is a bug, so I attempted
to edit vi.c and came up with the first of the following patches.

Also, now there is no way to ask redraw of the wrinting line
(that is what ^L were doing previously). In normal mode that
was remapped to ^R. I think that it is useful in insert mode
also. You can see the second patch for this.

I hope that this will at least bring the issue to your attention.

Thank you for your time.

### /* first patch */
diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c
index 53be5a76d50..5a45ab67710 100644
--- a/bin/ksh/vi.c
+++ b/bin/ksh/vi.c
@@ -55,7 +55,7 @@ static int    Endword(int);
 static int     grabhist(int, int);
 static int     grabsearch(int, int, int, char *);
 static void    do_clear_screen(void);
-static void    redraw_line(int);
+static void    redraw_line(int, int);
 static void    refresh_line(int);
 static int     outofwin(void);
 static void    rewindow(void);
@@ -719,7 +719,7 @@ vi_cmd(int argcnt, const char *cmd)
                        break;

                case CTRL('r'):
-                       redraw_line(1);
+                       redraw_line(1, 0);
                        break;

                case '@':
@@ -1737,18 +1737,18 @@ do_clear_screen(void)
                        neednl = 0;
        }
 #endif
-       redraw_line(neednl);
+       redraw_line(neednl, 1);
 }

 static void
-redraw_line(int neednl)
+redraw_line(int neednl, int full)
 {
        (void) memset(wbuf[win], ' ', wbuf_len);
        if (neednl) {
                x_putc('\r');
                x_putc('\n');
        }
-       vi_pprompt(0);
+       vi_pprompt(full);
        cur_col = pwidth;
        morec = ' ';
 }
@@ -2109,7 +2109,7 @@ complete_word(int command, int count)
                        vi_error();
                        x_print_expansions(nwords, words, is_command);
                        x_free_words(nwords, words);
-                       redraw_line(0);
+                       redraw_line(0, 0);
                        return -1;
                }
                /*
@@ -2183,7 +2183,7 @@ print_expansions(struct edstate *e)
        }
        x_print_expansions(nwords, words, is_command);
        x_free_words(nwords, words);
-       redraw_line(0);
+       redraw_line(0, 0);
        return 0;
 }

### /* end of first patch */
### /* second patch */
--- a/bin/ksh/vi.c
+++ b/bin/ksh/vi.c
@@ -658,6 +658,10 @@ vi_insert(int ch)
                do_clear_screen();
                break;

+       case CTRL('r'):
+               redraw_line(1, 0);
+               break;
+
        case CTRL('i'):
                if (Flag(FVITABCOMPLETE)) {
                        complete_word(0, 0);
### /* end of second patch */

Reply via email to