plugins/pscolor/src/module/src/public/Out-Default.ps1

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function Out-Default {
    <#
    .SYNOPSIS
    Proxy Out-Default command required for colorization of console output.
    .DESCRIPTION
    Proxy Out-Default command required for colorization of console output.
    .PARAMETER Transcript
    TBD
    .PARAMETER InputObject
    TBD
    #>

    [CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=113362', RemotingCapability='None')]
    param(
        [switch]
        ${Transcript},

        [Parameter(Position=0, ValueFromPipeline=$true)]
        [psobject]
        ${InputObject})

    begin
    {
        try {
            $outBuffer = $null
            if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
            {
                $PSBoundParameters['OutBuffer'] = 1
            }
            $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Core\Out-Default', [System.Management.Automation.CommandTypes]::Cmdlet)
            $scriptCmd = {& $wrappedCmd @PSBoundParameters }

            $steppablePipeline = $scriptCmd.GetSteppablePipeline()
            $steppablePipeline.Begin($PSCmdlet)
        } catch {
            throw
        }
    }

    process {
        try {
            # Our snazzy hook for colorizing the output...
            if ($_ -ne $null) {
                if  ($Script:PSColorTypeMapKeys -contains ($_.pstypenames)[0]) {
                    .([scriptblock]::create($Script:PSColorTypeMap[$_.pstypenames[0]]))
                    $_ = $null
                }
                else {
                    $steppablePipeline.Process($_)
                }
            }
            else {
                $steppablePipeline.Process($_)
            }
        } catch {
            throw
        }
    }

    end {
        try {
            write-host ""
            $script:showHeader=$true
            $steppablePipeline.End()
        }
        catch {
            throw
        }
    }
}