Re: ksh: [vi.c] "clear-screen" bug + patch

2021-03-10 Thread Theo Buehler
On Wed, Mar 10, 2021 at 01:10:55PM -0700, Todd C. Miller wrote:
> Now the the clear screen change has been committed, here's the
> insert mode ^R (redraw) diff again with a man page update.  Note
> that ^R is already supported in command mode.
> 

ok



Re: ksh: [vi.c] "clear-screen" bug + patch

2021-03-10 Thread Todd C . Miller
Now the the clear screen change has been committed, here's the
insert mode ^R (redraw) diff again with a man page update.  Note
that ^R is already supported in command mode.

OK?

 - todd

Index: bin/ksh/ksh.1
===
RCS file: /cvs/src/bin/ksh/ksh.1,v
retrieving revision 1.212
diff -u -p -u -r1.212 ksh.1
--- bin/ksh/ksh.1   8 Mar 2021 06:20:50 -   1.212
+++ bin/ksh/ksh.1   10 Mar 2021 20:08:21 -
@@ -5060,6 +5060,8 @@ See the
 command in
 .Sx Emacs editing mode
 for more information.
+.It ^R
+Redraw the current line.
 .It ^V
 Literal next.
 The next character typed is not treated specially (can be used
Index: bin/ksh/vi.c
===
RCS file: /cvs/src/bin/ksh/vi.c,v
retrieving revision 1.58
diff -u -p -u -r1.58 vi.c
--- bin/ksh/vi.c10 Mar 2021 20:06:04 -  1.58
+++ bin/ksh/vi.c10 Mar 2021 20:08:21 -
@@ -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);



Re: ksh: [vi.c] "clear-screen" bug + patch

2021-03-10 Thread Theo Buehler
On Tue, Mar 09, 2021 at 10:03:56AM -0700, Todd C. Miller wrote:
> I think that in do_clear_screen() full should not be set unless
> neednl is 0.  That is, we should only print the entire prompt if
> the screen was actually cleared.  Otherwise looks good to me.

ok tb



Re: ksh: [vi.c] "clear-screen" bug + patch

2021-03-09 Thread Todd C . Miller
On Tue, 09 Mar 2021 17:53:06 +0100, Benjamin Baier wrote:

> Ping

I think that in do_clear_screen() full should not be set unless
neednl is 0.  That is, we should only print the entire prompt if
the screen was actually cleared.  Otherwise looks good to me.

 - todd

Index: bin/ksh/vi.c
===
RCS file: /cvs/src/bin/ksh/vi.c,v
retrieving revision 1.57
diff -u -p -u -r1.57 vi.c
--- bin/ksh/vi.c20 Sep 2020 14:40:45 -  1.57
+++ bin/ksh/vi.c9 Mar 2021 17:02:14 -
@@ -55,7 +55,7 @@ static intEndword(int);
 static int grabhist(int, int);
 static int grabsearch(int, int, int, char *);
 static voiddo_clear_screen(void);
-static voidredraw_line(int);
+static voidredraw_line(int, int);
 static voidrefresh_line(int);
 static int outofwin(void);
 static voidrewindow(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,19 @@ do_clear_screen(void)
neednl = 0;
}
 #endif
-   redraw_line(neednl);
+   /* Only print the full prompt if we cleared the screen. */
+   redraw_line(neednl, !neednl);
 }
 
 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 +2110,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 +2184,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;
 }
 



Re: ksh: [vi.c] "clear-screen" bug + patch

2021-03-09 Thread Benjamin Baier
Ping

On Sat, 21 Nov 2020 18:59:25 +0200
Πάτερος Πέτρος  wrote:

> 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.
Still an issue on  6.9 GENERIC.MP#379 amd64

> 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.
I do use a 2-line $PS1 prompt. Ctrl+L works (prints full $PS1) in emacs mode,
does not work correct in vi mode (prints last line of $PS1)

> 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.
Does what it says, with multiline $PS1. Reattached below.
Ramdisk's SMALL version is not affected, because vi mode is not compiled in.

> 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.
Maybe later?

> I hope that this will at least bring the issue to your attention.
> 
> Thank you for your time.



First patch reattached from a cvs diff
Index: vi.c
===
RCS file: /var/cvs/src/bin/ksh/vi.c,v
retrieving revision 1.57
diff -u -p -r1.57 vi.c
--- vi.c20 Sep 2020 14:40:45 -  1.57
+++ vi.c9 Mar 2021 12:57:30 -
@@ -55,7 +55,7 @@ static intEndword(int);
 static int grabhist(int, int);
 static int grabsearch(int, int, int, char *);
 static voiddo_clear_screen(void);
-static voidredraw_line(int);
+static voidredraw_line(int, int);
 static voidrefresh_line(int);
 static int outofwin(void);
 static voidrewindow(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;
 }
 

> ### /* 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);
> -