Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.bugs.dist > #1102725

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

From Julian Andres Klode <jak@debian.org>
Newsgroups linux.debian.bugs.dist
Subject Bug#1010806: apt: Avoid color output on monochrome terminals
Date 2022-05-10 18:10 +0200
Message-ID <ElAAV-ezOV-1@gated-at.bofh.it> (permalink)
References <ElxWq-eycc-5@gated-at.bofh.it> <ElxWq-eycc-5@gated-at.bofh.it> <Elzvb-eyYm-3@gated-at.bofh.it> <ElxWq-eycc-5@gated-at.bofh.it> <Elzvb-eyYm-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, May 10, 2022 at 04:54:21PM +0200, Adam Borowski wrote:
> On Tue, May 10, 2022 at 02:38:40PM +0200, Axel wrote:
> > The apt command shows colors on monochrome terminals (even on a dumb terminal),
> > please avoid this. Included is a patch which i believe will solve the problem
> > and only allows output on terminals which actually have 'color' in them; the
> > same logic as to when to color the default bash prompt.
> > I have not tested this patch.
> 
> > --- private-output.cc.orig	2022-05-10 14:18:27.611767218 +0200
> > +++ private-output.cc	2022-05-10 14:20:17.511703336 +0200
> > @@ -86,7 +86,8 @@
> >        SigWinch(0);
> >     }
> >  
> > -   if(!isatty(1))
> > +   char *term = getenv("TERM");
> > +   if(!isatty(1) || strstr(term, "color") == NULL)
> >     {
> >        _config->Set("APT::Color", "false");
> >        _config->Set("APT::Color::Highlight", "");
> 
> You mean monochrome terminals such as "xterm", "rxvt", "linux", ...?
> 
> I haven't seen an actual monochrome terminal since the first half of the
> 90's.  But even those accepted color codes and gracefully ignored them.
> To find a terminal that speaks a different language you'd need to go
> another decade into the past.
> 
> Thus, I guess that what you want is some global switch to disable color
> in programs.  But there's no common characteristic of a terminal that'd
> allow autodetecting your wishes.

apt respects https://no-color.org/ NO_COLOR environment variable,
and I believe this is the way to go for this.

For completeness, my bashrc does the following, so it looks at
tput setaf 1 (change color to red to see if there's color available).

case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi

-- 
debian developer - deb.li/jak | jak-linux.org - free software dev
ubuntu core developer                              i speak de, en

Back to linux.debian.bugs.dist | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Bug#1010806: apt: Avoid color output on monochrome terminals Axel <axel.scheepers76+debian@gmail.com> - 2022-05-10 15:20 +0200
  Bug#1010806: apt: Avoid color output on monochrome terminals Daniel Abrecht <debian-apt@danielabrecht.ch> - 2022-05-10 16:50 +0200
  Bug#1010806: apt: Avoid color output on monochrome terminals Adam Borowski <kilobyte@angband.pl> - 2022-05-10 17:00 +0200
    Bug#1010806: apt: Avoid color output on monochrome terminals Julian Andres Klode <jak@debian.org> - 2022-05-10 18:10 +0200
      Bug#1010806: apt: Avoid color output on monochrome terminals Axel Scheepers <axel.scheepers76@gmail.com> - 2022-05-10 21:00 +0200
        Bug#1010806: apt: Avoid color output on monochrome terminals Adam Borowski <kilobyte@angband.pl> - 2022-05-16 18:40 +0200
          Bug#1010806: apt: Avoid color output on monochrome terminals Axel Scheepers <axel.scheepers76@gmail.com> - 2022-05-16 20:20 +0200
            Bug#1010806: apt: Avoid color output on monochrome terminals Adam Borowski <kilobyte@angband.pl> - 2022-05-25 21:40 +0200
              Bug#1010806: apt: Avoid color output on monochrome terminals Axel Scheepers <axel.scheepers76@gmail.com> - 2022-05-26 11:10 +0200
          Bug#1010806: apt: Avoid color output on monochrome terminals Daniel Abrecht <debian-apt@danielabrecht.ch> - 2022-05-16 23:10 +0200
      Bug#1010806: apt: Avoid color output on monochrome terminals Axel Scheepers <axel.scheepers76@gmail.com> - 2022-05-10 21:50 +0200

csiph-web