Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/aiomixer aiomixer(1): Support the informal NO_COLOR ...



details:   https://anonhg.NetBSD.org/src/rev/61d86e494ac7
branches:  trunk
changeset: 377169:61d86e494ac7
user:      nia <nia%NetBSD.org@localhost>
date:      Thu Jun 29 19:06:54 2023 +0000

description:
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:

 usr.bin/aiomixer/aiomixer.1 |  11 ++++++++---
 usr.bin/aiomixer/app.h      |   3 ++-
 usr.bin/aiomixer/draw.c     |  34 ++++++++++++++++++----------------
 usr.bin/aiomixer/main.c     |  13 +++++++++++--
 4 files changed, 39 insertions(+), 22 deletions(-)

diffs (210 lines):

diff -r 21a6728a7b11 -r 61d86e494ac7 usr.bin/aiomixer/aiomixer.1
--- a/usr.bin/aiomixer/aiomixer.1       Thu Jun 29 16:11:31 2023 +0000
+++ b/usr.bin/aiomixer/aiomixer.1       Thu Jun 29 19:06:54 2023 +0000
@@ -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 dev
 .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 pkg
 properly, among other bugs.
 .Sh AUTHORS
 .Nm
-was written by 
+was written by
 .An Nia Alarie
 .Aq nia%NetBSD.org@localhost .
 .Sh BUGS
diff -r 21a6728a7b11 -r 61d86e494ac7 usr.bin/aiomixer/app.h
--- a/usr.bin/aiomixer/app.h    Thu Jun 29 16:11:31 2023 +0000
+++ b/usr.bin/aiomixer/app.h    Thu Jun 29 19:06:54 2023 +0000
@@ -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 -r 21a6728a7b11 -r 61d86e494ac7 usr.bin/aiomixer/draw.c
--- a/usr.bin/aiomixer/draw.c   Thu Jun 29 16:11:31 2023 +0000
+++ b/usr.bin/aiomixer/draw.c   Thu Jun 29 19:06:54 2023 +0000
@@ -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 *contr
                }
                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 *contr
                }
                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 *contr
 }
 
 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 *contro
 
 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 *con
                }
                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 *con
                    (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 -r 21a6728a7b11 -r 61d86e494ac7 usr.bin/aiomixer/main.c
--- a/usr.bin/aiomixer/main.c   Thu Jun 29 16:11:31 2023 +0000
+++ b/usr.bin/aiomixer/main.c   Thu Jun 29 19:06:54 2023 +0000
@@ -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);



Home | Main Index | Thread Index | Old Index