@@ -19,8 +19,9 @@ namespace Microsoft.PowerShell.EditorServices.Console
19
19
20
20
internal class ConsoleReadLine
21
21
{
22
- #region Private Fields
22
+ #region Private Field
23
23
24
+ private bool isUnix = false ;
24
25
private PowerShellContext powerShellContext ;
25
26
private AsyncQueue < ConsoleKeyInfo > readKeyQueue = new AsyncQueue < ConsoleKeyInfo > ( ) ;
26
27
@@ -31,6 +32,8 @@ internal class ConsoleReadLine
31
32
public ConsoleReadLine ( PowerShellContext powerShellContext )
32
33
{
33
34
this . powerShellContext = powerShellContext ;
35
+ // TODO: Change me?
36
+ this . isUnix = false ;
34
37
}
35
38
36
39
#endregion
@@ -186,11 +189,12 @@ private async Task<string> ReadLine(bool isCommandLine, CancellationToken cancel
186
189
inputBeforeCompletion = inputLine . ToString ( ) ;
187
190
inputAfterCompletion = null ;
188
191
189
- int cursorColumn =
190
- this . CalculateIndexFromCursor (
191
- promptStartCol ,
192
- promptStartRow ,
193
- consoleWidth ) ;
192
+ // int cursorColumn =
193
+ // this.CalculateIndexFromCursor(
194
+ // promptStartCol,
195
+ // promptStartRow,
196
+ // consoleWidth);
197
+ int cursorColumn = currentCursorIndex ;
194
198
195
199
// TODO: This logic should be moved to AstOperations or similar!
196
200
@@ -271,13 +275,27 @@ private async Task<string> ReadLine(bool isCommandLine, CancellationToken cancel
271
275
else if ( keyInfo . Key == ConsoleKey . Home )
272
276
{
273
277
currentCompletion = null ;
278
+ int oldCursorIndex = currentCursorIndex ;
274
279
currentCursorIndex = 0 ;
275
280
276
- this . MoveCursorToIndex (
277
- promptStartCol ,
278
- promptStartRow ,
279
- consoleWidth ,
280
- currentCursorIndex ) ;
281
+ if ( this . isUnix )
282
+ {
283
+ this . RenderInputLine (
284
+ inputLine ,
285
+ promptStartCol ,
286
+ promptStartRow ,
287
+ consoleWidth ,
288
+ oldCursorIndex ,
289
+ currentCursorIndex ) ;
290
+ }
291
+ else
292
+ {
293
+ this . MoveCursorToIndex (
294
+ promptStartCol ,
295
+ promptStartRow ,
296
+ consoleWidth ,
297
+ currentCursorIndex ) ;
298
+ }
281
299
}
282
300
else if ( keyInfo . Key == ConsoleKey . RightArrow )
283
301
{
@@ -607,6 +625,47 @@ private int InsertInput(
607
625
return finalCursorIndex != - 1 ? finalCursorIndex : inputLine . Length ;
608
626
}
609
627
628
+ private void RenderInputLine (
629
+ StringBuilder inputLine ,
630
+ int promptStartCol ,
631
+ int promptStartRow ,
632
+ int consoleWidth ,
633
+ int cursorIndex ,
634
+ int finalCursorIndex ,
635
+ int overrunCount = 5 )
636
+ {
637
+ this . CalculateCursorFromIndex (
638
+ promptStartCol ,
639
+ promptStartRow ,
640
+ consoleWidth ,
641
+ cursorIndex ,
642
+ out int newCol ,
643
+ out int newRow ) ;
644
+
645
+ Console . SetCursorPosition ( newCol , newRow ) ;
646
+
647
+ // Re-render affected section
648
+ Console . Write (
649
+ inputLine . ToString (
650
+ cursorIndex ,
651
+ inputLine . Length - cursorIndex ) ) ;
652
+
653
+ Console . Write (
654
+ new string (
655
+ ' ' ,
656
+ overrunCount ) ) ;
657
+
658
+ this . CalculateCursorFromIndex (
659
+ promptStartCol ,
660
+ promptStartRow ,
661
+ consoleWidth ,
662
+ finalCursorIndex ,
663
+ out newCol ,
664
+ out newRow ) ;
665
+
666
+ Console . SetCursorPosition ( newCol , newRow ) ;
667
+ }
668
+
610
669
private void MoveCursorToIndex (
611
670
int promptStartCol ,
612
671
int promptStartRow ,
0 commit comments