xref: /freebsd/contrib/nvi/ex/ex_screen.c (revision bc96366c864c07ef352edb92017357917c75b36c)
1 /*-
2  * Copyright (c) 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 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: ex_screen.c,v 10.12 2001/06/25 15:19:19 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 #include <stdlib.h>
24 #include <string.h>
25 
26 #include "../common/common.h"
27 #include "../vi/vi.h"
28 
29 /*
30  * ex_bg --	:bg
31  *	Hide the screen.
32  *
33  * PUBLIC: int ex_bg __P((SCR *, EXCMD *));
34  */
35 int
36 ex_bg(SCR *sp, EXCMD *cmdp)
37 {
38 	return (vs_bg(sp));
39 }
40 
41 /*
42  * ex_fg --	:fg [file]
43  *	Show the screen.
44  *
45  * PUBLIC: int ex_fg __P((SCR *, EXCMD *));
46  */
47 int
48 ex_fg(SCR *sp, EXCMD *cmdp)
49 {
50 	SCR *nsp;
51 	int newscreen;
52 
53 	newscreen = F_ISSET(cmdp, E_NEWSCREEN);
54 	if (vs_fg(sp, &nsp, cmdp->argc ? cmdp->argv[0]->bp : NULL, newscreen))
55 		return (1);
56 
57 	/* Set up the switch. */
58 	if (newscreen) {
59 		sp->nextdisp = nsp;
60 		F_SET(sp, SC_SSWITCH);
61 	}
62 	return (0);
63 }
64 
65 /*
66  * ex_resize --	:resize [+-]rows
67  *	Change the screen size.
68  *
69  * PUBLIC: int ex_resize __P((SCR *, EXCMD *));
70  */
71 int
72 ex_resize(SCR *sp, EXCMD *cmdp)
73 {
74 	adj_t adj;
75 
76 	switch (FL_ISSET(cmdp->iflags,
77 	    E_C_COUNT | E_C_COUNT_NEG | E_C_COUNT_POS)) {
78 	case E_C_COUNT:
79 		adj = A_SET;
80 		break;
81 	case E_C_COUNT | E_C_COUNT_NEG:
82 		adj = A_DECREASE;
83 		break;
84 	case E_C_COUNT | E_C_COUNT_POS:
85 		adj = A_INCREASE;
86 		break;
87 	default:
88 		ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
89 		return (1);
90 	}
91 	return (vs_resize(sp, cmdp->count, adj));
92 }
93 
94 /*
95  * ex_sdisplay --
96  *	Display the list of screens.
97  *
98  * PUBLIC: int ex_sdisplay __P((SCR *));
99  */
100 int
101 ex_sdisplay(SCR *sp)
102 {
103 	GS *gp;
104 	SCR *tsp;
105 	int cnt, col, len, sep;
106 
107 	gp = sp->gp;
108 	if ((tsp = TAILQ_FIRST(gp->hq)) == NULL) {
109 		msgq(sp, M_INFO, "149|No background screens to display");
110 		return (0);
111 	}
112 
113 	col = len = sep = 0;
114 	for (cnt = 1; tsp != NULL && !INTERRUPTED(sp);
115 	    tsp = TAILQ_NEXT(tsp, q)) {
116 		col += len = strlen(tsp->frp->name) + sep;
117 		if (col >= sp->cols - 1) {
118 			col = len;
119 			sep = 0;
120 			(void)ex_puts(sp, "\n");
121 		} else if (cnt != 1) {
122 			sep = 1;
123 			(void)ex_puts(sp, " ");
124 		}
125 		(void)ex_puts(sp, tsp->frp->name);
126 		++cnt;
127 	}
128 	if (!INTERRUPTED(sp))
129 		(void)ex_puts(sp, "\n");
130 	return (0);
131 }
132