PoshCode Archive  Artifact [d36e42f704]

Artifact d36e42f704b741c7075961138e5bef2e32d01a038792f5d6be4eee91dde84461:

  • File Out-IseFile.ps1 — part of check-in [65bac29566] at 2018-06-10 12:59:19 on branch trunk — PowerShells wrapping behaviour may be adequate for the console host. Using ISE it’s far from the optimal. But you don’t need to use the output pane. Send your output to a new ISE Editor. To see the difference just try: (user: unknown size: 2579)

# encoding: ascii
# api: powershell
# title: Out-IseFile
# description: PowerShells wrapping behaviour may be adequate for the console host. Using ISE it’s far from the optimal. But you don’t need to use the output pane. Send your output to a new ISE Editor. To see the difference just try:
# version: 0.1
# type: function
# license: CC0
# function: Out-IseFile
# x-poshcode-id: 1623
# x-archived: 2010-02-26T16:09:16
#
# get-help *  | out-ISEFile
#


function Out-IseFile
{

    [CmdletBinding()]
    param (
        [Parameter(Position = 0, Mandatory = $True,  ValueFromPipeline = $True) ]        
        $msg, 
        [Parameter(Position = 1, Mandatory = $False, ValueFromPipeline = $False)]        
        $path = $null,
        [Parameter(Position = 2, Mandatory = $False, ValueFromPipeline = $False)]        
        $width = 2000,
        [switch]$fl,
        [switch]$passEditor
    )

    Begin
    {
        $cnt = 0
        $count   = $psise.CurrentPowerShellTab.Files.count
        $null    = $psIse.CurrentPowerShellTab.Files.Add()
        $Newfile = $psIse.CurrentPowerShellTab.Files[$count]
        if ($path)
        {    
            $NewFile.SaveAs($path)
            $NewFile.Save([Text.Encoding]::default)
        }
        $Editor = $Newfile.Editor
        
        filter Remove-TrailingBlanks { $_ -replace '(?m)\s*$', '' }
        #filter Remove-TrailingBlanks { $_.TrimEnd() }
    }

    Process
    {
        $cnt++
       # if ($msg) { $msg | gm | Write-Verbose }
       if ($cnt -eq 1)
       {
        $cmsg = @($msg)
       }
       else
       {
       $cmsg = $cmsg +  @($msg)
       }
    }
    
    End
    {   
        if ($cnt -gt 1)
        {
            $msg = $cmsg
        }
        if ($fl)
        {
            $msg = $msg |  Format-list | out-string -width $width | Remove-trailingBlanks
        }
        else
        {
            $msg = $msg | out-string -width $width | Remove-trailingBlanks
        }
        $msg = $msg +  "`r`n"

        #$Editor.SetCaretPosition($Editor.LineCount, 1)
        $Editor.InsertText($msg)

        if ($passEditor){ $Newfile }
        
        Write-Verbose "Anzahl = $cnt   len msg = $($msg.count)"
    }
}

<#

$profile.psextended | out-IseFile -fl -verb

get-help *  | out-string -width 2000| out-ISEFile -verb
get-help *  | out-ISEFile -verb
get-help *  | out-ISEFile 

 
 
$a =  $profile.psextended
out-IseFile  $a -fl


$a = get-help *  | out-string -width 2000 
out-IseFile  $a
#>