1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- using Microsoft . Extensions . Logging ;
5
- using Microsoft . PowerShell . EditorServices . Services . PowerShell . Console ;
6
4
using System ;
7
5
using System . Collections . Generic ;
8
6
using System . Collections . ObjectModel ;
11
9
using System . Reflection ;
12
10
using System . Security ;
13
11
using System . Threading ;
12
+ using Microsoft . Extensions . Logging ;
13
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Console ;
14
14
15
15
namespace Microsoft . PowerShell . EditorServices . Services . PowerShell . Host
16
16
{
17
17
internal class EditorServicesConsolePSHostUserInterface : PSHostUserInterface
18
18
{
19
- private readonly ILogger _logger ;
20
-
21
19
private readonly IReadLineProvider _readLineProvider ;
22
20
23
21
private readonly PSHostUserInterface _underlyingHostUI ;
@@ -29,22 +27,22 @@ public EditorServicesConsolePSHostUserInterface(
29
27
IReadLineProvider readLineProvider ,
30
28
PSHostUserInterface underlyingHostUI )
31
29
{
32
- _logger = loggerFactory . CreateLogger < EditorServicesConsolePSHostUserInterface > ( ) ;
33
30
_readLineProvider = readLineProvider ;
34
31
_underlyingHostUI = underlyingHostUI ;
35
32
RawUI = new EditorServicesConsolePSHostRawUserInterface ( loggerFactory , underlyingHostUI . RawUI ) ;
36
33
37
34
_consoleHostUI = GetConsoleHostUI ( _underlyingHostUI ) ;
35
+
38
36
if ( _consoleHostUI != null )
39
37
{
40
38
SetConsoleHostUIToInteractive ( _consoleHostUI ) ;
41
39
}
42
40
}
43
41
44
- public override PSHostRawUserInterface RawUI { get ; }
45
-
46
42
public override bool SupportsVirtualTerminal => _underlyingHostUI . SupportsVirtualTerminal ;
47
43
44
+ public override PSHostRawUserInterface RawUI { get ; }
45
+
48
46
public override Dictionary < string , PSObject > Prompt ( string caption , string message , Collection < FieldDescription > descriptions )
49
47
{
50
48
if ( _consoleHostUI != null )
@@ -77,66 +75,45 @@ public override PSCredential PromptForCredential(string caption, string message,
77
75
78
76
public override PSCredential PromptForCredential ( string caption , string message , string userName , string targetName )
79
77
{
80
- if ( _consoleHostUI != null )
78
+ if ( _consoleHostUI is not null )
81
79
{
82
80
return _consoleHostUI . PromptForCredential ( caption , message , userName , targetName ) ;
83
81
}
84
82
85
83
return _underlyingHostUI . PromptForCredential ( caption , message , userName , targetName ) ;
86
84
}
87
85
88
- public override string ReadLine ( )
89
- {
90
- return _readLineProvider . ReadLine . ReadLine ( CancellationToken . None ) ;
91
- }
86
+ public override string ReadLine ( ) => _readLineProvider . ReadLine . ReadLine ( CancellationToken . None ) ;
92
87
93
- public override SecureString ReadLineAsSecureString ( )
94
- {
95
- return _readLineProvider . ReadLine . ReadSecureLine ( CancellationToken . None ) ;
96
- }
88
+ public override SecureString ReadLineAsSecureString ( ) => _readLineProvider . ReadLine . ReadSecureLine ( CancellationToken . None ) ;
97
89
98
- public override void Write ( ConsoleColor foregroundColor , ConsoleColor backgroundColor , string value )
99
- {
100
- _underlyingHostUI . Write ( foregroundColor , backgroundColor , value ) ;
101
- }
90
+ public override void Write ( ConsoleColor foregroundColor , ConsoleColor backgroundColor , string value ) => _underlyingHostUI . Write ( foregroundColor , backgroundColor , value ) ;
102
91
103
- public override void Write ( string value )
104
- {
105
- _underlyingHostUI . Write ( value ) ;
106
- }
92
+ public override void Write ( string value ) => _underlyingHostUI . Write ( value ) ;
107
93
108
- public override void WriteDebugLine ( string message )
109
- {
110
- _underlyingHostUI . WriteDebugLine ( message ) ;
111
- }
94
+ public override void WriteDebugLine ( string message ) => _underlyingHostUI . WriteDebugLine ( message ) ;
112
95
113
- public override void WriteErrorLine ( string value )
114
- {
115
- _underlyingHostUI . WriteErrorLine ( value ) ;
116
- }
96
+ public override void WriteErrorLine ( string value ) => _underlyingHostUI . WriteErrorLine ( value ) ;
117
97
118
- public override void WriteLine ( string value )
119
- {
120
- _underlyingHostUI . WriteLine ( value ) ;
121
- }
98
+ public override void WriteInformation ( InformationRecord record ) => _underlyingHostUI . WriteInformation ( record ) ;
99
+
100
+ public override void WriteLine ( ) => _underlyingHostUI . WriteLine ( ) ;
101
+
102
+ public override void WriteLine ( ConsoleColor foregroundColor , ConsoleColor backgroundColor , string value ) => _underlyingHostUI . WriteLine ( foregroundColor , backgroundColor , value ) ;
103
+
104
+ public override void WriteLine ( string value ) => _underlyingHostUI . WriteLine ( value ) ;
122
105
123
106
public override void WriteProgress ( long sourceId , ProgressRecord record ) => _underlyingHostUI . WriteProgress ( sourceId , record ) ;
124
107
125
- public override void WriteVerboseLine ( string message )
126
- {
127
- _underlyingHostUI . WriteVerboseLine ( message ) ;
128
- }
108
+ public override void WriteVerboseLine ( string message ) => _underlyingHostUI . WriteVerboseLine ( message ) ;
129
109
130
- public override void WriteWarningLine ( string message )
131
- {
132
- _underlyingHostUI . WriteWarningLine ( message ) ;
133
- }
110
+ public override void WriteWarningLine ( string message ) => _underlyingHostUI . WriteWarningLine ( message ) ;
134
111
135
112
private static PSHostUserInterface GetConsoleHostUI ( PSHostUserInterface ui )
136
113
{
137
114
FieldInfo externalUIField = ui . GetType ( ) . GetField ( "_externalUI" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
138
115
139
- if ( externalUIField == null )
116
+ if ( externalUIField is null )
140
117
{
141
118
return null ;
142
119
}
0 commit comments