Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maker-ATOM opened this issue Feb 25, 2024 · 7 comments
Open
Labels
support request This is not a code issue but merely a support request. Please use the mailing list or IRC instead.

Comments

@maker-ATOM
Copy link

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.

@fasterit
Copy link
Member

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

@fasterit fasterit added the support request This is not a code issue but merely a support request. Please use the mailing list or IRC instead. label Feb 25, 2024
@maker-ATOM
Copy link
Author

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.

@fasterit
Copy link
Member

fasterit commented Mar 2, 2024

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.

@maker-ATOM
Copy link
Author

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.

@BenBE
Copy link
Member

BenBE commented Mar 3, 2024

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 …

@rubyFeedback
Copy link

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.

@fasterit
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support request This is not a code issue but merely a support request. Please use the mailing list or IRC instead.
Projects
None yet
Development

No branches or pull requests

4 participants