1/*	$OpenBSD: spawn.c,v 1.13 2023/03/08 04:43:11 guenther 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 */
23int
24spawncli(int f, int n)
25{
26	sigset_t	oset;
27
28	/* Very similar to what vttidy() does. */
29	ttcolor(CTEXT);
30	ttnowindow();
31	ttmove(nrow - 1, 0);
32	if (epresf != FALSE) {
33		tteeol();
34		epresf = FALSE;
35	}
36	if (ttcooked() == FALSE)
37		return (FALSE);
38
39	/* Exit application mode and tidy. */
40	tttidy();
41	ttflush();
42	(void)sigprocmask(SIG_SETMASK, NULL, &oset);
43	(void)kill(0, SIGTSTP);
44	(void)sigprocmask(SIG_SETMASK, &oset, NULL);
45	ttreinit();
46
47	/* Force repaint. */
48	sgarbf = TRUE;
49	return (ttraw());
50}
51