@@ -1212,7 +1212,7 @@ private void SetExecutionPolicy(ExecutionPolicy desiredExecutionPolicy)
1212
1212
}
1213
1213
}
1214
1214
1215
- private void WritePromptToHost ( Func < PSCommand , string > invokeAction )
1215
+ private string GetPromptString ( Func < PSCommand , string > invokeAction )
1216
1216
{
1217
1217
string promptString = null ;
1218
1218
@@ -1228,26 +1228,42 @@ private void WritePromptToHost(Func<PSCommand, string> invokeAction)
1228
1228
LogLevel . Verbose ,
1229
1229
"Runtime exception occurred while executing prompt command:\r \n \r \n " + e . ToString ( ) ) ;
1230
1230
}
1231
+ catch ( InvalidCastException e )
1232
+ {
1233
+ Logger . WriteException (
1234
+ LogLevel . Verbose ,
1235
+ "Prompt function returned a result which is not a string." ,
1236
+ e ) ;
1237
+ }
1231
1238
finally
1232
1239
{
1233
- promptString = promptString ?? "PS >" ;
1240
+ promptString = promptString ?? "PS>" ;
1234
1241
}
1235
1242
1236
- this . WriteOutput (
1237
- Environment . NewLine ,
1238
- false ) ;
1239
-
1240
1243
// Trim the '>' off the end of the prompt string to reduce
1241
1244
// user confusion about where they can type.
1242
1245
// TODO: Eventually put this behind a setting, #133
1243
- promptString = promptString . TrimEnd ( ' ' , '>' , '\r ' , '\n ' ) ;
1246
+ return promptString . TrimEnd ( ' ' , '>' , '\r ' , '\n ' ) ;
1247
+ }
1248
+
1249
+ private void WritePromptStringToHost ( string promptString )
1250
+ {
1251
+ this . WriteOutput (
1252
+ Environment . NewLine ,
1253
+ false ) ;
1244
1254
1245
1255
// Write the prompt string
1246
1256
this . WriteOutput (
1247
1257
promptString ,
1248
1258
true ) ;
1249
1259
}
1250
1260
1261
+ private void WritePromptToHost ( Func < PSCommand , string > invokeAction )
1262
+ {
1263
+ this . WritePromptStringToHost (
1264
+ this . GetPromptString ( invokeAction ) ) ;
1265
+ }
1266
+
1251
1267
private void WritePromptWithRunspace ( Runspace runspace )
1252
1268
{
1253
1269
this . WritePromptToHost (
@@ -1275,9 +1291,9 @@ private void WritePromptWithRunspace(Runspace runspace)
1275
1291
} ) ;
1276
1292
}
1277
1293
1278
- private void WritePromptInDebugger ( )
1294
+ private string GetPromptInDebugger ( )
1279
1295
{
1280
- this . WritePromptToHost (
1296
+ return this . GetPromptString (
1281
1297
command =>
1282
1298
{
1283
1299
return
@@ -1286,6 +1302,46 @@ private void WritePromptInDebugger()
1286
1302
} ) ;
1287
1303
}
1288
1304
1305
+ private void WritePromptInDebugger ( DebuggerStopEventArgs eventArgs = null )
1306
+ {
1307
+ string promptPrefix = string . Empty ;
1308
+ string promptString = this . GetPromptInDebugger ( ) ;
1309
+
1310
+ if ( eventArgs != null )
1311
+ {
1312
+ // Is there a prompt prefix worth keeping?
1313
+ const string promptSeparator = "]: " ;
1314
+ if ( promptString != null && promptString [ 0 ] == ( '[' ) )
1315
+ {
1316
+ int separatorIndex = promptString . LastIndexOf ( promptSeparator ) ;
1317
+ if ( separatorIndex > 0 )
1318
+ {
1319
+ promptPrefix =
1320
+ promptString . Substring (
1321
+ 0 ,
1322
+ separatorIndex + promptSeparator . Length ) ;
1323
+ }
1324
+ }
1325
+
1326
+ // This was called from OnDebuggerStop, write a different prompt
1327
+ if ( eventArgs . Breakpoints . Count > 0 )
1328
+ {
1329
+ // The breakpoint classes have nice ToString output so use that
1330
+ promptString = $ "Hit { eventArgs . Breakpoints [ 0 ] . ToString ( ) } ";
1331
+ }
1332
+ else
1333
+ {
1334
+ // TODO: What do we display when we don't know why we stopped?
1335
+ promptString = null ;
1336
+ }
1337
+ }
1338
+
1339
+ if ( promptString != null )
1340
+ {
1341
+ this . WritePromptStringToHost ( promptPrefix + promptString ) ;
1342
+ }
1343
+ }
1344
+
1289
1345
private void WritePromptWithNestedPipeline ( )
1290
1346
{
1291
1347
using ( var pipeline = this . CurrentRunspace . Runspace . CreateNestedPipeline ( ) )
@@ -1418,7 +1474,7 @@ private void OnDebuggerStop(object sender, DebuggerStopEventArgs e)
1418
1474
}
1419
1475
1420
1476
// Write out the debugger prompt
1421
- this . WritePromptInDebugger ( ) ;
1477
+ this . WritePromptInDebugger ( e ) ;
1422
1478
1423
1479
// Raise the event for the debugger service
1424
1480
this . DebuggerStop ? . Invoke ( sender , e ) ;
0 commit comments