Hi Steven,
I had a look at the VIM source code and its git commit log. The code that handles this colour response is in src/term.c at around line 4955 (should anyone want to look themselves).
There was a patch applied to this section of code within vim on 05/06/2019 with the following comment:
Problem: 'background' not correctly set for 2-digit rgb termresponse.
Solution: Adjust what digit to use. (closes #4495)
Looks like this change was applied against vim version 8.1. My Ubuntu 18.04 LTS systems are all running vim 8.0.1453 and hence seeing the issue with iTerm. I downloaded and compiled the latest source which gave me version 8.2.314. When running the 8.2 version of vim the dark/light is detected correctly with iTerm – with no need for environment variables (i.e. $COLORFGBG).
So, I guess you could download and compile a new vim on your server; or persuade George to move to a 16-bit response for the terminal colours in iTerm.
The iTerm update may well consist of updating the following function in VT1000Output.m:
- (NSData *)reportColor:(NSColor *)color atIndex:(int)index prefix:(NSString *)prefix {
NSString *string = [NSString stringWithFormat:@"%c]%@%d;rgb:%02x/%02x/%02x%c",
ESC,
prefix,
index,
(int) ([color redComponent] * 255.0),
(int) ([color greenComponent] * 255.0),
(int) ([color blueComponent] * 255.0),
7];
return [string dataUsingEncoding:NSUTF8StringEncoding];
}
To something like:
- (NSData *)reportColor:(NSColor *)color atIndex:(int)index prefix:(NSString *)prefix {
NSString *string = [NSString stringWithFormat:@"%c]%@%d;rgb:%04x/%04x/%04x%c", // 16-bit response for R,G,B
ESC,
prefix,
index,
(int) ([color redComponent] * 255.0 * 255.0), // shift value two bytes left
(int) ([color greenComponent] * 255.0 * 255.0), // shift value two bytes left
(int) ([color blueComponent] * 255.0 * 255.0), // shift value two bytes left
7];
return [string dataUsingEncoding:NSUTF8StringEncoding];
}
I've checked this out; and the change seems to work OK – at least with vim. It is possible that other console applications only like 8-bit responses....
Cheers,
aid