7
7
using System . Collections . ObjectModel ;
8
8
using System . Management . Automation ;
9
9
using System . Management . Automation . Host ;
10
- using System . Reflection ;
11
10
using System . Security ;
12
11
using System . Threading ;
13
12
using Microsoft . Extensions . Logging ;
@@ -21,8 +20,6 @@ internal class EditorServicesConsolePSHostUserInterface : PSHostUserInterface
21
20
22
21
private readonly PSHostUserInterface _underlyingHostUI ;
23
22
24
- private readonly PSHostUserInterface _consoleHostUI ;
25
-
26
23
/// <summary>
27
24
/// We use a ConcurrentDictionary because ConcurrentHashSet does not exist, hence the value
28
25
/// is never actually used, and `WriteProgress` must be thread-safe.
@@ -37,58 +34,19 @@ public EditorServicesConsolePSHostUserInterface(
37
34
_readLineProvider = readLineProvider ;
38
35
_underlyingHostUI = underlyingHostUI ;
39
36
RawUI = new EditorServicesConsolePSHostRawUserInterface ( loggerFactory , underlyingHostUI . RawUI ) ;
40
-
41
- _consoleHostUI = GetConsoleHostUI ( _underlyingHostUI ) ;
42
-
43
- if ( _consoleHostUI != null )
44
- {
45
- SetConsoleHostUIToInteractive ( _consoleHostUI ) ;
46
- }
47
37
}
48
38
49
39
public override bool SupportsVirtualTerminal => _underlyingHostUI . SupportsVirtualTerminal ;
50
40
51
41
public override PSHostRawUserInterface RawUI { get ; }
52
42
53
- public override Dictionary < string , PSObject > Prompt ( string caption , string message , Collection < FieldDescription > descriptions )
54
- {
55
- if ( _consoleHostUI != null )
56
- {
57
- return _consoleHostUI . Prompt ( caption , message , descriptions ) ;
58
- }
43
+ public override Dictionary < string , PSObject > Prompt ( string caption , string message , Collection < FieldDescription > descriptions ) => _underlyingHostUI . Prompt ( caption , message , descriptions ) ;
59
44
60
- return _underlyingHostUI . Prompt ( caption , message , descriptions ) ;
61
- }
45
+ public override int PromptForChoice ( string caption , string message , Collection < ChoiceDescription > choices , int defaultChoice ) => _underlyingHostUI . PromptForChoice ( caption , message , choices , defaultChoice ) ;
62
46
63
- public override int PromptForChoice ( string caption , string message , Collection < ChoiceDescription > choices , int defaultChoice )
64
- {
65
- if ( _consoleHostUI != null )
66
- {
67
- return _consoleHostUI . PromptForChoice ( caption , message , choices , defaultChoice ) ;
68
- }
69
-
70
- return _underlyingHostUI . PromptForChoice ( caption , message , choices , defaultChoice ) ;
71
- }
47
+ public override PSCredential PromptForCredential ( string caption , string message , string userName , string targetName , PSCredentialTypes allowedCredentialTypes , PSCredentialUIOptions options ) => _underlyingHostUI . PromptForCredential ( caption , message , userName , targetName , allowedCredentialTypes , options ) ;
72
48
73
- public override PSCredential PromptForCredential ( string caption , string message , string userName , string targetName , PSCredentialTypes allowedCredentialTypes , PSCredentialUIOptions options )
74
- {
75
- if ( _consoleHostUI != null )
76
- {
77
- return _consoleHostUI . PromptForCredential ( caption , message , userName , targetName , allowedCredentialTypes , options ) ;
78
- }
79
-
80
- return _underlyingHostUI . PromptForCredential ( caption , message , userName , targetName , allowedCredentialTypes , options ) ;
81
- }
82
-
83
- public override PSCredential PromptForCredential ( string caption , string message , string userName , string targetName )
84
- {
85
- if ( _consoleHostUI is not null )
86
- {
87
- return _consoleHostUI . PromptForCredential ( caption , message , userName , targetName ) ;
88
- }
89
-
90
- return _underlyingHostUI . PromptForCredential ( caption , message , userName , targetName ) ;
91
- }
49
+ public override PSCredential PromptForCredential ( string caption , string message , string userName , string targetName ) => _underlyingHostUI . PromptForCredential ( caption , message , userName , targetName ) ;
92
50
93
51
public override string ReadLine ( ) => _readLineProvider . ReadLine . ReadLine ( CancellationToken . None ) ;
94
52
@@ -138,19 +96,5 @@ public void ResetProgress()
138
96
public override void WriteVerboseLine ( string message ) => _underlyingHostUI . WriteVerboseLine ( message ) ;
139
97
140
98
public override void WriteWarningLine ( string message ) => _underlyingHostUI . WriteWarningLine ( message ) ;
141
-
142
- private static PSHostUserInterface GetConsoleHostUI ( PSHostUserInterface ui )
143
- {
144
- FieldInfo externalUIField = ui . GetType ( ) . GetField ( "_externalUI" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
145
-
146
- if ( externalUIField is null )
147
- {
148
- return null ;
149
- }
150
-
151
- return ( PSHostUserInterface ) externalUIField . GetValue ( ui ) ;
152
- }
153
-
154
- private static void SetConsoleHostUIToInteractive ( PSHostUserInterface ui ) => ui . GetType ( ) . GetProperty ( "ThrowOnReadAndPrompt" , BindingFlags . NonPublic | BindingFlags . Instance ) ? . SetValue ( ui , false ) ;
155
99
}
156
100
}
0 commit comments