Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adds support for keys : Delete Home & End

  • Loading branch information...
commit 0d9966d2e2c1857ce8175414c3f8a01bd272a3bc 1 parent beac82a
Stephan authored
View
44 src/shell.me/ShellMe.CommandLine/Console/LowLevel/LowLevelToAbstractConsoleAdapter.cs
@@ -78,6 +78,23 @@ private ReadInfo Read()
OnBackspaceHit();
}
+ else if(keyInfo.Key == ConsoleKey.Delete)
+ {
+ if (_cursorController.IsEndOfInput())
+ return new ReadInfo { KeyInfo = keyInfo };
+
+ OnDeleteHit();
+ }
+ else if(keyInfo.Key == ConsoleKey.Home)
+ {
+ if(!_cursorController.IsStartOfInput())
+ _cursorController.MoveCursorToHome();
+ }
+ else if( keyInfo.Key == ConsoleKey.End)
+ {
+ if(!_cursorController.IsEndOfInput())
+ _cursorController.MoveCursorToEnd();
+ }
else if (keyInfo.Key == ConsoleKey.LeftArrow)
{
if (!_cursorController.IsStartOfInput())
@@ -125,6 +142,21 @@ private void OnBackspaceHit()
_cursorController.MoveLineMarkerBackward();
}
+ private void OnDeleteHit()
+ {
+ var textAfterInput = ReadFromCursorToEndOfInput();
+ _console.WriteAtCursorAndMove(' ');
+ _cursorController.MoveCursorBackward();
+ var returnPoint = _cursorController.CreateCursorReturnPoint();
+
+ returnPoint();
+ Write(textAfterInput
+ .Skip(1), false);
+
+ returnPoint();
+ _cursorController.MoveLineMarkerForward();
+ }
+
public override ConsoleColor ForegroundColor
{
get { return _console.ForegroundColor; }
@@ -285,6 +317,18 @@ public void MoveCursorToStartOfNewLine()
_lineEnd.CursorTop = _console.CursorTop;
}
+ public void MoveCursorToHome()
+ {
+ _console.CursorTop = _lineStart.CursorTop;
+ _console.CursorLeft = _lineStart.CursorLeft;
+ }
+
+ public void MoveCursorToEnd()
+ {
+ _console.CursorTop = _lineEnd.CursorTop;
+ _console.CursorLeft = _lineEnd.CursorLeft;
+ }
+
public bool IsStartOfInput()
{
return _console.CursorLeft == _lineStart.CursorLeft && _console.CursorTop == _lineStart.CursorTop;
Please sign in to comment.
Something went wrong with that request. Please try again.