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

Bug#1010806: apt: Avoid color output on monochrome terminals



1010806@bugs.debian.org

On Thu, 26 May 2022 11:03:25 +0200 Axel Scheepers
<axel.scheepers76@gmail.com> wrote:
> Or the other way around as I proposed. The entire problem of knowing what
> and how to use color goes away when curses is used. Would you accept a
> patch for using that instead?

I've forgot about this but how about the following?

#include <curses.h>
#include <term.h>

int
ncolors(void)
{
        int ncolors = -1;

        if (setupterm(NULL, 1, NULL) == OK) {
                ncolors = tigetnum("colors");
                del_curterm(cur_term);
        }

        return ncolors;
}

This doesn't initialise the terminal so you can still do the
progressbar without clearing the screen and/or use hardcoded ansi
codes for colors if you want. It returns the number of colors for the
used terminal or -1 if color is not supported. Maybe the progressbar
should be optional in that case too. I think it would be a nice
addition and one doesn't have to use apt-get  and/or apt-cache
instead.
Also, maybe using italics, bold and reverse video instead of colors
can be considered? They usually do the right thing with either
background. Anyway, I hope you can implement the above function to
make at least monochrome and/or dumb terminals behave.

Kind regards,
Axel


Reply to: