xref: /openbsd/usr.bin/mg/spawn.c (revision 274d7c50)
1 /*	$OpenBSD: spawn.c,v 1.12 2015/03/19 21:22:15 bcallah Exp $	*/
2 
3 /* This file is in the public domain. */
4 
5 /*
6  * Spawn.  Actually just suspends Mg.
7  * Assumes POSIX job control.
8  */
9 
10 #include <sys/queue.h>
11 #include <signal.h>
12 #include <stdio.h>
13 #include <term.h>
14 #include <termios.h>
15 
16 #include "def.h"
17 
18 /*
19  * This causes mg to send itself a stop signal.  It assumes the parent
20  * shell supports POSIX job control.  If the terminal supports an alternate
21  * screen, we will switch to it.
22  */
23 /* ARGSUSED */
24 int
25 spawncli(int f, int n)
26 {
27 	sigset_t	oset;
28 
29 	/* Very similar to what vttidy() does. */
30 	ttcolor(CTEXT);
31 	ttnowindow();
32 	ttmove(nrow - 1, 0);
33 	if (epresf != FALSE) {
34 		tteeol();
35 		epresf = FALSE;
36 	}
37 	if (ttcooked() == FALSE)
38 		return (FALSE);
39 
40 	/* Exit application mode and tidy. */
41 	tttidy();
42 	ttflush();
43 	(void)sigprocmask(SIG_SETMASK, NULL, &oset);
44 	(void)kill(0, SIGTSTP);
45 	(void)sigprocmask(SIG_SETMASK, &oset, NULL);
46 	ttreinit();
47 
48 	/* Force repaint. */
49 	sgarbf = TRUE;
50 	return (ttraw());
51 }
52