summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authornia <nia@NetBSD.org>2023-06-29 19:06:54 +0000
committernia <nia@NetBSD.org>2023-06-29 19:06:54 +0000
commit27a47761efb2efebd1979988501cecc8d71eadc5 (patch)
tree8a5ddd28e4c0daeacd7078d6ec8780f162b148cc /usr.bin
parent3a21b4f1009c422e2485c5d90b71dfc4a9ade298 (diff)
aiomixer(1): Support the informal NO_COLOR standard.
When the NO_COLOR environment variable is set, no ANSI colours will be displayed. https://no-color.org/
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/aiomixer/aiomixer.111
-rw-r--r--usr.bin/aiomixer/app.h3
-rw-r--r--usr.bin/aiomixer/draw.c34
-rw-r--r--usr.bin/aiomixer/main.c13
4 files changed, 39 insertions, 22 deletions
diff --git a/usr.bin/aiomixer/aiomixer.1 b/usr.bin/aiomixer/aiomixer.1
index 23d75dc3005..658e24a7425 100644
--- a/usr.bin/aiomixer/aiomixer.1
+++ b/usr.bin/aiomixer/aiomixer.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: aiomixer.1,v 1.1 2021/05/07 16:29:24 nia Exp $
+.\" $NetBSD: aiomixer.1,v 1.2 2023/06/29 19:06:54 nia Exp $
.\"
.\" Copyright (c) 2021 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd April 4, 2019
+.Dd July 29, 2023
.Dt AIOMIXER 1
.Os
.Sh NAME
@@ -67,6 +67,11 @@ Used to specify an alternative mixer device.
.It Fl u
Used to unlock channels on start up.
.El
+.Pp
+.Nm
+honours the informal standard
+.Dv NO_COLOR .
+When it is set in the environment, no colour will be used.
.Sh FILES
.Bl -tag -width /dev/mixer[0-3] -compact
.It Pa /dev/mixer
@@ -81,7 +86,7 @@ The first version (only available in pkgsrc) didn't support
properly, among other bugs.
.Sh AUTHORS
.Nm
-was written by
+was written by
.An Nia Alarie
.Aq nia@NetBSD.org .
.Sh BUGS
diff --git a/usr.bin/aiomixer/app.h b/usr.bin/aiomixer/app.h
index 8c4521107f4..982f48afaf2 100644
--- a/usr.bin/aiomixer/app.h
+++ b/usr.bin/aiomixer/app.h
@@ -1,4 +1,4 @@
-/* $NetBSD: app.h,v 1.1 2021/05/07 16:29:24 nia Exp $ */
+/* $NetBSD: app.h,v 1.2 2023/06/29 19:06:54 nia Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -70,6 +70,7 @@ struct aiomixer {
bool widgets_resized;
WINDOW *header;
WINDOW *classbar;
+ bool use_colour;
};
#define COLOR_CONTROL_SELECTED 1
diff --git a/usr.bin/aiomixer/draw.c b/usr.bin/aiomixer/draw.c
index 4c51dd6eb44..ffc83f06897 100644
--- a/usr.bin/aiomixer/draw.c
+++ b/usr.bin/aiomixer/draw.c
@@ -1,4 +1,4 @@
-/* $NetBSD: draw.c,v 1.9 2021/07/15 07:03:14 nia Exp $ */
+/* $NetBSD: draw.c,v 1.10 2023/06/29 19:06:54 nia Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -37,10 +37,10 @@
#include "draw.h"
static int get_enum_color(const char *);
-static void draw_enum(struct aiomixer_control *, int, bool);
-static void draw_set(struct aiomixer_control *, int);
+static void draw_enum(struct aiomixer_control *, int, bool, bool);
+static void draw_set(struct aiomixer_control *, int, bool);
static void draw_levels(struct aiomixer_control *,
- const struct mixer_level *, bool, bool);
+ const struct mixer_level *, bool, bool, bool);
void
draw_mixer_select(unsigned int num_mixers, unsigned int selected_mixer)
@@ -103,14 +103,14 @@ draw_control(struct aiomixer *aio,
switch (value.type) {
case AUDIO_MIXER_ENUM:
- draw_enum(control, value.un.ord, selected);
+ draw_enum(control, value.un.ord, selected, aio->use_colour);
break;
case AUDIO_MIXER_SET:
- draw_set(control, value.un.mask);
+ draw_set(control, value.un.mask, aio->use_colour);
break;
case AUDIO_MIXER_VALUE:
draw_levels(control, &value.un.value,
- aio->channels_unlocked, selected);
+ aio->channels_unlocked, selected, aio->use_colour);
break;
}
@@ -159,7 +159,8 @@ get_enum_color(const char *name)
}
static void
-draw_enum(struct aiomixer_control *control, int ord, bool selected)
+draw_enum(struct aiomixer_control *control, int ord,
+ bool selected, bool colour)
{
struct audio_mixer_enum *e;
int color = COLOR_ENUM_MISC;
@@ -175,7 +176,7 @@ draw_enum(struct aiomixer_control *control, int ord, bool selected)
}
waddch(control->widgetpad, '[');
if (ord == e->member[i].ord) {
- if (has_colors()) {
+ if (colour) {
color = get_enum_color(e->member[i].label.name);
wattron(control->widgetpad,
COLOR_PAIR(color));
@@ -185,7 +186,7 @@ draw_enum(struct aiomixer_control *control, int ord, bool selected)
}
wprintw(control->widgetpad, "%s", e->member[i].label.name);
if (ord == control->info.un.e.member[i].ord) {
- if (has_colors()) {
+ if (colour) {
wattroff(control->widgetpad,
COLOR_PAIR(color));
}
@@ -204,19 +205,19 @@ draw_enum(struct aiomixer_control *control, int ord, bool selected)
}
static void
-draw_set(struct aiomixer_control *control, int mask)
+draw_set(struct aiomixer_control *control, int mask, bool colour)
{
int i;
for (i = 0; i < control->info.un.s.num_mem; ++i) {
waddch(control->widgetpad, '[');
if (mask & control->info.un.s.member[i].mask) {
- if (has_colors()) {
+ if (colour) {
wattron(control->widgetpad,
COLOR_PAIR(COLOR_SET_SELECTED));
}
waddch(control->widgetpad, '*');
- if (has_colors()) {
+ if (colour) {
wattroff(control->widgetpad,
COLOR_PAIR(COLOR_SET_SELECTED));
}
@@ -245,7 +246,8 @@ draw_set(struct aiomixer_control *control, int mask)
static void
draw_levels(struct aiomixer_control *control,
- const struct mixer_level *levels, bool channels_unlocked, bool selected)
+ const struct mixer_level *levels, bool channels_unlocked,
+ bool selected, bool colour)
{
int i;
int j, nchars;
@@ -260,7 +262,7 @@ draw_levels(struct aiomixer_control *control,
}
wprintw(control->widgetpad, "[%3u/%3u ",
levels->level[i], AUDIO_MAX_GAIN);
- if (has_colors()) {
+ if (colour) {
wattron(control->widgetpad,
COLOR_PAIR(COLOR_LEVELS));
}
@@ -268,7 +270,7 @@ draw_levels(struct aiomixer_control *control,
(getmaxx(control->widgetpad) - 11)) / AUDIO_MAX_GAIN;
for (j = 0; j < nchars; ++j)
waddch(control->widgetpad, '*');
- if (has_colors()) {
+ if (colour) {
wattroff(control->widgetpad,
COLOR_PAIR(COLOR_LEVELS));
}
diff --git a/usr.bin/aiomixer/main.c b/usr.bin/aiomixer/main.c
index d8708cf45ca..90f7fe1ba38 100644
--- a/usr.bin/aiomixer/main.c
+++ b/usr.bin/aiomixer/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.4 2021/07/18 11:45:31 nia Exp $ */
+/* $NetBSD: main.c,v 1.5 2023/06/29 19:06:54 nia Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -501,6 +501,7 @@ main(int argc, char **argv)
unsigned int mixer_count = 0;
int i, fd;
int ch;
+ char *no_color = getenv("NO_COLOR");
if ((aio = malloc(sizeof(struct aiomixer))) == NULL) {
err(EXIT_FAILURE, "malloc failed");
@@ -535,7 +536,15 @@ main(int argc, char **argv)
cbreak();
noecho();
- if (has_colors()) {
+ aio->use_colour = true;
+
+ if (!has_colors())
+ aio->use_colour = false;
+
+ if (no_color != NULL && no_color[0] != '\0')
+ aio->use_colour = false;
+
+ if (aio->use_colour) {
start_color();
use_default_colors();
init_pair(COLOR_CONTROL_SELECTED, COLOR_BLUE, COLOR_BLACK);