Renderers/MemberDefinitionRenderer.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
function Write-MemberDefinitionHeader{
    [CmdletBinding()]
    param (
        [Parameter()]
        [System.String]
        $TypeName
    )

    if ($script:currentDirectory -eq "" -or $script:currentDirectory -ne $TypeName)
    {
        Write-Host
        Write-Host $TypeName -ForegroundColor Green
        Write-Host

        Write-Host 'Name MemberType Definition'
        Write-Host '---- ---------- ----------'

        $script:currentDirectory = "$TypeName"
    }
}

function Write-MemberDefinition
{
    param ([Parameter(Mandatory=$True,Position=1)] $item)

    Write-MemberDefinitionHeader $item.TypeName

    $width = $Host.UI.RawUI.WindowSize.Width - 45

    if ($width -lt 30)
    {
        $width = 30
    }

    $definition = $item.Definition;

    if ($definition.Length -ge $width)
    {
        $definition = $definition.Substring(0, $width) + ".."
    }

    $output = [System.String]::Format("{0, -27}{1, -16}{2}", $item.Name, $item.MemberType, $definition)

    $foreground = $global:PoshColor.CommandInfo.Default.Color

    if ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::CodeMethod)
    {
        $foreground = $global:PoshColor.PSMemberType.CodeMethod.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::AliasProperty)
    {
        $foreground = $global:PoshColor.PSMemberType.AliasProperty.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::CodeProperty)
    {
        $foreground = $global:PoshColor.PSMemberType.CodeProperty.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::Method)
    {
        $foreground = $global:PoshColor.PSMemberType.Method.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::Methods)
    {
        $foreground = $global:PoshColor.PSMemberType.Methods.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::NoteProperty)
    {
        $foreground = $global:PoshColor.PSMemberType.NoteProperty.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::ParameterizedProperty)
    {
        $foreground = $global:PoshColor.PSMemberType.ParameterizedProperty.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::Properties)
    {
        $foreground = $global:PoshColor.PSMemberType.Properties.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::Property)
    {
        $foreground = $global:PoshColor.PSMemberType.Property.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::PropertySet)
    {
        $foreground = $global:PoshColor.PSMemberType.PropertySet.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::ScriptMethod)
    {
        $foreground = $global:PoshColor.PSMemberType.ScriptMethod.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::ScriptProperty)
    {
        $foreground = $global:PoshColor.PSMemberType.ScriptProperty.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::Dynamic)
    {
        $foreground = $global:PoshColor.PSMemberType.Dynamic.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::Event)
    {
        $foreground = $global:PoshColor.PSMemberType.Event.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::InferredProperty)
    {
        $foreground = $global:PoshColor.PSMemberType.InferredProperty.Color
    }
    elseif ($item.MemberType -eq [System.Management.Automation.PSMemberTypes]::MemberSet)
    {
        $foreground = $global:PoshColor.PSMemberType.MemberSet.Color
    }
    
    Write-HostColor $output -Foreground $foreground

    return $true
}