altercation / vim-colors-solarized

precision colorscheme for the vim text editor
http://ethanschoonover.com/solarized
6.58k stars 1.75k forks source link

Windows console cterm values do not function correctly #141

Open kashperanto opened 8 years ago

kashperanto commented 8 years ago

Hey, I've been attempting to get solarized up and running on my cmd.exe console as a convenience when using Powershell on my work machine. Aside from a minor hickup when I had colors 0 and 8 swapped, almost everything seems to be working as expected. The only problem I have now is that most groups highlighted with "cterm=..." are nearly (or totally) unreadable.

I did a little messing around, and it seems like "cterm=reverse" is not behaving as intended. It sets the background to the standard text foreground color, and then the ctermfg color is applied to the actual text as usual. It is my understanding that 'reverse' should swap bg and fg colors. For example, instead of ErrorMsg showing up as red background and black (former background) text, the background is light grey and the text is red. My IncSearch group is a lovely red background with orange text.

Also, "cterm=underline" appears to change the bg color to 4 (blue), so groups like helpHyperTextJump and vimGroup are just solid blue blocks (ctermfg=4). It appears that having 'underline' and 'reverse' gives a white background, but I haven't the faintest clue why.

Another thing I noticed is that having settings for both fg and bg colors will override the negative effects of the cterm settings, so my WildMenu ends up dark with white text, which is the reverse of what it should be (reverse still doesn't work, but we have the correct colors for bg and fg). My Visual just changes text to be grey with the dark background (instead of gray background and dark text). TabLine ends up with the correct colors and no underline. I also figured that bold doesn't seem to do anything, and undercurl has a similar effect to underline.

I have been having a hard time figuring out exactly how vim or any other program outputs color to the windows console, but I do know it has no support for ASCII terminal escapes natively. I'm not sure if this is something that is an issue with vim's color display for the Windows console, but I do think it would be something we could fix in the colorscheme in solarized.vim by detecting the Windows console and removing all of the offending options. We would also have to add another case in defining the highlighting options since some of these rely on the reverse properties (this is the part I question the feasibility of).

As far as I can tell there should be no reason we couldn't just specify bg and fg colors correctly instead of relying on reverse to swap them. Experimenting with Visual and Search I can see no difference in results from the existing method and me just setting the fg and bg colors specifically. The only time I can see this mattering is if the bg color is different from the standard bg color for the selected text, which should hardly ever be the case in my experience. It makes me wonder why we even rely on reverse at all, since keeping the original bg color as the new text color can result in unreadable text.

I am using the 16-color mode with exact colors in the cmd.exe color pallete, so I'm not sure if the other modes are affected by this. I am presently planning on just incorporating these into my own vimrc file, as I am an uber-noob when it comes to this git stuff. If I get a green light from anyone more knowledgeable I might commit the changes, though. I also have a Powershell script to set the default colorscheme to match the expected values for solarized vim that might be useful.

ianchanning commented 7 years ago

@kashperanto I've been having a serious go at trying to get these colours working. I suspect there's a very select and tiny group that will ever consider trying to get Vim + Solarized + Cmd/Powershell working. So I expect there won't be much help coming for this :)

I've combined them with https://github.com/neilpa/cmd-colors-solarized.

Short version

Only 8 colours works and I modified the colour names to match the Powershell colours specified by cmd-colors-solarized.

My hope is that with 256 colours in the Windows 10 Console this issue will go away (I haven't installed Windows build #14931 yet)

Long version

I've found that there's frustrating differences between running with :set t_Co=8 and :set t_Co=16

Neither have worked perfectly for me.

With 8 colours

I got a result I was happy with because the code is correct which is the most important - but:

  1. The statusline is incorrect - coloured blue and orange
  2. The TabLine is incorrect - coloured yellow
  3. The LineNr should have a base02 background rather than base03

Initially, I modified the colour names e.g. the 'LightGray' colour doesn't apply to cmd/powershell - you have to use 'Gray'. I also discovered that the old cmd colours which had e.g. 'Green' instead of 'DarkGreen' (but does have 'LightGray') aren't used by Vim, I don't know why.

Cterm colours handle a few differences of the same colours e.g. Grey and Gray. However for them to work properly they have to match the Powershell colours (even for cmd). You can find these at :help cterm-colors, there's also quite a good tutorial on configuring vim colours:

NR-16   NR-8    COLOR NAME
0       0       Black
1       4       DarkBlue
2       2       DarkGreen
3       6       DarkCyan
4       1       DarkRed
5       5       DarkMagenta
6       3       Brown, DarkYellow
7       7       LightGray, LightGrey, Gray, Grey
8       0*      DarkGray, DarkGrey
9       4*      Blue, LightBlue
10      2*      Green, LightGreen
11      6*      Cyan, LightCyan
12      1*      Red, LightRed
13      5*      Magenta, LightMagenta
14      3*      Yellow, LightYellow
15      7*      White

The cmd-colors-solarized colours differ from these:

 PowerShell  | ColorTable | DWORD
-------------|------------|----------
 Black       | 00         | 00362b00
 DarkGray    | 08         | 00423607
 DarkGreen   | 02         | 00756e58
 DarkYellow  | 06         | 00837b65
 DarkBlue    | 01         | 00969483
 DarkCyan    | 03         | 00a1a193
 Gray        | 07         | 00d5e8ee
 White       | 15         | 00e3f6fd
 Yellow      | 14         | 000089b5
 DarkRed     | 04         | 00164bcb
 Red         | 12         | 002f32dc
 Magenta     | 13         | 008236d3
 DarkMagenta | 05         | 00c4716c
 Blue        | 09         | 00d28b26
 Cyan        | 11         | 0098a12a
 Green       | 10         | 00009985

So I replaced vim colours to match the solarized-cmd colours:

 let s:base03      = "Black"
 let s:base02      = "DarkGray"
 let s:base01      = "DarkGreen"
 let s:base00      = "DarkYellow"
 let s:base0       = "DarkBlue"
 let s:base1       = "DarkCyan"
 let s:base2       = "Gray"
 let s:base3       = "White"
 let s:yellow      = "Yellow"
 let s:orange      = "DarkRed"
 let s:red         = "Red"
 let s:magenta     = "Magenta"
 let s:violet      = "DarkMagenta"
 let s:blue        = "Blue"
 let s:cyan        = "Cyan"
 let s:green       = "Green"

By replacing all the colours to use just the Powershell ones, I got the code colours correct. I think this was in the end, just pure luck. There's numerous issues with handling 8 colours. The main issue is that you have to use 'bold' to switch to colours above 7, e.g. 0, but if you apply bold to a highlight then you apply it to the foreground and background, so 0,4 becomes 0,4*. So ideally you only want to use foreground and background colours that are in the same range.

With 16 colours

Eventually after messing around I came to the conclusion that although there are 16 possible colours - they're referred to using an 8 colour range in Vim. So you can't properly use 16 colours and you hit the same trade offs, using 'bold'. So using '10', just returns a random colour, you have to specify '2*'. But this then means that vim has to apply 'bold' to the background and foreground colours.

Here's what mine looks like now:

2017-05-17 11_48_36-command prompt - vim

Plus the light theme works too:

2017-05-17 12_01_10-command prompt - vim

kashperanto commented 7 years ago

Cool, I'll have to take a look at your work. I have also been experimenting since my original post, and I currently have a good setup based on the cmd solarize project that works for vim in bash on the WSL, although it may work for windows vim in the prompt.

I noticed that the "bright/bold" and normal colors are swapped in the existing theme (probably to match the powershell/cmd "dark" terminology). I swapped those in the .reg file so that the ansi codes to get the colors are correct from vim's perspective. I also had to export the term as xterm-16color, and outside of tmux I have the correct solarized colors for light and dark (in tmux the bg color only changes for text-containing cells, so I suspect a terminfo problem causing vim to take shortcuts that don't work in cmd).

I imagine that the same results could be had by modifying the colorscheme itself to work with the cmd/powershell layout, but changing the colors is easier ;)

ianchanning commented 7 years ago

Yes - I think they're swapped because of the issues around bold.

From the changelog it looks like they were designed to get things working with Terminal.app (I assume is a Mac terminal app). However they clearly don't seem to match up to the Windows console.

From the time I've wasted so far it seems an exercise in complete futility to try and get things properly working in 8 colours - I think kind of like trying to get your website looking nice in IE 5.

So I think the best step is just to get the Creators Update installed and then switch to the > 256 colours.

kashperanto commented 7 years ago

Hah, I definitely would feel bad to tell anyone how much time I've spent on colorschemes and other customization. It sounds so simple, lol.

I don't really use powershell or cmd proper now that they have given us the WSL, so I will probably stick to swapping the bold colors to match the ANSI definitions. Unfortunately I am on an enterprise license at work, so no Creator's update for me until IT rolls it out :'(

I've had plenty of other things to waste time on with vim, though, so it is kind of a good thing that I don't have the newer features yet. I recently took the plunge into YouCompleteMe and UltiSnips.

ianchanning commented 7 years ago

Actually I've given up on the console for Vim now - I've switched to GVim on Windows. It gives proper 256 colour support plus bold and italic fonts.

It was a separate issue that made me switch in the end though. I started hitting issues with indenting when opening files from a vim session. There's so few people trying to use it that it was just a waste of time trying to debug stuff.

ianchanning commented 5 years ago

@kashperanto If you fancy giving the console another shot, with the fixes to Windows 10 Console and then some further fixes to Vim, with Vim 8.1.428 (64-bit direct from vim.org downloads rather than chocolatey) and Windows 10 build 1803 I have lovely 24-bit colours in my Vim terminal.

I've used the new ColorTool from the Windows console team which allows you to switch between the solarized light/dark themes and the new default 'campbell' colours that comes with the new Windows 10 console.

Rather sadly the solarized colorscheme looks very bad, but the :AirlineTheme colours are perfectly correct and I imagine that it should be possible to get the correct colours working. Instead of solarized, I've done an initial test with tender which is a 24-bit theme.

I've put some screenshots in an answer on Vi StackExchange, but it is glorious to have proper colours:

2018-10-07 23_20_50-chk es6 js c__inetpub_wwwroot_chk - vim

ianchanning commented 5 years ago

@kashperanto further to this, using the vim-solarized8 colorscheme I now have glorious 24-bit solarized colours too:

2018-10-08 00_20_47- vimrc - vim