Using a Color Dialog to choose colors for ISE
Posted by: Andy Schneider in CTP 3, ISE, Integrated Scripting Environment, PowershellCurrently, 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
After clicking on Red, I get the following output
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:
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.
Entries (RSS)
Nice!
[...] Andy Schneider talked about this on the interview: Using a Color Dialog to Choose Colors for ISE [...]
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