|
6 | 6 | using Microsoft.PowerShell.EditorServices.Session;
|
7 | 7 | using Microsoft.PowerShell.EditorServices.Utility;
|
8 | 8 | using System;
|
| 9 | +using System.Diagnostics.CodeAnalysis; |
9 | 10 | using System.Management.Automation;
|
10 | 11 | using System.Management.Automation.Host;
|
11 | 12 | using System.Management.Automation.Runspaces;
|
@@ -78,14 +79,132 @@ public override string Name
|
78 | 79 | }
|
79 | 80 |
|
80 | 81 | /// <summary>
|
81 |
| - /// |
| 82 | + /// |
| 83 | + /// </summary> |
| 84 | + public class ConsoleColorProxy |
| 85 | + { |
| 86 | + private EditorServicesPSHostUserInterface _hostUserInterface; |
| 87 | + |
| 88 | + public ConsoleColorProxy(EditorServicesPSHostUserInterface hostUserInterface) |
| 89 | + { |
| 90 | + if (hostUserInterface == null) throw new ArgumentNullException("hostUserInterface"); |
| 91 | + _hostUserInterface = hostUserInterface; |
| 92 | + } |
| 93 | + |
| 94 | + public ConsoleColor ErrorForegroundColor |
| 95 | + { |
| 96 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 97 | + get |
| 98 | + { return _hostUserInterface.ErrorForegroundColor; } |
| 99 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 100 | + set |
| 101 | + { _hostUserInterface.ErrorForegroundColor = value; } |
| 102 | + } |
| 103 | + |
| 104 | + public ConsoleColor ErrorBackgroundColor |
| 105 | + { |
| 106 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 107 | + get |
| 108 | + { return _hostUserInterface.ErrorBackgroundColor; } |
| 109 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 110 | + set |
| 111 | + { _hostUserInterface.ErrorBackgroundColor = value; } |
| 112 | + } |
| 113 | + |
| 114 | + public ConsoleColor WarningForegroundColor |
| 115 | + { |
| 116 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 117 | + get |
| 118 | + { return _hostUserInterface.WarningForegroundColor; } |
| 119 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 120 | + set |
| 121 | + { _hostUserInterface.WarningForegroundColor = value; } |
| 122 | + } |
| 123 | + |
| 124 | + public ConsoleColor WarningBackgroundColor |
| 125 | + { |
| 126 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 127 | + get |
| 128 | + { return _hostUserInterface.WarningBackgroundColor; } |
| 129 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 130 | + set |
| 131 | + { _hostUserInterface.WarningBackgroundColor = value; } |
| 132 | + } |
| 133 | + |
| 134 | + public ConsoleColor DebugForegroundColor |
| 135 | + { |
| 136 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 137 | + get |
| 138 | + { return _hostUserInterface.DebugForegroundColor; } |
| 139 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 140 | + set |
| 141 | + { _hostUserInterface.DebugForegroundColor = value; } |
| 142 | + } |
| 143 | + |
| 144 | + public ConsoleColor DebugBackgroundColor |
| 145 | + { |
| 146 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 147 | + get |
| 148 | + { return _hostUserInterface.DebugBackgroundColor; } |
| 149 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 150 | + set |
| 151 | + { _hostUserInterface.DebugBackgroundColor = value; } |
| 152 | + } |
| 153 | + |
| 154 | + public ConsoleColor VerboseForegroundColor |
| 155 | + { |
| 156 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 157 | + get |
| 158 | + { return _hostUserInterface.VerboseForegroundColor; } |
| 159 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 160 | + set |
| 161 | + { _hostUserInterface.VerboseForegroundColor = value; } |
| 162 | + } |
| 163 | + |
| 164 | + public ConsoleColor VerboseBackgroundColor |
| 165 | + { |
| 166 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 167 | + get |
| 168 | + { return _hostUserInterface.VerboseBackgroundColor; } |
| 169 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 170 | + set |
| 171 | + { _hostUserInterface.VerboseBackgroundColor = value; } |
| 172 | + } |
| 173 | + |
| 174 | + public ConsoleColor ProgressForegroundColor |
| 175 | + { |
| 176 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 177 | + get |
| 178 | + { return _hostUserInterface.ProgressForegroundColor; } |
| 179 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 180 | + set |
| 181 | + { _hostUserInterface.ProgressForegroundColor = value; } |
| 182 | + } |
| 183 | + |
| 184 | + public ConsoleColor ProgressBackgroundColor |
| 185 | + { |
| 186 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 187 | + get |
| 188 | + { return _hostUserInterface.ProgressBackgroundColor; } |
| 189 | + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| 190 | + set |
| 191 | + { _hostUserInterface.ProgressBackgroundColor = value; } |
| 192 | + } |
| 193 | + } |
| 194 | + |
| 195 | + /// <summary> |
| 196 | + /// Return the actual console host object so that the user can get at |
| 197 | + /// the unproxied methods. |
82 | 198 | /// </summary>
|
83 | 199 | public override PSObject PrivateData
|
84 | 200 | {
|
85 |
| - // There is no PrivateData yet but by returning an empty object we can get past PowerShell's |
86 |
| - // check for $host.PrivateData["window"] which errors on the null returned by default. |
87 |
| - get { return new PSObject(); } |
| 201 | + get |
| 202 | + { |
| 203 | + if (hostUserInterface == null) return null; |
| 204 | + return _consoleColorProxy ?? (_consoleColorProxy = PSObject.AsPSObject(new ConsoleColorProxy(hostUserInterface))); |
| 205 | + } |
88 | 206 | }
|
| 207 | + private PSObject _consoleColorProxy; |
89 | 208 |
|
90 | 209 | /// <summary>
|
91 | 210 | ///
|
|
0 commit comments