Subject: Re: bin/10116: vi somewhat easily confused by suspension
To: None <gnats-bugs@gnats.netbsd.org, tech-userlevel@netbsd.org>
From: Julian Coleman <J.D.Coleman@newcastle.ac.uk>
List: tech-userlevel
Date: 05/24/2000 16:39:57
> However, vi requires more capability than what curses has, and some
> extra work may be needed.  For example, here a vi (ex) command is executed.
> 
> 	:!ls
> 	CVS          dist         gnu          local        sys
> 	Makefile     distrib      include      regress      usr.bin
> 	Makefile.inc etc          lib          sbin         usr.sbin
> 	bin          games        libexec      share
> 	Press any key to continue [: to enter more ex commands]:
> 
> The screen should not cleared to leave the result of ls visible (initscr()
> can't be called at this point) but the terminal driver should be in
> raw (or cbreak) mode.
> So we can't remove all the termios stuff.

Looked at this.  Not sure of the best solution.  From vi/vs_msg.c:576, we
eventually call cl_ex_init(), which does a tcsetattr() and then sends the
'ti' sequence.  To make the screen display more useful, you can do :

--- /usr/src/usr.bin/vi/vi/vs_msg.c	Tue Jan 13 15:03:38 1998
+++ vi/vs_msg.c	Wed May 24 16:22:59 2000
@@ -572,10 +572,7 @@
 	 * commands will have cumulative line modification reports.  That seems
 	 * right (well, at least not wrong) to me.
 	 */
-	if (F_ISSET(sp, SC_SCR_EXWROTE)) {
-		if (sp->gp->scr_screen(sp, SC_VI))
-			return (1);
-	} else {
+	if (!F_ISSET(sp, SC_SCR_EXWROTE)) {
 		if (vip->totalcount < 2) {
 			if (vip->totalcount == 0) {
 				F_CLR(sp, SC_EX_DONTWAIT);
@@ -597,9 +594,11 @@
 	if (!F_ISSET(sp, SC_EX_DONTWAIT) && !INTERRUPTED(sp)) {
 		wtype = F_ISSET(sp, SC_EXIT | SC_EXIT_FORCE |
 		    SC_FSWITCH | SC_SSWITCH) ? SCROLL_W : SCROLL_W_EX;
-		if (F_ISSET(sp, SC_SCR_EXWROTE))
+		if (F_ISSET(sp, SC_SCR_EXWROTE)) {
 			vs_wait(sp, continuep, wtype);
-		else
+			if (sp->gp->scr_screen(sp, SC_VI))
+				return (1);
+		} else
 			vs_scroll(sp, continuep, wtype);
 		if (*continuep)
 			return (0);

but we've also moved the tcsetattr(), so the terminal isn't in raw mode.

Looking at the nv-1.79 source, sending 'ti' and 'te' is not done directly
in cl_ex_init() but in cl_attr(), so the problem goes away.  Is it worth
importing nvi-1.79 (wasn't there mention of this a while back?)?  If not,
the bits dealing with SA_ALTERNATE need to be back-ported in order to fix
this (see also the comment in cl_attr() (cl/cl_funcs.c:91) in 1.79.

J

-- 
                    My other computer also runs NetBSD
                          http://www.netbsd.org/