Skip to content

Commit 6473447

Browse files
committed
Handle multi-line input better with CancelLine
Like cmd, we leave the input visible, but I appended ^C (or whatever key was used to cancel) so there is a clue input was canceled. Multi-line input is preserved as well.
1 parent 52ba345 commit 6473447

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

PSReadLine/ReadLine.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,14 @@ public static void RevertLine(ConsoleKeyInfo? key = null, object arg = null)
575575
/// </summary>
576576
public static void CancelLine(ConsoleKeyInfo? key = null, object arg = null)
577577
{
578-
// Clear out the input so it doesn't get executed, but
579-
// don't call render so the screen is left alone.
580-
_singleton._buffer.Clear();
581-
AcceptLine();
578+
// Append the key that canceled input and display it so we have some visual
579+
// hint that the command didn't run.
580+
_singleton._current = _singleton._buffer.Length;
581+
_singleton._buffer.Append(key.HasValue ? key.Value.KeyChar : Keys.CtrlC.KeyChar);
582+
_singleton.Render();
583+
Console.Out.Write("\n");
584+
_singleton._buffer.Clear(); // Clear so we don't actually run the input
585+
_singleton._inputAccepted = true;
582586
}
583587

584588
/// <summary>

0 commit comments

Comments
 (0)