xref: /dragonfly/contrib/nvi2/vi/v_screen.c (revision 6f5ec8b5)
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 #include <sys/types.h>
13 #include <sys/queue.h>
14 #include <sys/time.h>
15 
16 #include <bitstring.h>
17 #include <limits.h>
18 #include <stdio.h>
19 
20 #include "../common/common.h"
21 #include "vi.h"
22 
23 /*
24  * v_screen -- ^W
25  *	Switch screens.
26  *
27  * PUBLIC: int v_screen(SCR *, VICMD *);
28  */
29 int
30 v_screen(SCR *sp, VICMD *vp)
31 {
32 	/*
33 	 * You can't leave a colon command-line edit window -- it's not that
34 	 * it won't work, but it gets real weird, real fast when you execute
35 	 * a colon command out of a window that was forked from a window that's
36 	 * now backgrounded...  You get the idea.
37 	 */
38 	if (F_ISSET(sp, SC_COMEDIT)) {
39 		msgq(sp, M_ERR,
40 		    "308|Enter <CR> to execute a command, :q to exit");
41 		return (1);
42 	}
43 
44 	/*
45 	 * Try for the next lower screen, or, go back to the first
46 	 * screen on the stack.
47 	 */
48 	if (TAILQ_NEXT(sp, q) != NULL)
49 		sp->nextdisp = TAILQ_NEXT(sp, q);
50 	else if (TAILQ_FIRST(sp->gp->dq) == sp) {
51 		msgq(sp, M_ERR, "187|No other screen to switch to");
52 		return (1);
53 	} else
54 		sp->nextdisp = TAILQ_FIRST(sp->gp->dq);
55 
56 	F_SET(sp->nextdisp, SC_STATUS);
57 	F_SET(sp, SC_SSWITCH | SC_STATUS);
58 	return (0);
59 }
60