Is there an existing issue for this?
Midnight Commander version and build configuration
Operating system
Is this issue reproducible using the latest version of Midnight Commander?
How to reproduce
Forking from #5018, in particular #5018 (comment):
This is relevant for terminals that only support 8 colors, and their terminfo describes 64 or so color pairs (tput pairs), e.g TERM=linux or TERM=xterm.
Probably only relevant for ncurses.
We allocate a new ncurses color pair whenever we encounter a (fg, bg, attrs) combo that we haven't seen before. This is wasteful, and with only 64 colors pairs available we should be more frugal.
We should only allocate a new color pair whenever the (fg, bg) combo is a new one, and move the attributes out of this game. ncurses only insists on the palette-based approach for the (fg, bg) color pair, and allows to set the attributes independently in attr_set() and friends.
So there should be a two-step lookup. Internals of mc identify each different (fg, bg, attrs) combo with an index, I wouldn't change this at this point. This would point to a potentially different ncurses color pair id, as well as the attributes.
In 8-color mode, where we map bright colors to the bold attribute, this mapping should be performed first, and then check if we need a new ncurses color pair. Currently these two steps are performed in the opposite order: first color.c tty_try_alloc_color_pair()) checks if we've seen the combo, then color-ncurses.c tty_color_try_alloc_lib_pair() does the bright->bold mapping.
For example, seeing a red;black would allocate a color pair. Then seeing a brightred;black would reuse the same ncurses color pair (since it's mapped to the same red;black), and apply the bold attribute.
I think we should see an improvement in the rendering of the test case of #5018 in 8-color terminals, more text should be displayed in its desired colors.
We'd still run out of the available color pairs eventually and start to use wrong ones, since as explained in #5018 (comment) the number of color pairs supported by ncurses should really be 81 instead of 64, but we'd start to err later, meaning that real life syntax highlighting scenarios will more likely work correctly.
Expected behavior
.
Actual behavior
.
Additional context
No response
Is there an existing issue for this?
Midnight Commander version and build configuration
Operating system
.Is this issue reproducible using the latest version of Midnight Commander?
How to reproduce
Forking from #5018, in particular #5018 (comment):
This is relevant for terminals that only support 8 colors, and their terminfo describes 64 or so color pairs (
tput pairs), e.gTERM=linuxorTERM=xterm.Probably only relevant for ncurses.
We allocate a new ncurses color pair whenever we encounter a (fg, bg, attrs) combo that we haven't seen before. This is wasteful, and with only 64 colors pairs available we should be more frugal.
We should only allocate a new color pair whenever the (fg, bg) combo is a new one, and move the attributes out of this game. ncurses only insists on the palette-based approach for the (fg, bg) color pair, and allows to set the attributes independently in
attr_set()and friends.So there should be a two-step lookup. Internals of mc identify each different (fg, bg, attrs) combo with an index, I wouldn't change this at this point. This would point to a potentially different ncurses color pair id, as well as the attributes.
In 8-color mode, where we map bright colors to the bold attribute, this mapping should be performed first, and then check if we need a new ncurses color pair. Currently these two steps are performed in the opposite order: first
color.ctty_try_alloc_color_pair()) checks if we've seen the combo, thencolor-ncurses.ctty_color_try_alloc_lib_pair()does the bright->bold mapping.For example, seeing a
red;blackwould allocate a color pair. Then seeing abrightred;blackwould reuse the same ncurses color pair (since it's mapped to the samered;black), and apply theboldattribute.I think we should see an improvement in the rendering of the test case of #5018 in 8-color terminals, more text should be displayed in its desired colors.
We'd still run out of the available color pairs eventually and start to use wrong ones, since as explained in #5018 (comment) the number of color pairs supported by ncurses should really be 81 instead of 64, but we'd start to err later, meaning that real life syntax highlighting scenarios will more likely work correctly.
Expected behavior
.
Actual behavior
.
Additional context
No response