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

ANSI 256-color and 24-bit color support #455

Merged
merged 8 commits into from
Mar 16, 2017
Merged

ANSI 256-color and 24-bit color support #455

merged 8 commits into from
Mar 16, 2017

Conversation

dahlbyk
Copy link
Owner

@dahlbyk dahlbyk commented Mar 4, 2017

This PR adds support for colors beyond [ConsoleColor]:

Includes #454 for adjusting Write-Prompt semantics, updated for 1.0 changes.

24-bit support currently depends on System.Drawing. Not sure what Core options are there, but I've tried to make the assembly/type loading resilient.

Usage

$GitPromptSettings.DefaultForegroundColor = [ConsoleColor]::Blue
$GitPromptSettings.DefaultForegroundColor = 'Aquamarine'
$GitPromptSettings.DefaultForegroundColor = [Drawing.Color]::Aqua
$GitPromptSettings.DefaultForegroundColor = '#bbb'
$GitPromptSettings.DefaultForegroundColor = [byte]0xf0
$GitPromptSettings.DefaultForegroundColor = $null

I have tried testing with ConEmu, but 256-color mode doesn't seem to be working? Or is that a limitation of PS v5?
conemu64_2017-03-04_11-28-00

24-bit support depends on System.Drawing for parsing HTML color strings.
The setting exists for legacy reasons: 02956e1.
It was removed in #202 and restored in #209 to avoid a breaking change.

Since we still have it, I suppose we might as well support using it to
control the prompt text color.
@dahlbyk
Copy link
Owner Author

dahlbyk commented Mar 4, 2017

Interesting... so a question maybe for @lzybkr: is it expected that the $Host.UI.RawUI color properties are mutated by "<ANSI color string>" | Out-Host but not "<ANSI color string>" | Write-Host"? Since #447, using ANSI in the prompt means $Host.UI.RawUI colors can't be adjusted because they're always reset by ESC[0m in the prompt result. Are RawUI.ForegroundColor/BackgroundColor not meant to be manipulated? How else might one change, let's say, the default colors from the (very peculiar) defaults of DarkYellow/DarkMagenta?

image

Copy link
Collaborator

@lzybkr lzybkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

256 color/24 bit color support is in the Creators update - hopefully hitting RTM soon. You can try out insiders builds to see it working - there's nothing special about it in PowerShell, see https://twitter.com/lzybkr/status/779069905136037888

@@ -20,10 +20,28 @@ $ConsoleColorToAnsi = @(
$AnsiDefaultColor = 39
$AnsiEscape = [char]27 + "["

[Reflection.Assembly]::LoadWithPartialName('System.Drawing') > $null
$ColorTranslatorType = ([System.Management.Automation.PSTypeName]'System.Drawing.ColorTranslator').Type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

$ColorTranslatorType = 'System.Drawing.ColorTranslator' -as [Type]

@lzybkr
Copy link
Collaborator

lzybkr commented Mar 5, 2017

Regarding ESC[0m - I feel like there is a bug in conhost in not honoring the current foreground/background colors - but it depends on how you set those colors.

If you set fore/background colors via escape sequences, then I believe ESC[0m is working as expected - not necessarily the way I think it should, but it's compatible with *nix systems.

If you set fore/background colors via a specific Win32 api, I think ESC[0m should reset to those colors, not the initial colors from startup.

Ideally ANSI would have push/pop semantics, but that doesn't exist unfortunately.

@dahlbyk
Copy link
Owner Author

dahlbyk commented Mar 6, 2017

@lzybkr so from posh-git's standpoint, then, would you agree that it is most correct for us to continue using ESC[0m to terminate our colorized strings?

I guess what confuses me most is the distinction between Write-Host (doesn't modify RawUI) and Out-Host (does). Apparently the prompt string is using the latter?

@dahlbyk dahlbyk merged commit 91064eb into develop Mar 16, 2017
@dahlbyk dahlbyk deleted the 24-bit-color branch March 16, 2017 04:17
@dahlbyk
Copy link
Owner Author

dahlbyk commented Mar 16, 2017

Merged so I can more easily bring master's Write-Prompt changes into develop.

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

Successfully merging this pull request may close these issues.

2 participants