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

Wrong colors using emacs-nox in WT-Ubuntu #2953

Open
angelog0 opened this issue Sep 28, 2019 · 20 comments
Open

Wrong colors using emacs-nox in WT-Ubuntu #2953

angelog0 opened this issue Sep 28, 2019 · 20 comments
Labels
Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Attention The core contributors need to come back around and look at this ASAP. Product-Terminal The new Windows Terminal.
Milestone

Comments

@angelog0
Copy link

By default I use MSYS2 MinTTY and by means of wslbridge I use also this MinTTY for WSL Ubuntu. With both these apps I use a color scheme which I added to the profile.json:

{
            "name" : "base16-default-mod-lighten",
            "foreground" : "#D0D0D0",
            "background" : "#151515",
            "black" : "#151515",
            "red" : "#AC4142",
            "green" : "#90A959",
            "yellow" : "#F4BF75",
            "blue" : "#6A9FB5",
            "purple" : "#AA759F",
            "cyan" : "#75B5AA",
            "white" : "#D0D0D0",
            "brightBlack" : "#505050",
            "brightRed" : "#C25E5E",
            "brightGreen" : "#A6BB7B",
            "brightYellow" : "#F8D5A5",
            "brightBlue" : "#8CB5C6",
            "brightPurple" : "#BE95B5",
            "brightCyan" : "#97C7BE",
            "brightWhite" : "#F5F5F5"
        }

In the same profile.json I added the profiles for MSYS2 bash. I use the same above color scheme for MSYS2 bash and Ubuntu in WT.

In this attachment
emacs-nox-sshots.tar.gz
there are a few screenshots of emacs-nox running on various systems. As you can see I have the same good result in MinTTY (emacs-nox-mintty.png), Ubuntu in MinTTY (emacs-nox-mintty-Ubuntu.png) and in MSYS2 bash in WT (emacs-nox-WT-msys2.png). Instead in WT Ubuntu I get what I call bad result (emacs-nox-WT-Ubuntu.png).

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 28, 2019
@DHowett-MSFT
Copy link
Contributor

Can you report what the TERM environment variable contains in msys2 and WSL Ubuntu? What do you get when you run WSL ubuntu outside of WT?

@DHowett-MSFT DHowett-MSFT added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Sep 30, 2019
@angelog0
Copy link
Author

angelog0 commented Oct 1, 2019

@DHowett-MSFT, in WT and outside it (from the Start Menu), Ubuntu has

$ echo $TERM
xterm-256color

while in MinTTY, Ubuntu has

$ echo $TERM
xterm

MSYS2 bash in MinTTY has

$ echo $TERM
xterm

while in WT (using "commandline": "cmd.exe /c \"set MSYSTEM=MSYS&& C:/msys64/usr/bin/bash.exe --login\"")

$ echo $TERM cygwin

(here it COPY/PATEs wrong, does not take the \n).

In any case, in 2., 3., 4. with the same theme there is the good result. In 1. it is wrong.

BTW, I tested this in WT Ubuntu:

$ export TERM=xterm

and the result is similar to 2., 3., 4. : just the comment lines differ, in RED instead of YELLOW.

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Oct 1, 2019
@DHowett-MSFT
Copy link
Contributor

I'm wondering if this is a side effect of #2661.

@DHowett-MSFT DHowett-MSFT added Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. labels Oct 29, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Oct 29, 2019
@DHowett-MSFT DHowett-MSFT added Needs-Tag-Fix Doesn't match tag requirements and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Oct 29, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Oct 29, 2019
@DHowett-MSFT DHowett-MSFT added Needs-Tag-Fix Doesn't match tag requirements and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Oct 29, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Oct 29, 2019
@DHowett-MSFT DHowett-MSFT added this to the Terminal Backlog milestone Oct 29, 2019
@angelog0

This comment has been minimized.

@HoLengZai
Copy link

Any update on that issue... I got the same issue... the colours are horrible, it is really difficult to read it:
I tried others colour schemes but it is the same result.
image

With a white background, it is a bit better but the font is horrible and painful for the eyes
image

@angelog0
Copy link
Author

@HoLengZai , have you tried the color scheme below? It seems a bit better...

{
            // From: https://windowsterminalthemes.dev
            "name": "Terminal Basic",
            "black": "#000000",
            "red": "#990000",
            "green": "#00A600",
            "yellow": "#999900",
            "blue": "#0000B2",
            "purple": "#B200B2",
            "cyan": "#00A6B2",
            "white": "#BFBFBF",
            "brightBlack": "#666666",
            "brightRed": "#E50000",
            "brightGreen": "#00D900",
            "brightYellow": "#E5E500",
            "brightBlue": "#0000FF",
            "brightPurple": "#E500E5",
            "brightCyan": "#00E5E5",
            "brightWhite": "#E5E5E5",
            "background": "#FFFFFF",
            "foreground": "#000000",
            "selectionBackground": "#A4C9FF",
            "cursorColor": "#7F7F7F"
        }

@zadjii-msft
Copy link
Member

Okay sorry this one got missed.

The xterm vs xterm-256color thing - that makes me think that emacs is using the 16 color palette in mintty, and is using 256-color palette in Windows Terminal. That might also explain why changing the color scheme seems to do nothing in the Terminal - that'd only change the 16 colors, not the rest of the 256 colors.

I'd suspect that launching emacs with TERM=xterm emacs-nox would look more like what you'd want. That's my theory at least. I'm not super familiar with how emacs sets it's own internal color palette unfortunately...

@zadjii-msft zadjii-msft added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Nov 17, 2021
@ghost ghost added the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Nov 21, 2021
@ghost
Copy link

ghost commented Nov 21, 2021

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@HoLengZai
Copy link

@HoLengZai , have you tried the color scheme below? It seems a bit better...

{
            // From: https://windowsterminalthemes.dev
            "name": "Terminal Basic",
            "black": "#000000",
            "red": "#990000",
            "green": "#00A600",
            "yellow": "#999900",
            "blue": "#0000B2",
            "purple": "#B200B2",
            "cyan": "#00A6B2",
            "white": "#BFBFBF",
            "brightBlack": "#666666",
            "brightRed": "#E50000",
            "brightGreen": "#00D900",
            "brightYellow": "#E5E500",
            "brightBlue": "#0000FF",
            "brightPurple": "#E500E5",
            "brightCyan": "#00E5E5",
            "brightWhite": "#E5E5E5",
            "background": "#FFFFFF",
            "foreground": "#000000",
            "selectionBackground": "#A4C9FF",
            "cursorColor": "#7F7F7F"
        }

@angelog0 , Not really, it looks like the same as "One Half Light" default color scheme.
I would like to keep dark/black background,

As a workaround, I change the default e-macs theme instead of changing the Windows Terminal one:
At least, it is not pain for the eyes and I can read it easily:
image

That's the fastest workaround I guess.
If you want to do the same, I use the built-in "wombat" theme:
$> emacs ~/.emacs.d/init.el
and add the following line:
(load-theme 'wombat t)

Emacs theme will override all the colours and you will get the same result as above...
If you change the Windows Terminal color scheme, it won't affect Emacs at all, you will only see the window border color changed.

@ghost ghost removed the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Nov 22, 2021
@angelog0
Copy link
Author

angelog0 commented Nov 22, 2021

@HoLengZai , thanks for suggestions. I will give it a try...

@msftbot, as you see this thread is not dead... and should be your interest to understand why on WT this occurs..

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Nov 22, 2021
@angelog0
Copy link
Author

@HoLengZai , yes with that theme things are better. I tried it with MSYS2 emacs-nox in WT and MinTTY.

In MinTTY it looks a bit different...

@zadjii-msft
Copy link
Member

zadjii-msft commented Nov 22, 2021

Like I said, this sounds like a TERM mismatch. Changing the color scheme of the Terminal isn't going to magically change the colors that emacs emits for it's own scheme, if it's using 256colors for its scheme. You had different TERM values for mintty vs Windows Terminal, which would probably explain what you're seeing. Is that still the case?

@zadjii-msft zadjii-msft added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Nov 22, 2021
@HoLengZai
Copy link

HoLengZai commented Nov 22, 2021

@zadjii-msft, @angelog0

Sorry, I didn't catch your comments @zadjii-msft. (I didn't get that I can use your example as a command on my shell :D, I was probably tired.. or your explanation was a way to advance my knowledge of terminal customization)
So I read this: #6087
Then I read this: https://stackoverflow.com/a/64585/11559874
Then I do some tests: (Alt+M then list-colors-display to see the list of colours supported on emacs)
Then I guess I got your point

(I used WT Campbell colour scheme for all my tests)

$>TERM=screen emacs script.sh

$>TERM=xterm emacs script.sh

$>TERM=xterm-256color emacs script.sh

$>TERM=screen-256color emacs script.sh

By default, when I type env, I got TERM=xterm-256color
So I guess we can add something like:
export TERM=xterm
or
export TERM=screen-256color
(which is the 2 best colours scheme, in my opinion, to be able to read properly the source code)

@angelog0 , So I removed "wombat theme" on all my examples above. I just use the default one. Hope it will help anyone like me who just want to have a simple emacs with the proper way to read it through Windows Terminal :D

@HoLengZai
Copy link

HoLengZai commented Nov 22, 2021

@zadjii-msft
However, does it mean that Emacs tries to know the term colors used but it doesn't because Windows Terminal does not provide him this info?

I just try to understand the issue with emacs only even if on environment variable we see xterm-256color....

I found this article for example for iTerm: https://iterm2.com/faq.html
Q: How do I get 256 color mode working in vim?
A: The recommended way is to set your terminal type to xterm-256color in Preferences > Profiles > Terminal > Report Terminal Type. You may also need to put set background=light or set background=dark in your .vimrc.

Hence, maybe Windows Terminal can provide this kind of option too? So Emacs will know that we are using xterm-256color or set screen-256color (don't really get the diff) but a custom value on Report Terminal Type option

@zadjii-msft
Copy link
Member

When using WSL, the Terminal (and console) both already report themselves as xterm-256color. If you're getting a TERM that's anything else, then it's probably due to running emacs outside of WSL, or something manually changing the TERM value.

I don't understand why emacs would have different color schemes for xterm-256color vs screen-256color, that doesn't make any dang sense.

@angelog0
Copy link
Author

@HoLengZai, I did the same tests. With TERM=screen-256color, the menu bar has a black background.. It almost does not looks as a menu bar... This shows up also from your images.

I still do not understand why in MinTTY (which has TERM=xterm) Emacs colors look better than in WT with the same TERM setting...

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Nov 22, 2021
@HoLengZai
Copy link

HoLengZai commented Nov 23, 2021

Well, I think the ticket can be closed as it is not specific to Windows Terminal but related to Emacs behaviour to determine the right "terminal (emulator) color"

I finally found the trick to make it work properly without playing or messing around with an environment variable or affecting emacs keyboard, etc (as some people got issues by changing/playing with $TERM)
That's the posts that help me to understand/fix the issue:

So basically if you determine your "frame-background-mode" for emacs, you will be able to fix the issue:

(Using emacs-nox)

$>emacs --eval "(setq frame-background-mode 'dark)" script.sh
$>emacs --eval "(setq frame-background-mode 'light)" script.sh

Check the one you prefer which match the "normal color"
Mine is dark mode, so I add this entry in my ~/.emacs.d/init.el

(setq frame-background-mode 'dark)
(setq frame-set-background-mode nil) ;;<= I do not find any difference with or without it but i kept it

Result: (still using Campbell color scheme)

However... Still wondering how emacs retrieve the frame-background-mode, I guess it cannot get it from the terminal so it applies the light one?
http://doc.endlessparentheses.com/Var/frame-background-mode.html

@zadjii-msft zadjii-msft modified the milestones: Terminal Backlog, Backlog Jan 4, 2022
@zadjii-msft
Copy link
Member

@angelog0 did @HoLengZai's suggestion work for you/?

@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Aug 12, 2022
@angelog0
Copy link
Author

angelog0 commented Aug 12, 2022

@zadjii-msft, I do not use dark mode so i cannot say if that works. Meanwhile I changed the WSL theme. Now I use Terminal Basic with which things with Emacs-nox work better.

Anyway, I think you should discuss these things with Emacs people, the developers...

wsl-WT-emacs-nox

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Aug 12, 2022
@angelog0
Copy link
Author

angelog0 commented Aug 12, 2022

BTW, MSYS2 has a TTY package of Emacs and to use it in WT I had to change Emacs theme:

;; See https://github.com/microsoft/terminal/issues/2953#issuecomment-975180916
(load-theme 'wombat t)

With that theme, things work better. BETTER does not mean RIGHT! For this reason, in previous post, I suggested to discuss the issue with Emacs people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Attention The core contributors need to come back around and look at this ASAP. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

4 participants