htop icon indicating copy to clipboard operation
htop copied to clipboard

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

Open maker-ATOM opened this issue 1 year ago • 7 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.

maker-ATOM avatar Feb 25 '24 12:02 maker-ATOM

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

fasterit avatar Feb 25 '24 18:02 fasterit

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.

maker-ATOM avatar Mar 02 '24 04:03 maker-ATOM

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.

fasterit avatar Mar 02 '24 10:03 fasterit

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.

maker-ATOM avatar Mar 03 '24 13:03 maker-ATOM

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 …

BenBE avatar Mar 03 '24 17:03 BenBE

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.

rubyFeedback avatar Mar 17 '24 22:03 rubyFeedback

If a user wished to modify a theme, they can do so in https://github.com/htop-dev/htop/blob/ad3b90e59db8ab6b18898d7d31665a654866c26d/CRT.c#L117 and recompile htop.

fasterit avatar Mar 18 '24 06:03 fasterit