Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect colors in :terminal #5346

Open
Melandel opened this issue Dec 11, 2019 · 22 comments
Open

Incorrect colors in :terminal #5346

Melandel opened this issue Dec 11, 2019 · 22 comments

Comments

@Melandel
Copy link

Melandel commented Dec 11, 2019

Describe the bug
The colors used inside :terminal do not seem to match the colors used from a normal shell.

To Reproduce
Detailed steps to reproduce the behavior:

  1. Install bat (github)
  2. Run bat path/to/some/code/file inside your shell
  3. Open a new shell, run vim inside, then run :terminal
  4. Run bat path/to/some/code/file inside your :terminal window
  5. The colors are not the same in the window from the shell, and in the terminal window inside vim

Expected behavior
The two file previews should look identical

Screenshots
On the right, this is what bat shows when run from a shell and from a :! command:
image

On the right, that is what bat shows when run from a vim :terminal:
image

Environment (please complete the following information):

  • Vim version: 8.1 including patch 1-2197
  • OS: Windows 10 19033.1
  • Terminal: cmd and pwsh.exe

Additional context
I use bat with the default theme, which from their source code, should be Monokai Extended.

@brammool
Copy link
Contributor

I use a test file to check that the colors are exactly the same. Most likely there is something in your setup that isn't quite right.

@Melandel
Copy link
Author

Melandel commented Dec 11, 2019

Here's the output with vim -u NONE in %windir%\system32\cmd.exe:
image

What could be other elements of my setup that impact this issue?

Edit: the weird characters we see when I am in Terminal Mode in vim seem to point towards an encoding issue, but I checked: both terminals indicate that they use the Code Page 850 (Multilingual (Latin I)), and changing to 65001 (UTF-8) didn't solve the issue.
image

@chrisbra
Copy link
Member

Hm, perhaps the windows default terminal is buggy? There is a known problem #5092, perhaps its the same?

@ghost
Copy link

ghost commented Dec 11, 2019

Color problems have been recognized for some time and patches have been written.
I was checking the operation in my real environment.
A similar problem has now been noticed as it has moved away from PC life.

@brammool
Copy link
Contributor

Oh, you are using an MS-Windows console to run a terminal in? Obviously this has restrictions, since a terminal window is made to run in a terminal (such as xterm), a console in MS-Windows doesn't have nearly the kind of support needed for that. The ConPTY stuff is supposed to make it work, but there are bugs...

@ghost
Copy link

ghost commented Dec 12, 2019

I was able to reproduce it. The display will be crushed. It wasn't just the color difference.
I will do my best to resolve it.

@ghost
Copy link

ghost commented Dec 12, 2019

Maybe ConPTY's device detection '^[[0c' and winpty features are mixed.
'vim -u NONE' starts winpty, ConPTY reports as VT101, bat seems it and outputs in ANSI color.

"vim -u NONE -c 'set termwintype=conpty'" 's :terminal is no color, right.
notermguicolors, t_Co=16 is originally a 16-color palette, and colors are output using the API.

For now, use ConPTY's :terminal. However, not all will be solved.

The line next to the ruled lines becomes trashy, which requires a retest.
Line breaks don't work, this requires additional testing.

@Melandel
Copy link
Author

Thank you so much!

I didn't know about termwintype.

Thanks again!

@ghost
Copy link

ghost commented Dec 13, 2019

Thank you for your report!
I am very encouraged.

Now, ruled lines, the so-called ambiwidth problem. A destructive display in my environment. This does not solve cleanly.

@Shane-XB-Qian
Copy link
Contributor

probably it do had a issue, i was thinking if that's a bug also, though maybe not same issue like here.
for example: yellow '^[[1;33mtest' that's a different color in my xfce-term and :term in vim.
but problem maybe just about highlight or bold of one color.

@ghost
Copy link

ghost commented Dec 13, 2019

The color is different between the newly installed Windows 10 terminal and the Windows 10 terminal updated from the previous Windows. Incredible.
Color development is a heavy issue. I care and do my best.

@Shane-XB-Qian
Copy link
Contributor

um, that issue said actually not specific to windows, but linux also, probably mac same.
just a fyi to @brammool , it did not impact sth, but just the color looks different between :term of vim and outside.
as for issue this ticket saying, pls keep going, sorry jump in.. :)

@ghost
Copy link

ghost commented Dec 14, 2019

There is also such a thing.
#5359

@ghost
Copy link

ghost commented Dec 14, 2019

I read the source code. Vim script is easier to implement. Well...

@Shane-XB-Qian
Copy link
Contributor

Shane-XB-Qian commented Dec 15, 2019

@ntak vim script sometime was not the best option either :)
compiled within vim itself sometime can avoid sth .. just jumped out such of my mind.
you are doing great.

@brammool
Copy link
Contributor

I have tuned the behavoir of the terminal window using src/testdir/color_ramp.vim. That works perfectly in an xterm now: "cat testdir/color_ramp.txt" shows the same colors at the shell prompt as inside a terminal window. Since the terminal window uses an xterm-like terminal this is possible, for Windows it will be more tricky. But we can try.

@Shane-XB-Qian
Copy link
Contributor

Shane-XB-Qian commented Dec 16, 2019

those looks for 256 colors, but for palette - looks some term has its own setting.
anyway, to my issue i bring up here, i found it caused by my term has a option to switch bold from bright.
that's why color looks was not its intact one. thx @brammool gave me some tips.

@Melandel
Copy link
Author

Melandel commented Jul 5, 2020

I am using @ntak's fix for now (set termwintype=conpty from this comment) and though the colors are fixed, I find myself unable to use arrows, home and end keys.

I can confirm that removing set termwintype=conpty gives me back support of arrows, and keys.

I'm using gvim v8.2.1127 on Windows10, with the vifm.vim plugin:

  • on the left, set termwintype= with ability to use <up>, <down>, <left>, <right>, <home> and <end> but incorrect colors
  • on the right, set termwintype=conpty with correct colors but <up>, <down>, <left>, <right>, <home> and <end> don't seem to respond
    image

Is there a way where I can have both the colors I configured, and support for the <up>, <down>, <left>, <right>, <home> and <end> keys?

@Melandel
Copy link
Author

Any news on this issue?

@jessebot
Copy link

jessebot commented Nov 2, 2022

My issue may be unrelated as windows is being discussed here and I'm on macOS, but my colors are also not as would seem correct.

I have set termguicolors in my .vimrc and I am also seeing issue with the way colors are working for :terminal right now. I am using iterm2 and this version of vim:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Oct 19 2022 18:24:48)
macOS version - x86_64

I also have export TERM=xterm-256color in my .bashrc.

I'll use neofetch to show color examples, since it outputs the main terminal colors.

This is just my normal BASH config in iterm2:
Schermafbeelding 2022-11-02 om 15 52 56

I moved my actual .vimrc out of the way so I could test with the minimal settings you see on the right side of each image below.

This is without set termguicolors, which fixes the shell, but breaks my vim colorscheme:
Schermafbeelding 2022-11-02 om 16 10 52

This is with set termguicolors, which fixes my vim colorscheme, but breaks the :terminal colors:
Schermafbeelding 2022-11-02 om 16 10 20

Perhaps I am just doing something wrong, or there is an additional setting I should be aware of?

@zewpo
Copy link
Contributor

zewpo commented Nov 2, 2022

Can I ask what happens after you exit vim, but stay in the same terminal session? Does vim then correctly restore the terminals colors to what they were previously, or do they stay different until you restart the terminal?

I'm thinking it maybe similar to what i'm fixing for windows. In windows, Vim tries to get the terminals default color table (the colors mapped to the standard 16 ansi color names), and then change that table while vim is running, and then tries to restore it on exit. This fails on the new windows terminal, because windows has changed how they reports the colortable - it doesnt mean the same thing anymore as it used to in the old command prompt console.

@habamax
Copy link
Contributor

habamax commented Nov 3, 2022

Perhaps I am just doing something wrong, or there is an additional setting I should be aware of?

With termguicolors, vim uses g:terminal_ansi_colors variable to set up 16 colors of built-in terminal. If you (or your colorscheme) didn't set it up, then I guess some default hardcoded values are used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants