netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Phil Sutter <phil@nwl.cc>
Cc: Matteo Croce <technoboy85@gmail.com>,
	netdev@vger.kernel.org, Matteo Croce <teknoraver@meta.com>
Subject: Re: [PATCH iproute2-next v2] color: default to dark color theme
Date: Thu, 13 Mar 2025 09:30:35 -0700	[thread overview]
Message-ID: <20250313093035.18848cf0@hermes.local> (raw)
In-Reply-To: <Z9LJ_zDqy8iKpX7y@orbyte.nwl.cc>

On Thu, 13 Mar 2025 13:05:19 +0100
Phil Sutter <phil@nwl.cc> wrote:

> On Thu, Mar 13, 2025 at 12:41:54PM +0100, Matteo Croce wrote:
> > Il giorno gio 13 mar 2025 alle ore 12:28 Phil Sutter <phil@nwl.cc> ha scritto:  
> > >
> > > On Mon, Mar 10, 2025 at 02:12:16PM -0700, Stephen Hemminger wrote:  
> > > > On Mon, 10 Mar 2025 21:36:09 +0100
> > > > Matteo Croce <technoboy85@gmail.com> wrote:
> > > >  
> > > > > From: Matteo Croce <teknoraver@meta.com>
> > > > >
> > > > > The majority of Linux terminals are using a dark background.
> > > > > iproute2 tries to detect the color theme via the `COLORFGBG` environment
> > > > > variable, and defaults to light background if not set.
> > > > >  
> > > >
> > > > This is not true. The default gnome terminal color palette is not dark.  
> > >
> > > ACK. Ever since that famous movie I stick to the real(TM) programmer
> > > colors of green on black[1], but about half of all the blue pill takers
> > > probably don't.
> > >  
> > > > > Change the default behaviour to dark background, and while at it change
> > > > > the current logic which assumes that the color code is a single digit.
> > > > >
> > > > > Signed-off-by: Matteo Croce <teknoraver@meta.com>  
> > > >
> > > > The code was added to follow the conventions of other Linux packages.
> > > > Probably best to do something smarter (like util-linux) or more exactly
> > > > follow what systemd or vim are doing.  
> > >
> > > I can't recall a single system on which I didn't have to 'set bg=dark'
> > > in .vimrc explicitly, so this makes me curious: Could you name a
> > > concrete example of working auto color adjustment to given terminal
> > > background?
> > >
> > > Looking at vim-9.1.0794 source code, I see:
> > >
> > > |     char_u *
> > > | term_bg_default(void)
> > > | {
> > > | #if defined(MSWIN)
> > > |     // DOS console is nearly always black
> > > |     return (char_u *)"dark";
> > > | #else
> > > |     char_u      *p;
> > > |
> > > |     if (STRCMP(T_NAME, "linux") == 0
> > > |             || STRCMP(T_NAME, "screen.linux") == 0
> > > |             || STRNCMP(T_NAME, "cygwin", 6) == 0
> > > |             || STRNCMP(T_NAME, "putty", 5) == 0
> > > |             || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
> > > |                 && (p = vim_strrchr(p, ';')) != NULL
> > > |                 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
> > > |                 && p[2] == NUL))
> > > |         return (char_u *)"dark";
> > > |     return (char_u *)"light";
> > > | #endif
> > > | }
> > >
> > > So apart from a little guesswork based on terminal names, this does the
> > > same as iproute currently (in his commit 54eab4c79a608 implementing
> > > set_color_palette(), Petr Vorel even admitted where he had copied the
> > > code from). No hidden gems to be found in vim sources, at least!
> > >
> > > Cheers, Phil
> > >
> > > [1] And have the screen rotated 90 degrees to make it more realistic,
> > >     but that's off topic.  
> > 
> > I think that we could use the OSC command 11 to query the color:
> > 
> > # black background
> > $ echo -ne '\e]11;?\a'
> > 11;rgb:0000/0000/0000
> > 
> > # white background
> > $ echo -ne '\e]11;?\a'
> > 11;rgb:ffff/ffff/ffff  
> 
> Maybe a better technique than checking $COLORFGBG. Note that:
> 
> - This may return rgba and a transparency value
> - In 'xterm -bg green', it returns '11;rgb:0000/ffff/0000'
> 
> So the value may not be as clear as in the above cases.
> 
> Cheers, Phil

Rather than hard coding color palettes it would be better to use some
form of environment or config file to allow user to choose.




  reply	other threads:[~2025-03-13 16:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-10 20:36 [PATCH iproute2-next v2] color: default to dark color theme Matteo Croce
2025-03-10 21:12 ` Stephen Hemminger
2025-03-13 11:28   ` Phil Sutter
2025-03-13 11:41     ` Matteo Croce
2025-03-13 12:05       ` Phil Sutter
2025-03-13 16:30         ` Stephen Hemminger [this message]
2025-03-14 17:12           ` Phil Sutter
2025-03-14 17:37             ` Phil Sutter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250313093035.18848cf0@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=netdev@vger.kernel.org \
    --cc=phil@nwl.cc \
    --cc=technoboy85@gmail.com \
    --cc=teknoraver@meta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).