File tree Expand file tree Collapse file tree 2 files changed +24
-11
lines changed
src/Common/Commands.Common Expand file tree Collapse file tree 2 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -225,6 +225,28 @@ protected void SaveDataCollectionProfile()
225
225
WriteWarning ( string . Format ( Resources . DataCollectionSaveFileInformation , fileFullPath ) ) ;
226
226
}
227
227
228
+ protected bool CheckIfInteractive ( )
229
+ {
230
+ bool interactive = true ;
231
+ try
232
+ {
233
+ var test = this . Host . UI . RawUI . CursorSize ;
234
+ }
235
+ catch ( HostException ex )
236
+ {
237
+ if ( ex . Message . StartsWith ( "A command that prompts the user failed" ) )
238
+ {
239
+ interactive = false ;
240
+ }
241
+ else
242
+ {
243
+ throw ex ;
244
+ }
245
+ }
246
+
247
+ return interactive ;
248
+ }
249
+
228
250
/// <summary>
229
251
/// Prompt for the current data collection profile
230
252
/// </summary>
@@ -234,7 +256,7 @@ protected void PromptForDataCollectionProfileIfNotExists()
234
256
// Initialize it from the environment variable or profile file.
235
257
InitializeDataCollectionProfile ( ) ;
236
258
237
- if ( GeneralUtilities . CheckIfInteractive ( ) && ! _dataCollectionProfile . EnableAzureDataCollection . HasValue )
259
+ if ( CheckIfInteractive ( ) && ! _dataCollectionProfile . EnableAzureDataCollection . HasValue )
238
260
{
239
261
WriteWarning ( Resources . DataCollectionPrompt ) ;
240
262
@@ -259,7 +281,7 @@ protected void PromptForDataCollectionProfileIfNotExists()
259
281
bool enabled = false ;
260
282
if ( this . Host . UI . RawUI . KeyAvailable )
261
283
{
262
- KeyInfo keyInfo = this . Host . UI . RawUI . ReadKey ( ReadKeyOptions . NoEcho ) ;
284
+ KeyInfo keyInfo = this . Host . UI . RawUI . ReadKey ( ReadKeyOptions . NoEcho | ReadKeyOptions . AllowCtrlC | ReadKeyOptions . IncludeKeyDown ) ;
263
285
enabled = ( keyInfo . Character == 'Y' || keyInfo . Character == 'y' ) ;
264
286
}
265
287
Original file line number Diff line number Diff line change @@ -430,14 +430,5 @@ public static void EnsureDefaultProfileDirectoryExists()
430
430
AzureSession . DataStore . CreateDirectory ( AzureSession . ProfileDirectory ) ;
431
431
}
432
432
}
433
-
434
- /// <summary>
435
- /// Check if the PS program is run in interactive mode.
436
- /// </summary>
437
- public static bool CheckIfInteractive ( )
438
- {
439
- var arguments = Environment . GetCommandLineArgs ( ) ;
440
- return arguments . Any ( s => ! string . Equals ( s , "-noninteractive" ) ) ;
441
- }
442
433
}
443
434
}
You can’t perform that action at this time.
0 commit comments