xref: /openbsd-src/usr.bin/mg/bell.c (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
1 /*	$OpenBSD: bell.c,v 1.5 2019/07/17 18:18:37 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 int
30 dobeep_msgs(const char *msg, const char *s)
31 {
32 	ewprintf("%s %s", msg, s);
33 	dobeep();
34 	return (FALSE);
35 }
36 
37 int
38 dobeep_msg(const char *msg)
39 {
40 	ewprintf("%s", msg);
41 	dobeep();
42 	return (FALSE);
43 }
44 
45 void
46 dobeep(void)
47 {
48 	if (doaudiblebell) {
49 		ttbeep();
50 	}
51 	if (dovisiblebell) {
52 		sgarbf = TRUE;
53 		update(CNONE);
54 		if (inmacro)	/* avoid delaying macro execution. */
55 			return;
56 		usleep(50000);
57 	}
58 }
59 
60 /* ARGSUSED */
61 int
62 toggleaudiblebell(int f, int n)
63 {
64 	if (f & FFARG)
65 		doaudiblebell = n > 0;
66 	else
67 		doaudiblebell = !doaudiblebell;
68 
69 	return (TRUE);
70 }
71 
72 /* ARGSUSED */
73 int
74 togglevisiblebell(int f, int n)
75 {
76 	if (f & FFARG)
77 		dovisiblebell = n > 0;
78 	else
79 		dovisiblebell = !dovisiblebell;
80 
81 	return (TRUE);
82 }
83