xref: /freebsd/contrib/nvi/vi/v_screen.c (revision b0d29bc47dba79f6f38e67eabadfb4b32ffd9390)
1 /*-
2  * Copyright (c) 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 1992, 1993, 1994, 1995, 1996
5  *	Keith Bostic.  All rights reserved.
6  *
7  * See the LICENSE file for redistribution information.
8  */
9 
10 #include "config.h"
11 
12 #ifndef lint
13 static const char sccsid[] = "$Id: v_screen.c,v 10.12 2001/06/25 15:19:34 skimo Exp $";
14 #endif /* not lint */
15 
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
19 
20 #include <bitstring.h>
21 #include <limits.h>
22 #include <stdio.h>
23 
24 #include "../common/common.h"
25 #include "vi.h"
26 
27 /*
28  * v_screen -- ^W
29  *	Switch screens.
30  *
31  * PUBLIC: int v_screen(SCR *, VICMD *);
32  */
33 int
34 v_screen(SCR *sp, VICMD *vp)
35 {
36 	/*
37 	 * You can't leave a colon command-line edit window -- it's not that
38 	 * it won't work, but it gets real weird, real fast when you execute
39 	 * a colon command out of a window that was forked from a window that's
40 	 * now backgrounded...  You get the idea.
41 	 */
42 	if (F_ISSET(sp, SC_COMEDIT)) {
43 		msgq(sp, M_ERR,
44 		    "308|Enter <CR> to execute a command, :q to exit");
45 		return (1);
46 	}
47 
48 	/*
49 	 * Try for the next lower screen, or, go back to the first
50 	 * screen on the stack.
51 	 */
52 	if (TAILQ_NEXT(sp, q) != NULL)
53 		sp->nextdisp = TAILQ_NEXT(sp, q);
54 	else if (TAILQ_FIRST(sp->gp->dq) == sp) {
55 		msgq(sp, M_ERR, "187|No other screen to switch to");
56 		return (1);
57 	} else
58 		sp->nextdisp = TAILQ_FIRST(sp->gp->dq);
59 
60 	F_SET(sp->nextdisp, SC_STATUS);
61 	F_SET(sp, SC_SSWITCH | SC_STATUS);
62 	return (0);
63 }
64