1 /* $OpenBSD: bell.c,v 1.7 2023/03/08 04:43:11 guenther 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
bellinit(void)23 bellinit(void)
24 {
25 doaudiblebell = 1;
26 dovisiblebell = 0;
27 }
28
29 int
dobeep_num(const char * msg,int n)30 dobeep_num(const char *msg, int n)
31 {
32 ewprintf("%s %d", msg, n);
33 dobeep();
34 return (FALSE);
35 }
36
37 int
dobeep_msgs(const char * msg,const char * s)38 dobeep_msgs(const char *msg, const char *s)
39 {
40 ewprintf("%s %s", msg, s);
41 dobeep();
42 return (FALSE);
43 }
44
45 int
dobeep_msg(const char * msg)46 dobeep_msg(const char *msg)
47 {
48 ewprintf("%s", msg);
49 dobeep();
50 return (FALSE);
51 }
52
53 void
dobeep(void)54 dobeep(void)
55 {
56 if (doaudiblebell) {
57 ttbeep();
58 }
59 if (dovisiblebell) {
60 sgarbf = TRUE;
61 update(CNONE);
62 if (inmacro) /* avoid delaying macro execution. */
63 return;
64 usleep(50000);
65 }
66 }
67
68 int
toggleaudiblebell(int f,int n)69 toggleaudiblebell(int f, int n)
70 {
71 if (f & FFARG)
72 doaudiblebell = n > 0;
73 else
74 doaudiblebell = !doaudiblebell;
75
76 return (TRUE);
77 }
78
79 int
togglevisiblebell(int f,int n)80 togglevisiblebell(int f, int n)
81 {
82 if (f & FFARG)
83 dovisiblebell = n > 0;
84 else
85 dovisiblebell = !dovisiblebell;
86
87 return (TRUE);
88 }
89