Using a Color Dialog to choose colors for ISE

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.

Comments (4) -

Andy Tearle 2/6/2009 2:02:12 AM

Nice!

roshan porwal 4/21/2009 6:04:01 AM

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.

Hi,
Sorry for what might be a newbie question (I've only embraced Powershell in the last week!) but how do you customise the GUI to look like the screenshots above (i.e. cut/copy/paste toolbars along the side of the command pane, run/stop buttons at top of the command pand and the graphical command prompt?
I am running Powershell V2 on Vista with .NET Framework 3.5 if that helps...

Thanks in advance!
H

Made a web based color picker
http://jrich523.atspace.com/index.htm
I have some idea's for more features and to make it run better, but want to get a feel for interest before i put in more effort, check it out!

Comments are closed