htop-dev / htop

htop - an interactive process viewer
https://htop.dev/
GNU General Public License v2.0
6.47k stars 441 forks source link

[Feature suggestion] Modify the colours used by htop #1416

Open rubyFeedback opened 7 months ago

rubyFeedback commented 7 months ago

I am on manjaro linux right now.

On mate-terminal htop looks like this:

image (from https://i.imgur.com/cew5MLq.jpeg)

I quite like that for the most part. I assume this is derived from the default local theme.

I do not always use mate-desktop though. Often I just use icewm and KDE, so if I use, say, another linux distribution, I probably won't have that htop variant in use anymore. But I would like to re-use it.

This brings me to my question or issue request. Can we customize the colours for htop, on a per-application basis? That is to allow for overriding the deafult colours.

I don't know if htop makes use of a htoprc file or ENV variables but any change would be neat. This does not have to be super-complicated, mind you. It can be kept super-simple, say, only allow for very few values to be customized. Perhaps a simple colour-profile that is human-readable. This could be specified via a commandline flag too such as "htop --rcfile=/tmp/foobar.rc" or anything like that. Or other ways that are simple; I am not requesting a complex and complicated addition.

I read in other threads that htop uses hardcoded values right now (although, htop also seems to derive the colours from the theme itself, so it seems to be only semi hardcoded). So this feature request would also ask for a bit more flexibility - again, just to keep it simple, nothing too complicated. We don't want to inflate the code base too much, so simplest-colour support possible (custom colours though).

Htop itself could also bundle, say, six different colour profiles by default, and people could use it via the commandline too, such as via:

"htop --colour-profile1" or "htop --color-profile=1" # and you can allow colour and color, to not have to care for UK/US spelling differences too
"htop --colour-profile2" or "htop --color-profile=2"

Having default profiles gives people a bit of flexibility. And by limiting it to, say, 6, the amount of maintenance work is also kept low (you can also put it at 12 or so, or even lower, say only 3 options, aside from the current default, so the current default is always available without a need to choose anything else).

Explorer09 commented 7 months ago
  1. You might be confused between the htop color scheme and the color palette from your mate-terminal. htop has only a limited set of basic colors (about 16, IIRC) to choose for a color scheme, and the actual "terminal color" to RGB values mapping is done from your mate-terminal (not in the scope of htop).
  2. htop can load a htoprc file from a non-default location by using HTOPRC environment variable. Though there is no option for partial option override.
BenBE commented 7 months ago

There is already support for a set of pre-defined color profiles available in the setup screen. As @Explorer09 mentioned, these use just the 16 primary console colors, which then get mapped to actual RGB colors by your terminal emulator. And while there's roughly a agreed-upon mapping of these colors, there's nothing that prevents your terminal emulator to display color 1 as bright pink instead of the commonly used dark blue …

To answer the questions:

To provide a small clarification on how the color themes in htop work: There's a list of enum values that make up what kinds of items we have to color in the UI. Each color profile basically maps the (VGA/VESA) color IDs that each of those UI items should use. That mapping is fully compile-time.

P.S.: Please avoid linking images from other services, as these links may break. Instead embed the image in the post (copy the image to your clipboard and paste it into your text at the right location). This not only avoids images becoming unavailable, but avoids spraying around everyone's data across the internet unnecessarily …

AndrewKvalheim commented 2 months ago

If you’d like an example of how to customize the colors, this is how I’ve done it.

htop

I already render “magenta” as orange and “cyan” as purple, so just needed a small change to htop’s color profile to accommodate that.