Skip to content

Loading…

adds support for keys : Delete Home & End #12

Merged
merged 1 commit into from

2 participants

@straeger

No description provided.

@cburgdorf
dff solutions GmbH member

Great contribution! I just merged your changes. I just had to fix a minor issue with the DELETEkey. The line actually wasn't trunkated to the right when hitting the DELETE key. You always need to keep the line marker in sync. Otherwise the cursor can move more to the right than it should be allowed to.

Would you mind writing tests for those three keys?

@cburgdorf cburgdorf merged commit 0d9966d into dff-solutions:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 30, 2012
  1. adds support for keys : Delete Home & End

    Stephan committed
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;
Something went wrong with that request. Please try again.