Skip to content

Migrate away from legacy ncurses functions attrset, attron,attroff, ... #1541

Open
@C0rn3j

Description

@C0rn3j

Ran into this while trying to fix #243

Fixing these will allow htop to correctly handle the 65k available colors and the necessary version bump enables 8-bit RGB colors (24-bit).

Maybe migrate to wide chars where doable -> wattr_on/wattr_off/wattr_set?
In which case other things also have to be migrated, see the docs.

Here's picmap source from ncurses test examples - https://github.com/ThomasDickey/ncurses-snapshots/blob/master/test/picsmap.c

With the 6.1+ bump:

init_pair -> init_extended_pair

% grep -R init_pair 2>/dev/null
test_spec.lua:            curses.init_pair(pair, foreground, background)
CRT.c:            init_pair(ColorIndex(i, j), i, bg);
CRT.c:   init_pair(ColorIndexGrayBlack, grayBlackFg, grayBlackBg);
CRT.c:   init_pair(ColorIndexWhiteDefault, White, -1);

attron -> attr_on

NEW:   attr_on(resetColor, NULL);

% grep -R attron 2>/dev/null
CRT.c:   attron(resetColor);

attroff -> attr_off

NEW:   attr_off(resetColor, NULL);

% grep -R attroff 2>/dev/null
CRT.c:   attroff(resetColor);

attrset -> attr_set

% grep -R attrset 2>/dev/null
Action.c:   attrset(attr);
Action.c:   attrset(CRT_colors[HELP_BOLD]);
Action.c:   attrset(CRT_colors[DEFAULT_COLOR]);
Action.c:   attrset(CRT_colors[DEFAULT_COLOR]);
Action.c:   attrset(CRT_colors[DEFAULT_COLOR]);
Action.c:   attrset(CRT_colors[DEFAULT_COLOR]);
Action.c:   attrset(CRT_colors[DEFAULT_COLOR]);
Action.c:      attrset((helpLeft[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[DEFAULT_COLOR]);
Action.c:      attrset((helpLeft[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[HELP_BOLD]);
Action.c:         attrset((helpLeft[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[PROCESS_THREAD]);
Action.c:         attrset((helpLeft[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[PROCESS_THREAD]);
Action.c:      attrset((helpRight[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[HELP_BOLD]);
Action.c:      attrset((helpRight[item].roInactive && readonly) ? CRT_colors[HELP_SHADOW] : CRT_colors[DEFAULT_COLOR]);
Action.c:   attrset(CRT_colors[HELP_BOLD]);
Action.c:   attrset(CRT_colors[DEFAULT_COLOR]);
Meter.c:   attrset(CRT_colors[METER_TEXT]);
Meter.c:   attrset(CRT_colors[RESET_COLOR]);
Meter.c:   attrset(CRT_colors[METER_TEXT]);
Meter.c:   attrset(CRT_colors[BAR_BORDER]);
Meter.c:   attrset(CRT_colors[RESET_COLOR]);
Meter.c:   attrset(CRT_colors[RESET_COLOR]);
Meter.c:   attrset(CRT_colors[METER_TEXT]);
Meter.c:         attrset(CRT_colors[colorIdx]);
Meter.c:   attrset(CRT_colors[RESET_COLOR]);
Meter.c:   attrset(CRT_colors[LED_COLOR]);
Meter.c:         const cchar_t wc = { .chars = { c, '\0' }, .attr = 0 }; /* use LED_COLOR from attrset() */
Meter.c:   attrset(CRT_colors[RESET_COLOR]);
InfoScreen.c:   attrset(CRT_colors[METER_TEXT]);
InfoScreen.c:   attrset(CRT_colors[DEFAULT_COLOR]);
ScreenManager.c:   attrset(CRT_colors[cur ? SCREENS_CUR_BORDER : SCREENS_OTH_BORDER]);
ScreenManager.c:   attrset(CRT_colors[cur ? SCREENS_CUR_TEXT : SCREENS_OTH_TEXT]);
ScreenManager.c:   attrset(CRT_colors[cur ? SCREENS_CUR_BORDER : SCREENS_OTH_BORDER]);
ScreenManager.c:   attrset(CRT_colors[RESET_COLOR]);
FunctionBar.c:   attrset(CRT_colors[FUNCTION_BAR]);
FunctionBar.c:      attrset(CRT_colors[FUNCTION_KEY]);
FunctionBar.c:      attrset(CRT_colors[FUNCTION_BAR]);
FunctionBar.c:         attrset(CRT_colors[FUNCTION_BAR]);
FunctionBar.c:         attrset(attr);
FunctionBar.c:   attrset(CRT_colors[RESET_COLOR]);
FunctionBar.c:      attrset(CRT_colors[FUNCTION_BAR]);
FunctionBar.c:      attrset(attr);
FunctionBar.c:   attrset(CRT_colors[RESET_COLOR]);
Header.c:   attrset(CRT_colors[RESET_COLOR]);
Panel.c:      attrset(header_attr);
Panel.c:      attrset(CRT_colors[RESET_COLOR]);
Panel.c:            attrset(item.highlightAttr);
Panel.c:            attrset(CRT_colors[RESET_COLOR]);
Panel.c:      attrset(selectionColor);
Panel.c:      attrset(CRT_colors[RESET_COLOR]);

Moreover it looks like htop is written with the 16 (8+8bold) colors of the ancient past in mind, rather than the 256 color standard of yesterday, or the 8-bit RGB of today.

Any arguments about old distributions can rest, as those distributions will simply use old htop, even Ubuntu 20.04 from 2020 has ncurses 6.2... and htop 2.2.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code quality ♻️Code quality enhancementdependenciesPull requests that update a dependency fileenhancementExtension or improvement to existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions