Would someone mind giving me a brief explanation of how this function works?
nc_color hilite( nc_color c ) returns the highlighted (blue background) color by finding it in color_array (get_highlight). The thing is that the color and the highlighted color - are two different colors.
Here is a search in the color_array:
const color_id id = color_to_id( color );
const color_struct &st = color_array[id];
And here is a search for requested highlighted color:
const auto &hl = st.highlight;
return hl[bg];
highlight is an array of all highlighted colors values for current color (like blue highlighted in red, blue highlighted in white, etc.). These array build in corresponse with an hl_enum.
The only reason ( int )color > 0 evaluates false (as far as i can tell) is here:
const auto &hl = st.highlight;
return hl[bg];
Requested color doesn’t have initialized elements in highlight array.
If you’ll look into void color_manager::finalize() you’ll see, that there ARE colors with no highlight array initialization:
const size_t underscore_num = std::count( root.begin(), root.end(), '_' ) -
( root.find( "light_" ) != std::string::npos ) -
( root.find( "dark_" ) != std::string::npos );
// do not try to highlight color pairs, highlighted, background, and invalid colors
if( my_name.substr( 0, 2 ) == "c_" && root != "unset" && underscore_num < 1 ) {
for( size_t j = 0; j < NUM_HL; j++ ) {
entry.highlight[j] = highlight_from_names( my_name, hilights[j] );
}
}
}
These colors are basically already backgrounded colors.
That means that when the last line in hilite evaluates false argument nc_color c is already highlighted (or has a background).