image

Currently, there are no default UI options to set the color for the Script Pane, the Command Pane, or the Output Pane. However, these can all be changed using $psISE.

I wrote a few functions to help with this.

function Set-CommandBackPaneColor {
param
(
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    $color
)
    $psise.Options.CommandPaneBackground = $color
}

function Set-OutputPaneColor {
param
(
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    $color
)
    $psise.Options.OutputPaneBackground = $color
    $psise.Options.OutputPaneTextBackground = $color
}

function Set-ScriptPaneColor {
param
(
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    $color
)
    $psise.Options.ScriptPaneBackground = $color
}

Automatically generated with a custom version of Write-CommandBlogPost

Set-OutputPaneColor sets two options, OutputPaneBackground and OutputPaneTextBackground. I have found that I like to have these the same, but you can easily separate them out if you like.

The last little tidbit is figuring out how to get a color picker rather than typing in the name of the color. We can accomplish this with a little Winforms action.

function Get-Color {
    $colorDialog = new-object System.Windows.Forms.ColorDialog
    $colorDialog.AllowFullOpen = $false
    [void]$colorDialog.ShowDialog()
    $colorDialog.Color.Name
}

Automatically generated with a custom version of Write-CommandBlogPost

This will return the name of the color that was picked

image

After clicking on Red, I get the following output

image

So now we can tie this all together with one final line to add a custom menu to ISE

[void]$psISE.CustomMenu.Submenus.Add("Output Pane Color", {Get-Color | Set-OutputPaneColor},$null)

I just passed in Null because I didn’t want a keyboard shortcut, but you can use one pretty easily.

So now I get the following:

image

I could set up Menus to set other color options for the script and command panes as well, but I figure that is enough screenshots to make the point.

The other custom commands are from Karl Prosser. I highly recommend you take a look at them as well. Very useful.

So there is one (not so subtle) flaw in the get-color function. It does not always place the color dialog on the top, so sometimes I have to Alt-Tab over to it. There is probably some nifty way with winforms to make it show up on top all the time, but I figured I would get this out there and then work on that little part.

Secondly, not all the colors work right now.

3 Responses to “Using a Color Dialog to choose colors for ISE”
  1. Andy Tearle says:

    Nice!

  2. [...] Andy Schneider talked about this on the interview: Using a Color Dialog to Choose Colors for ISE [...]

  3. roshan porwal says:

    hi,
    I am a facing a similar problem with colordialog – t does not always place the color dialog on the top. If you have the solution for it kindly share.

Leave a Reply