'Cmder wrong colors using Windows Terminal

I am trying to use Cmder in Windows Terminal. I tried following this guide, and I did everything as it says.

However, there is a small issue. No matter what I do, the prompt background colour does not change, it stays black.

enter image description here

I couldn't figure out the issue. Any suggestions?



Solution 1:[1]

In the comments section of the same article

I ran into this issue as well and was able to get it working. In your "%cmder_root%\config" directory, create a file called "my_prompt.lua" and add the following to it:

function my_prompt_filter()
  cwd = clink.get_cwd()
  prompt = "\x1b[1;32;49m{cwd} {git}{hg}{svn} \n\x1b[1;39;49m{lamb} \x1b[0m"
  new_value = string.gsub(prompt, "{cwd}", cwd)
  clink.prompt.value = string.gsub(new_value, "{lamb}", "?")
  end
  clink.prompt.register_filter(my_prompt_filter, 1)

Kudos to Eric Grandt

Solution 2:[2]

@AMagyar 's answer is great, except that if you use conda, pyenv or other virtual environments, that information would be omitted (when it should be (base) ?, you will get ?). Instead, you can create my_prompt.lua as something like:

function my_prompt_filter()
    local prompt = clink.prompt.value
    prompt = string.gsub(prompt, '^\x1b%[1;32;40m', '\x1b[1;32;49m')
    prompt = string.gsub(prompt, '\n\x1b%[1;39;40m', '\n\x1b[1;39;49m')
    clink.prompt.value = prompt
end
clink.prompt.register_filter(my_prompt_filter, 1)

Everything is settled.

What controls the terminal text & background color?

In function set_prompt_filter in %cmder_root%\vender\clink.lua, you may read lines like:

local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg}{svn} \n\x1b[1;39;40m{lamb} \x1b[0m"

This is the prototype of cmder prompts. The {cwd}, {git}, {lamb}, etc, are to be substituted with the actual content later on. The \x1b[1;32;40m is the ANSI escape sequence that controls the color of following text. 32 means green text color, 40 means black background color, 39 means default text color, and 49 means default background color.

Why was pyenv/conda environment omitted?

Also in function set_prompt_filter in %cmder_root%\vender\clink.lua, you may find how cmder added the information of virtual environments into {lamb} (or more specifically, prompts with () or []). So either you have to retrieve that information from the original prompt, or simply just replace the color codes, as in this answer.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 RibomBalt