xref: /openbsd-src/usr.bin/mg/bell.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: bell.c,v 1.4 2016/01/03 19:37:08 lum Exp $	*/
2 
3 /*
4  * This file is in the public domain.
5  *
6  * Author: Mark Lumsden <mark@showcomplex.com>
7  *
8  */
9 
10 /*
11  * Control how mg communicates with the user.
12  */
13 
14 #include <sys/queue.h>
15 #include <signal.h>
16 #include <stdio.h>
17 #include <unistd.h>
18 
19 #include "def.h"
20 #include "macro.h"
21 
22 void
23 bellinit(void)
24 {
25 	doaudiblebell = 1;
26 	dovisiblebell = 0;
27 }
28 
29 void
30 dobeep(void)
31 {
32 	if (doaudiblebell) {
33 		ttbeep();
34 	}
35 	if (dovisiblebell) {
36 		sgarbf = TRUE;
37 		update(CNONE);
38 		if (inmacro)	/* avoid delaying macro execution. */
39 			return;
40 		usleep(50000);
41 	}
42 }
43 
44 /* ARGSUSED */
45 int
46 toggleaudiblebell(int f, int n)
47 {
48 	if (f & FFARG)
49 		doaudiblebell = n > 0;
50 	else
51 		doaudiblebell = !doaudiblebell;
52 
53 	return (TRUE);
54 }
55 
56 /* ARGSUSED */
57 int
58 togglevisiblebell(int f, int n)
59 {
60 	if (f & FFARG)
61 		dovisiblebell = n > 0;
62 	else
63 		dovisiblebell = !dovisiblebell;
64 
65 	return (TRUE);
66 }
67