1 /* $OpenBSD: ex_screen.c,v 1.10 2016/01/06 22:28:52 millert Exp $ */
2
3 /*-
4 * Copyright (c) 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
8 *
9 * See the LICENSE file for redistribution information.
10 */
11
12 #include "config.h"
13
14 #include <sys/types.h>
15 #include <sys/queue.h>
16 #include <sys/time.h>
17
18 #include <bitstring.h>
19 #include <limits.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include "../common/common.h"
25 #include "../vi/vi.h"
26
27 /*
28 * ex_bg -- :bg
29 * Hide the screen.
30 *
31 * PUBLIC: int ex_bg(SCR *, EXCMD *);
32 */
33 int
ex_bg(SCR * sp,EXCMD * cmdp)34 ex_bg(SCR *sp, EXCMD *cmdp)
35 {
36 return (vs_bg(sp));
37 }
38
39 /*
40 * ex_fg -- :fg [file]
41 * Show the screen.
42 *
43 * PUBLIC: int ex_fg(SCR *, EXCMD *);
44 */
45 int
ex_fg(SCR * sp,EXCMD * cmdp)46 ex_fg(SCR *sp, EXCMD *cmdp)
47 {
48 SCR *nsp;
49 int newscreen;
50
51 newscreen = F_ISSET(cmdp, E_NEWSCREEN);
52 if (vs_fg(sp, &nsp, cmdp->argc ? cmdp->argv[0]->bp : NULL, newscreen))
53 return (1);
54
55 /* Set up the switch. */
56 if (newscreen) {
57 sp->nextdisp = nsp;
58 F_SET(sp, SC_SSWITCH);
59 }
60 return (0);
61 }
62
63 /*
64 * ex_resize -- :resize [+-]rows
65 * Change the screen size.
66 *
67 * PUBLIC: int ex_resize(SCR *, EXCMD *);
68 */
69 int
ex_resize(SCR * sp,EXCMD * cmdp)70 ex_resize(SCR *sp, EXCMD *cmdp)
71 {
72 adj_t adj;
73
74 switch (FL_ISSET(cmdp->iflags,
75 E_C_COUNT | E_C_COUNT_NEG | E_C_COUNT_POS)) {
76 case E_C_COUNT:
77 adj = A_SET;
78 break;
79 case E_C_COUNT | E_C_COUNT_NEG:
80 adj = A_DECREASE;
81 break;
82 case E_C_COUNT | E_C_COUNT_POS:
83 adj = A_INCREASE;
84 break;
85 default:
86 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
87 return (1);
88 }
89 return (vs_resize(sp, cmdp->count, adj));
90 }
91
92 /*
93 * ex_sdisplay --
94 * Display the list of screens.
95 *
96 * PUBLIC: int ex_sdisplay(SCR *);
97 */
98 int
ex_sdisplay(SCR * sp)99 ex_sdisplay(SCR *sp)
100 {
101 GS *gp;
102 SCR *tsp;
103 int cnt, col, len, sep;
104
105 gp = sp->gp;
106 if (TAILQ_EMPTY(&gp->hq)) {
107 msgq(sp, M_INFO, "No background screens to display");
108 return (0);
109 }
110
111 col = len = sep = 0;
112 cnt = 1;
113 TAILQ_FOREACH(tsp, &gp->hq, q) {
114 if (INTERRUPTED(sp))
115 break;
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