htop-dev / htop

htop - an interactive process viewer

Home Page:https://htop.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What method htop uses to extract color theme of current terminal session?

maker-ATOM opened this issue · comments

Within htop which source file is responsible to extract the current color theme of terminal session being used?
It would be great if you could redirect me to the file.

None. The color schemes are hard-coded at https://github.com/htop-dev/htop/blob/main/CRT.c#L117 ff.

If the schemes are hard-coded how does htop is able to register color changes as depicted,

demo

Initally background color is changed from black to somewhat red and then a palette color from blue to black.

This is your terminal emulator configuration. It can substitute colors as it wishes. The apps running in it will not know. Run mc (midnight commander) and you will see the same colors "faked" to be different colors.

Okay, my ultimate goal is to draw ASCII art using ncurses with the current palette colors of the terminal emulator, so how to I tell nucrses what colors does the current terminal emulator session has?

Current I found two methods,

  1. Read the conf file which store the properties of gnome-terminal
cd ~/.config/dconf/ && dconf dump / > dconf_settings.txt && cat dconf_settings.txt
  1. Using ANSI Escape Codes
printf("\033]11;?\007");

So the question remains the same how does htop uses ncurses to set the text with same colors as the current terminal emulator session.

So the question remains the same how does htop uses ncurses to set the text with same colors as the current terminal emulator session.

Simply by printing its text using ncurses to use the appropriate palette colors. What the terminal emulator makes of this is none of our business and htop does not care about the final rendering …

What the terminal emulator makes of this is none of our business and htop does not care about the final rendering …

What if the user wishes to modify that colour scheme, through htop? I am not disputing the "htop adheres to the current theme" in use, more the what if a user wishes to customize it on a per-application basis. I'll file a separate issue for this, though, as it does not really pertain to the issue here.

If a user wished to modify a theme, they can do so in

htop/CRT.c

Line 117 in ad3b90e

static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
and recompile htop.