Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Colored ls output & zsh-like autocompletion

Reply
 
Old 08-19-2006   #1 (permalink)
Andrey Balaguta


 
 

Colored ls output & zsh-like autocompletion

Hello!

I have two question about PowerShell standard console host.

First question, is it possible to produce colored output like ls under
Linux does _ONLY_ using Format.ps1xml files? Specifically, is it
possible to output one specific View /TableControl /TableRowEntries/
TableRowEntry /TableColumnItems /TableColumnItem in some specific color?

Second, is it possible to achieve autocompletion similar to zsh
autocompletion (or bash at worst). I mean that nifty colored list which
is popped up on TAB keypress and popped down on subsequent typing, and
all that "There is 10000000 files. Do you want me to show them all?"
stuff

Thanks in advance.

--
WBR, Andrey Balaguta <andrey.balaguta (@) gmail.com>

My System SpecsSystem Spec
Old 08-28-2006   #2 (permalink)
James Truher


 
 

Re: Colored ls output & zsh-like autocompletion

first question:
not really, color support is not provided in the formatting tools. It is possible to spoof, but it's because the script sets the foreground color back. Take the following example (note that it uses my custom convert-hashtoobject cmdlet):

$props = "symbol","Last","date","time","change","Open","high","low","volume"
$SYMS = "MSFT","SCO","^DJI","INFY","SUNW"
if ( $args ) { $SYMS += $args }
$fg = $host.ui.rawui.foregroundcolor
foreach ( $SYM in $SYMS )
{
$yahoo = "http://finance.yahoo.com/d/quotes.csv?s="
$url = "${yahoo}${SYM}&f=sl1d1t1c1ohgv&e=.csv"
[string]$string = $(get-uri $url )
if ( $string )
{
$stock = $string.replace("`"","").Trim().split(",")
$h = @{ Symbol = [string]$stock[0]
Last = [double]$stock[1]
Date = [datetime]$stock[2]
Time = [datetime]$stock[3]
Change = [double]$stock[4]
Open = [double]$stock[5]
High = [double]$stock[6]
Low = [double]$stock[7]
Volume = [int]$stock[8] }
convert-hashtoobject -hash $h -names JWT.Stock
}
}
$host.ui.rawui.foregroundcolor = $fg

when combined with this table view:
<View>
<Name>JWT.Stock</Name>
<ViewSelectedBy>
<TypeName>JWT.Stock</TypeName>
</ViewSelectedBy>
<TableControl>
<HideTableHeaders/>
<TableHeaders>
<TableColumnHeader>
<Width>8</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>8</Width>
<Alignment>Right</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Width>8</Width>
<Label>Change</Label>
<Alignment>Right</Alignment>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Symbol</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Last</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
if ( $_.change -lt 0 ) { $host.ui.rawui.foregroundcolor = "red" }
elseif ( $_.change -gt 0 ) { $host.ui.rawui.foregroundcolor = "darkgreen" }
else { $host.ui.rawui.foregroundcolor = "black" }
$_.Change
</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

you get output that looks like this:

PS> Stock
MSFT 25.95 0.1
SCO 2.46 -0.01
^DJI 11352.01 67.96
INFY 43.82 0.71
SUNW 4.92 0.07

(you'll see colors if you're looking at HTML rather than plaintext)

However, without the script, the font color will be left in whatever was the last color - not good. The formatter really wasn't designed to support color.

--
James Truher[MSFT]
Program Manager - Windows PowerShell
Microsoft Corporation
This posting is provided "AS IS" with no warranties, no confers rights.
Visit the Windows PowerShell Team blog at:
http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:
http://www.microsoft.com/technet/scr.../hubs/msh.mspx
"Andrey Balaguta" <andrey.balaguta@gmail.com> wrote in message news:uwENoo7wGHA.324@TK2MSFTNGP06.phx.gbl...
> Hello!
>
> I have two question about PowerShell standard console host.
>
> First question, is it possible to produce colored output like ls under
> Linux does _ONLY_ using Format.ps1xml files? Specifically, is it
> possible to output one specific View /TableControl /TableRowEntries/
> TableRowEntry /TableColumnItems /TableColumnItem in some specific color?
>
> Second, is it possible to achieve autocompletion similar to zsh
> autocompletion (or bash at worst). I mean that nifty colored list which
> is popped up on TAB keypress and popped down on subsequent typing, and
> all that "There is 10000000 files. Do you want me to show them all?"
> stuff
>
> Thanks in advance.
>
> --
> WBR, Andrey Balaguta <andrey.balaguta (@) gmail.com>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Colored Text and Pipelines PowerShell
Windows mail autocompletion Vista mail
Autocompletion and autoresolution Vista mail
Colored Folders Vista General
Autocompletion? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46