Skip to content

We need a way to customize output color for error/warning, etc #651

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

Closed
Jaykul opened this issue Apr 10, 2018 · 23 comments · Fixed by #654
Closed

We need a way to customize output color for error/warning, etc #651

Jaykul opened this issue Apr 10, 2018 · 23 comments · Fixed by #654
Labels
Area-Extension Terminal Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.

Comments

@Jaykul
Copy link

Jaykul commented Apr 10, 2018

Specifically, in PowerShell.exe we have the ability to change the color used for errors, warnings, etc.:

C:\PS> $Host.PrivateData                                                    
                                      
ErrorForegroundColor    : DarkRed     
ErrorBackgroundColor    : Black       
WarningForegroundColor  : Yellow      
WarningBackgroundColor  : Black       
DebugForegroundColor    : Green       
DebugBackgroundColor    : Black       
VerboseForegroundColor  : Cyan        
VerboseBackgroundColor  : Black       
ProgressForegroundColor : DarkMagenta 
ProgressBackgroundColor : Gray        

In VSCode I can change the colors of the 16 ANSI colors, but I can't find a way to change which of them you are using to write errors out.

@Jaykul Jaykul changed the title We need a way to customize colors We need a way to customize output color for error/warning, etc Apr 10, 2018
@TylerLeonhardt
Copy link
Member

Thanks Joel! I reasonable request indeed.

@TylerLeonhardt TylerLeonhardt added Issue-Enhancement A feature request (enhancement). Area-Extension Terminal labels Apr 10, 2018
@SeeminglyScience
Copy link
Collaborator

If anyone is interested in picking this up the general idea is to

  1. Port ConsoleColorProxy and the PrivateData member from ConsoleHost in pwsh to EditorServicesPSHost.PrivateData

  2. Change the Write* methods in EditorServicesPSHostUserInterface to use the new colors

@SeeminglyScience SeeminglyScience added the Up for Grabs Will shepherd PRs. label Apr 11, 2018
@KeroroLulu
Copy link
Contributor

KeroroLulu commented Apr 17, 2018

I would like to work on it ! Can I be assign ?

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Apr 18, 2018

@KeroroLulu you can work on any issue at any time you'd like :)

We don't usually 'assign' work. You can freely start and submit a Pull Request when you're ready to get feedback!

Once the PR looks good, we will merge it in!

@KeroroLulu
Copy link
Contributor

@tylerl0706 Thank you :)

I'm not used to stuff like that, so if I have any questions I'll ask you !

@TylerLeonhardt
Copy link
Member

You can always ask questions too!

Let me know if you have any 👍

@KeroroLulu
Copy link
Contributor

KeroroLulu commented Apr 18, 2018

@tylerl0706 In the instructions

Port ConsoleColorProxy and the PrivateData member from ConsoleHost in pwsh to EditorServicesPSHost.PrivateData

The link for EditorServicesPSHost.PrivateData redirect here, I should create this file and copy/past ConsoleColorProxy class and PrivateData member in it, or this file already exist ?

Edit

Nevermind I just found PrivateData. Sorry but my english comprehension is not perfect but what do you mean by "Port ConsoleColorProxy ..." ? I guess that it's not just a copy/past, right ?

@TylerLeonhardt
Copy link
Member

No problem :) Port usually means "take that and add it to this" sometimes it does mean actually copy/paste. However I think it's a little bit more work than copy/paste.

First copy paste those classes over into EditorServicesPSHost.PrivateData, then try to build and see what you need to fix to get those classes to work in PSES(PowerShell Editor Services).

Then, follow @SeeminglyScience's next step and Change the Write* methods in EditorServicesPSHostUserInterface to use the new colors.

@KeroroLulu
Copy link
Contributor

KeroroLulu commented Apr 18, 2018

@tylerl0706 Ok ! But I have to copy ConsoleColorProxy class into the override or above like in ConsoleHost ?

Edit

I can't use ConsoleHostUserInterface due to his level of restriction I tried using Microsoft.PowerShell.EditorServices.Console; but it doesn't work. Which import should I use to prevent this error ?

@TylerLeonhardt
Copy link
Member

What was the error that you got?

@KeroroLulu
Copy link
Contributor

@tylerl0706 My powershell is in french but by translating we got :

Session/Host/EditorServicesPSHost.cs(89,38): error CS0122: 'ConsoleHostUserInterface' is unreachable because of its level of protection

I think that's because ConsoleHostUserInterface is in Powershell and not in Powershell Editor Service

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Apr 18, 2018

Ah yeah you should replace that with EditorServicesPSHostUserInterface probably

Here are all of the *UserInterface.cs files:
https://github.com/PowerShell/PowerShellEditorServices/tree/a0761cf8cce885ec70c9307fa600aa02f2f4b441/src/PowerShellEditorServices/Session/Host

@KeroroLulu
Copy link
Contributor

KeroroLulu commented Apr 19, 2018

@tylerl0706 The problem is that EditorServicesPSHostUserInterface doesn't contain any color method so when I replace ConsoleHostUserInterface I have this error :

Session/Host/EditorServicesPSHost.cs(99,45): error CS1061: 'EditorServicesPSHostUserInterface' doesn't contain any definition for 'ErrorForegroundColor' and no extension method 'ErrorForegroundColor' accepting first argument of type 'EditorServicesPSHostUserInterface' has been found

Should I use WriteErrorLine instead of ErrorForegroundColoror ErrorBackgroundColor?

For example

public ConsoleColor ErrorBackgroundColor
            {
                [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
                get
                { return _hostUserInterface.Write.backgroundColor; }
                [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
                set
                { _hostUserInterface.Write.backgroundColor = value; }
            }

something like that ?
(Sorry for asking so many questions ^^")

@TylerLeonhardt
Copy link
Member

You should be able to add these that I see in ConsoleHostUserInterface:
https://github.com/PowerShell/PowerShell/blob/c1c5344a8897262433141ecbc13bb06ac2c4bbef/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs#L1359-L1376

to EditorServicesPSHostUserInterface

@TylerLeonhardt
Copy link
Member

And then don't forget to edit these to use those values instead of the hardcoded ones 🙂

Ask all the questions you need. You've got this 💪 you're going to fix this issue 😃

@KeroroLulu
Copy link
Contributor

KeroroLulu commented Apr 19, 2018

@tylerl0706 Console.BackgroundColor doesn't exist in Microsoft.PowerShell.EditorServices.Console. Where is BackgroundColor exactly ? I will add it to Console.

Edit

I found it I think it's

public static ConsoleColor BackgroundColor
        {
            get;
            set;
        }

Tell me if I'm wrong. I added it to EditorServicesPSHostUserInterface

Edit 2

I changed all the WriteOutput method for Debug, Error, Verbose and Warning :

public override void WriteDebugLine(string message)
        {
            this.WriteOutput(
                DebugMessagePrefix + message,
                true,
                OutputType.Debug,
                foregroundColor: this.DebugForegroundColor,
                backgroundColor: this.DebugBackgroundColor);
        }

tell me if I did nothing wrong with the Invoke-Build there's no error. I would like to test it but I don't really know how.

And finally WriteProgress I don't know if I have to change something for the color or if it's ok.

@TylerLeonhardt
Copy link
Member

That's great @KeroroLulu!

Here's what you can do to test:
Right now, the best way to do this is by building and launching the vscode powershell extension.

Follow these instructions to test your code out:
https://github.com/PowerShell/vscode-powershell/blob/master/docs/development.md

@KeroroLulu
Copy link
Contributor

KeroroLulu commented Apr 19, 2018

@tylerl0706 Should I add Unit Test to my code ?

Edit

I'm on mac and I'm trying to launch the extension with F5, it propose me several process to attach my extension (zsh, adobe, cloud, etc...) which one should I use ?

Edit 2

I did it somehow by using code-insiders --extensionDevelopmentPath="/Users/My/vscode-powershell" but then I don't know how it works exactly I tried to change some background value for warning but it change nothing so I don't know if this is the code or the way I test it.

KeroroLulu pushed a commit to KeroroLulu/PowerShellEditorServices that referenced this issue Apr 19, 2018
@TylerLeonhardt
Copy link
Member

@KeroroLulu does $Host.PrivateData give you anything?

@KeroroLulu
Copy link
Contributor

It gives me :

ErrorForegroundColor    : Red
ErrorBackgroundColor    : -1
WarningForegroundColor  : Yellow
WarningBackgroundColor  : -1
DebugForegroundColor    : Yellow
DebugBackgroundColor    : -1
VerboseForegroundColor  : Yellow
VerboseBackgroundColor  : -1
ProgressForegroundColor : Yellow
ProgressBackgroundColor : DarkCyan

I just tested it by deleting the message but it's just my way to test it that doesn't work. How can I print warning or error by using PWSH Editor Services ?

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Apr 19, 2018

If you change $Host.PrivateData.ErrorForegroundColor in the integrated terminal to DarkCyan, and do a:

Write-Error "foo"

does it still print in red or dark cyan?

Note this will only work if you made the correct changes to the Write* function here:

to use the this.ErrorForegroundColor (I think it's called) instead of "Red"

You're getting there! 😄

@KeroroLulu
Copy link
Contributor

KeroroLulu commented Apr 19, 2018

@tylerl0706 Well I changed it in EditorServicesPSHostInterface

public ConsoleColor ErrorForegroundColor { get; set; } = ConsoleColor.DarkCyan;

But it doesn't change in my pwsh

Here's my WriteOutput

public override void WriteErrorLine(string value)
        {
            this.WriteOutput(
                value,
                true,
                OutputType.Error,
                foregroundColor: this.ErrorForegroundColor,
                backgroundColor: this.ErrorBackgroundColor);
        }

I did my Invoke-Build Build and there's no error

Edit

It's really strange, I change my WriteOutput

public override void WriteErrorLine(string value)
        {
            this.WriteOutput(
                value,
                true,
                OutputType.Error,
                foregroundColor: ConsoleColor.DarkCyan,
                backgroundColor: this.ErrorBackgroundColor);
        }

But my error foreground color is still red !

Edit 2

Nevermind !! It works that was just a little problem from my installation :)

I will do the Pull Request !

KeroroLulu pushed a commit to KeroroLulu/PowerShellEditorServices that referenced this issue Apr 20, 2018
Supress Warnings in travis

Supress Warning in Travis PowerShell#2

Test for travis

Add Comment XML for travis

Add Comment for Testing
@TylerLeonhardt
Copy link
Member

That's great @KeroroLulu!! 🎉 🎉

TylerLeonhardt pushed a commit that referenced this issue Apr 21, 2018
* Add customize output color enhancement (#651)

Supress Warnings in travis

Supress Warning in Travis #2

Test for travis

Add Comment XML for travis

Add Comment for Testing

* Adding internal class

I added all internal class and suppress all the SuppressMessage.
But I can't remove the empty documentation, the analysis of
PowerShell Editor Services doesn't let it pass. I tried to add
the suppress warning in it but it doesn't work as well. So I had to
add all documentation.

* Suppress Documentation for internal members

Sorry I didn't notice that was only for public members until I read
the error again.

* Add text for color sumary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Extension Terminal Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants