summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorlum <lum@cvs.openbsd.org>2013-05-31 18:03:46 +0000
committerlum <lum@cvs.openbsd.org>2013-05-31 18:03:46 +0000
commit89898428a3cd3024fcc224f907cf67f832b77959 (patch)
tree0c370e56a3fcbae91639d6355f1b577321bd72da /usr.bin
parent0faf86143c2027b28f4556d51a85d11a7d34d175 (diff)
Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'. ok florian@ jasper@ Feedback Sunil Nimmagadda.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/Makefile4
-rw-r--r--usr.bin/mg/basic.c14
-rw-r--r--usr.bin/mg/bell.c60
-rw-r--r--usr.bin/mg/def.h13
-rw-r--r--usr.bin/mg/display.c12
-rw-r--r--usr.bin/mg/echo.c4
-rw-r--r--usr.bin/mg/funmap.c4
-rw-r--r--usr.bin/mg/kbd.c4
-rw-r--r--usr.bin/mg/main.c14
-rw-r--r--usr.bin/mg/match.c8
-rw-r--r--usr.bin/mg/mg.18
-rw-r--r--usr.bin/mg/re_search.c6
-rw-r--r--usr.bin/mg/search.c28
-rw-r--r--usr.bin/mg/window.c4
14 files changed, 134 insertions, 49 deletions
diff --git a/usr.bin/mg/Makefile b/usr.bin/mg/Makefile
index b5ed6482d39..023ed17fa16 100644
--- a/usr.bin/mg/Makefile
+++ b/usr.bin/mg/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.27 2012/06/18 07:13:26 jasper Exp $
+# $OpenBSD: Makefile,v 1.28 2013/05/31 18:03:43 lum Exp $
PROG= mg
@@ -15,7 +15,7 @@ DPADD+= ${LIBCURSES} ${LIBUTIL}
#
CFLAGS+=-Wall -DFKEYS -DREGEX -DXKEYS
-SRCS= autoexec.c basic.c buffer.c cinfo.c dir.c display.c \
+SRCS= autoexec.c basic.c bell.c buffer.c cinfo.c dir.c display.c \
echo.c extend.c file.c fileio.c funmap.c help.c kbd.c keymap.c \
line.c macro.c main.c match.c modes.c paragraph.c random.c \
re_search.c region.c search.c spawn.c tty.c ttyio.c ttykbd.c \
diff --git a/usr.bin/mg/basic.c b/usr.bin/mg/basic.c
index 91baf36b856..c4c24ddfe4c 100644
--- a/usr.bin/mg/basic.c
+++ b/usr.bin/mg/basic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: basic.c,v 1.39 2013/03/25 11:41:44 florian Exp $ */
+/* $OpenBSD: basic.c,v 1.40 2013/05/31 18:03:43 lum Exp $ */
/* This file is in the public domain */
@@ -43,8 +43,10 @@ backchar(int f, int n)
while (n--) {
if (curwp->w_doto == 0) {
if ((lp = lback(curwp->w_dotp)) == curbp->b_headp) {
- if (!(f & FFRAND))
+ if (!(f & FFRAND)) {
+ dobeep();
ewprintf("Beginning of buffer");
+ }
return (FALSE);
}
curwp->w_dotp = lp;
@@ -85,8 +87,10 @@ forwchar(int f, int n)
curwp->w_dotp = lforw(curwp->w_dotp);
if (curwp->w_dotp == curbp->b_headp) {
curwp->w_dotp = lback(curwp->w_dotp);
- if (!(f & FFRAND))
+ if (!(f & FFRAND)) {
+ dobeep();
ewprintf("End of buffer");
+ }
return (FALSE);
}
curwp->w_doto = 0;
@@ -283,7 +287,7 @@ forwpage(int f, int n)
lp = curwp->w_linep;
while (n--)
if ((lp = lforw(lp)) == curbp->b_headp) {
- ttbeep();
+ dobeep();
ewprintf("End of buffer");
return(TRUE);
}
@@ -332,7 +336,7 @@ backpage(int f, int n)
lp = lback(lp);
}
if (lp == curwp->w_linep) {
- ttbeep();
+ dobeep();
ewprintf("Beginning of buffer");
}
curwp->w_linep = lp;
diff --git a/usr.bin/mg/bell.c b/usr.bin/mg/bell.c
new file mode 100644
index 00000000000..aa24bf65ea0
--- /dev/null
+++ b/usr.bin/mg/bell.c
@@ -0,0 +1,60 @@
+/* $OpenBSD: bell.c,v 1.1 2013/05/31 18:03:43 lum Exp $ */
+
+/*
+ * This file is in the public domain.
+ *
+ * Author: Mark Lumsden <mark@showcomplex.com>
+ *
+ */
+
+/*
+ * Control how mg communicates with the user.
+ */
+
+#include "def.h"
+
+void
+bellinit(void)
+{
+ doaudiblebell = 1;
+ dovisiblebell = 0;
+ donebell = 0;
+}
+
+void
+dobeep(void)
+{
+ if (doaudiblebell) {
+ ttbeep();
+ }
+ if (dovisiblebell) {
+ sgarbf = TRUE;
+ update(CNONE);
+ usleep(50000);
+ }
+ donebell = 1;
+}
+
+/* ARGSUSED */
+int
+toggleaudiblebell(int f, int n)
+{
+ if (f & FFARG)
+ doaudiblebell = n > 0;
+ else
+ doaudiblebell = !doaudiblebell;
+
+ return (TRUE);
+}
+
+/* ARGSUSED */
+int
+togglevisiblebell(int f, int n)
+{
+ if (f & FFARG)
+ dovisiblebell = n > 0;
+ else
+ dovisiblebell = !dovisiblebell;
+
+ return (TRUE);
+}
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 3621f5c61f2..1ef0edc399a 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.137 2013/05/30 04:17:25 lum Exp $ */
+/* $OpenBSD: def.h,v 1.138 2013/05/31 18:03:43 lum Exp $ */
/* This file is in the public domain. */
@@ -424,7 +424,7 @@ int diffbuffer(int, int);
int vtresize(int, int, int);
void vtinit(void);
void vttidy(void);
-void update(void);
+void update(int);
int linenotoggle(int, int);
int colnotoggle(int, int);
@@ -681,6 +681,12 @@ int next_error(int, int);
int globalwdtoggle(int, int);
int compile(int, int);
+/* bell.c */
+void bellinit(void);
+int toggleaudiblebell(int, int);
+int togglevisiblebell(int, int);
+void dobeep(void);
+
/*
* Externals.
*/
@@ -704,6 +710,9 @@ extern int ttbot;
extern int tthue;
extern int defb_nmodes;
extern int defb_flag;
+extern int doaudiblebell;
+extern int dovisiblebell;
+extern int donebell;
extern char cinfo[];
extern char *keystrings[];
extern char pat[NPAT];
diff --git a/usr.bin/mg/display.c b/usr.bin/mg/display.c
index 69f2a3fb6c8..12f83f3c323 100644
--- a/usr.bin/mg/display.c
+++ b/usr.bin/mg/display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: display.c,v 1.40 2013/03/25 11:41:44 florian Exp $ */
+/* $OpenBSD: display.c,v 1.41 2013/05/31 18:03:44 lum Exp $ */
/* This file is in the public domain. */
@@ -68,7 +68,7 @@ void vtpute(int);
int vtputs(const char *);
void vteeol(void);
void updext(int, int);
-void modeline(struct mgwin *);
+void modeline(struct mgwin *, int);
void setscores(int, int);
void traceback(int, int, int, int);
void ucopy(struct video *, struct video *);
@@ -403,7 +403,7 @@ vteeol(void)
* virtual and physical screens the same.
*/
void
-update(void)
+update(int modelinecolor)
{
struct line *lp;
struct mgwin *wp;
@@ -503,7 +503,7 @@ update(void)
}
}
if ((wp->w_rflag & WFMODE) != 0)
- modeline(wp);
+ modeline(wp, modelinecolor);
wp->w_rflag = 0;
wp->w_frame = 0;
}
@@ -796,7 +796,7 @@ uline(int row, struct video *vvp, struct video *pvp)
* characters may never be seen.
*/
void
-modeline(struct mgwin *wp)
+modeline(struct mgwin *wp, int modelinecolor)
{
int n, md;
struct buffer *bp;
@@ -804,7 +804,7 @@ modeline(struct mgwin *wp)
int len;
n = wp->w_toprow + wp->w_ntrows; /* Location. */
- vscreen[n]->v_color = CMODE; /* Mode line color. */
+ vscreen[n]->v_color = modelinecolor; /* Mode line color. */
vscreen[n]->v_flag |= (VFCHG | VFHBAD); /* Recompute, display. */
vtmove(n, 0); /* Seek to right line. */
bp = wp->w_bufp;
diff --git a/usr.bin/mg/echo.c b/usr.bin/mg/echo.c
index e736bb972cc..0100ef5b041 100644
--- a/usr.bin/mg/echo.c
+++ b/usr.bin/mg/echo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: echo.c,v 1.54 2012/11/03 16:28:14 florian Exp $ */
+/* $OpenBSD: echo.c,v 1.55 2013/05/31 18:03:44 lum Exp $ */
/* This file is in the public domain. */
@@ -756,7 +756,7 @@ complt_list(int flags, char *buf, int cpos)
free_file_list(wholelist);
popbuftop(bp, WEPHEM); /* split the screen and put up the help
* buffer */
- update(); /* needed to make the new stuff actually
+ update(CMODE); /* needed to make the new stuff actually
* appear */
ttmove(oldrow, oldcol); /* update leaves cursor in arbitrary place */
ttcolor(oldhue); /* with arbitrary color */
diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c
index e8bf7113a85..b10a2cda3af 100644
--- a/usr.bin/mg/funmap.c
+++ b/usr.bin/mg/funmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: funmap.c,v 1.46 2013/05/22 19:23:45 lum Exp $ */
+/* $OpenBSD: funmap.c,v 1.47 2013/05/31 18:03:44 lum Exp $ */
/* This file is in the public domain */
@@ -21,6 +21,7 @@ static struct funmap *funs;
static struct funmap functnames[] = {
{apropos_command, "apropos",},
+ {toggleaudiblebell, "audible-bell",},
{auto_execute, "auto-execute",},
{fillmode, "auto-fill-mode",},
{indentmode, "auto-indent-mode",},
@@ -200,6 +201,7 @@ static struct funmap functnames[] = {
{universal_argument, "universal-argument",},
{upperregion, "upcase-region",},
{upperword, "upcase-word",},
+ {togglevisiblebell, "visible-bell",},
{tagsvisit, "visit-tags-table",},
{showcpos, "what-cursor-position",},
{filewrite, "write-file",},
diff --git a/usr.bin/mg/kbd.c b/usr.bin/mg/kbd.c
index 0eb3c360853..2c2803952e1 100644
--- a/usr.bin/mg/kbd.c
+++ b/usr.bin/mg/kbd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kbd.c,v 1.25 2012/04/12 04:47:59 lum Exp $ */
+/* $OpenBSD: kbd.c,v 1.26 2013/05/31 18:03:44 lum Exp $ */
/* This file is in the public domain. */
@@ -81,7 +81,7 @@ getkey(int flag)
/* avoid problems with % */
ewprintf("%s", prompt);
/* put the cursor back */
- update();
+ update(CMODE);
epresf = KCLEAR;
}
if (promptp > prompt)
diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c
index 804db934d32..cb105323b55 100644
--- a/usr.bin/mg/main.c
+++ b/usr.bin/mg/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.70 2012/12/28 16:12:50 naddy Exp $ */
+/* $OpenBSD: main.c,v 1.71 2013/05/31 18:03:44 lum Exp $ */
/* This file is in the public domain. */
@@ -18,6 +18,9 @@ int thisflag; /* flags, this command */
int lastflag; /* flags, last command */
int curgoal; /* goal column */
int startrow; /* row to start */
+int doaudiblebell; /* audible bell toggle */
+int dovisiblebell; /* visible bell toggle */
+int donebell; /* done't wring bell */
struct buffer *curbp; /* current buffer */
struct buffer *bheadp; /* BUFFER list head */
struct mgwin *curwp; /* current window */
@@ -93,13 +96,14 @@ main(int argc, char **argv)
dirinit(); /* Get current directory. */
edinit(bp); /* Buffers, windows. */
ttykeymapinit(); /* Symbols, bindings. */
+ bellinit(); /* Audible and visible bell. */
/*
* doing update() before reading files causes the error messages from
* the file I/O show up on the screen. (and also an extra display of
* the mode line if there are files specified on the command line.)
*/
- update();
+ update(CMODE);
/* user startup file. */
if ((cp = startupfile(NULL)) != NULL)
@@ -171,7 +175,7 @@ notnum:
do_redraw(0, 0, TRUE);
winch_flag = 0;
}
- update();
+ update(CMODE);
lastflag = thisflag;
thisflag = 0;
@@ -183,9 +187,11 @@ notnum:
/* FALLTHRU */
case FALSE:
default:
- ttbeep();
+ if (!donebell)
+ dobeep();
macrodef = FALSE;
}
+ donebell = 0;
}
}
diff --git a/usr.bin/mg/match.c b/usr.bin/mg/match.c
index 4c5d0c31d0b..448679fa074 100644
--- a/usr.bin/mg/match.c
+++ b/usr.bin/mg/match.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: match.c,v 1.16 2009/06/04 02:23:37 kjell Exp $ */
+/* $OpenBSD: match.c,v 1.17 2013/05/31 18:03:44 lum Exp $ */
/* This file is in the public domain. */
@@ -45,7 +45,7 @@ showmatch(int f, int n)
return (s);
/* unbalanced -- warn user */
if (balance() != TRUE)
- ttbeep();
+ dobeep();
}
return (TRUE);
}
@@ -152,13 +152,13 @@ displaymatch(struct line *clp, int cbo)
curwp->w_doto = cbo;
curwp->w_rflag |= WFMOVE;
- update(); /* show match */
+ update(CMODE); /* show match */
ttwait(1000); /* wait for key or 1 second */
curwp->w_dotp = tlp; /* return to old position */
curwp->w_doto = tbo;
curwp->w_rflag |= WFMOVE;
- update();
+ update(CMODE);
} else {
/* match is not in this window, so display line in echo area */
bufo = 0;
diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1
index 5b010abb4e7..5cbeb2d43a7 100644
--- a/usr.bin/mg/mg.1
+++ b/usr.bin/mg/mg.1
@@ -1,7 +1,7 @@
-.\" $OpenBSD: mg.1,v 1.78 2013/05/27 19:28:51 jmc Exp $
+.\" $OpenBSD: mg.1,v 1.79 2013/05/31 18:03:44 lum Exp $
.\" This file is in the public domain.
.\"
-.Dd $Mdocdate: May 27 2013 $
+.Dd $Mdocdate: May 31 2013 $
.Dt MG 1
.Os
.Sh NAME
@@ -361,6 +361,8 @@ Prompt the user for a string, open the *help* buffer,
and list all
.Nm
commands that contain that string.
+.It audible-bell
+Toggle the audible system bell.
.It auto-execute
Register an auto-execute hook; that is, specify a filename pattern
(conforming to the shell's filename globbing rules) and an associated
@@ -897,6 +899,8 @@ upper case.
.It upcase-word
Move the cursor forward by the specified number of words.
As it moves, convert any characters to upper case.
+.It visible-bell
+Toggle the visible bell. If this toggle is on, the modeline will flash.
.It visit-tags-table
Record name of the tags file to be used for subsequent find-tag.
.It what-cursor-position
diff --git a/usr.bin/mg/re_search.c b/usr.bin/mg/re_search.c
index db39fdc8e70..87f559e2725 100644
--- a/usr.bin/mg/re_search.c
+++ b/usr.bin/mg/re_search.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: re_search.c,v 1.26 2011/01/21 19:10:13 kjell Exp $ */
+/* $OpenBSD: re_search.c,v 1.27 2013/05/31 18:03:45 lum Exp $ */
/* This file is in the public domain. */
@@ -149,7 +149,7 @@ re_queryrepl(int f, int n)
*/
while (re_forwsrch() == TRUE) {
retry:
- update();
+ update(CMODE);
switch (getkey(FALSE)) {
case ' ':
plen = re_match[0].rm_eo - re_match[0].rm_so;
@@ -191,7 +191,7 @@ retry:
stopsearch:
curwp->w_rflag |= WFFULL;
- update();
+ update(CMODE);
if (!inmacro) {
if (rcnt == 0)
ewprintf("(No replacements done)");
diff --git a/usr.bin/mg/search.c b/usr.bin/mg/search.c
index 38d5e1a1307..1ad15afb8af 100644
--- a/usr.bin/mg/search.c
+++ b/usr.bin/mg/search.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: search.c,v 1.41 2012/09/07 19:01:56 lum Exp $ */
+/* $OpenBSD: search.c,v 1.42 2013/05/31 18:03:45 lum Exp $ */
/* This file is in the public domain. */
@@ -192,7 +192,7 @@ isearch(int dir)
is_prompt(dir, TRUE, success);
for (;;) {
- update();
+ update(CMODE);
switch (c = getkey(FALSE)) {
case CCHR('['):
@@ -248,7 +248,7 @@ isearch(int dir)
is_lpush();
pptr = strlen(pat);
if (forwchar(FFRAND, 1) == FALSE) {
- ttbeep();
+ dobeep();
success = FALSE;
ewprintf("Failed I-search: %s", pat);
} else {
@@ -256,7 +256,7 @@ isearch(int dir)
is_cpush(SRCH_MARK);
else {
(void)backchar(FFRAND, 1);
- ttbeep();
+ dobeep();
success = FALSE;
ewprintf("Failed I-search: %s", pat);
}
@@ -285,14 +285,14 @@ isearch(int dir)
is_lpush();
pptr = strlen(pat);
if (backchar(FFRAND, 1) == FALSE) {
- ttbeep();
+ dobeep();
success = FALSE;
} else {
if (is_find(SRCH_BACK) != FALSE)
is_cpush(SRCH_MARK);
else {
(void)forwchar(FFRAND, 1);
- ttbeep();
+ dobeep();
success = FALSE;
}
}
@@ -322,7 +322,7 @@ isearch(int dir)
break;
if (pptr == NPAT - 1) {
- ttbeep();
+ dobeep();
break;
}
firstc = 0;
@@ -335,7 +335,7 @@ isearch(int dir)
if (dir == SRCH_FORW) {
curwp->w_doto = cbo;
curwp->w_rflag |= WFMOVE;
- update();
+ update(CMODE);
}
}
is_prompt(dir, pptr < 0, success);
@@ -373,7 +373,7 @@ isearch(int dir)
if (pptr == 0)
success = TRUE;
if (pptr == NPAT - 1)
- ttbeep();
+ dobeep();
else {
pat[pptr++] = c;
pat[pptr] = '\0';
@@ -384,7 +384,7 @@ isearch(int dir)
is_cpush(c);
else {
success = FALSE;
- ttbeep();
+ dobeep();
is_cpush(SRCH_ACCM);
}
} else
@@ -579,7 +579,7 @@ queryrepl(int f, int n)
*/
while (forwsrch() == TRUE) {
retry:
- update();
+ update(CMODE);
switch (getkey(FALSE)) {
case 'y':
case ' ':
@@ -618,7 +618,7 @@ retry:
}
stopsearch:
curwp->w_rflag |= WFFULL;
- update();
+ update(CMODE);
if (rcnt == 1)
ewprintf("Replaced 1 occurrence");
else
@@ -647,7 +647,7 @@ replstr(int f, int n)
plen = strlen(pat);
while (forwsrch() == TRUE) {
- update();
+ update(CMODE);
if (lreplace((RSIZE)plen, news) == FALSE)
return (FALSE);
@@ -655,7 +655,7 @@ replstr(int f, int n)
}
curwp->w_rflag |= WFFULL;
- update();
+ update(CMODE);
if (rcnt == 1)
ewprintf("Replaced 1 occurrence");
diff --git a/usr.bin/mg/window.c b/usr.bin/mg/window.c
index db913c95022..c93e713be84 100644
--- a/usr.bin/mg/window.c
+++ b/usr.bin/mg/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.28 2011/08/01 12:15:23 lum Exp $ */
+/* $OpenBSD: window.c,v 1.29 2013/05/31 18:03:45 lum Exp $ */
/* This file is in the public domain. */
@@ -97,7 +97,7 @@ do_redraw(int f, int n, int force)
}
wp->w_ntrows = nrow - wp->w_toprow - 2;
sgarbf = TRUE;
- update();
+ update(CMODE);
} else
sgarbf = TRUE;
return (TRUE);