Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GetCursorPosition() plug #2128

Merged
merged 5 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Tests/Kernels/ConsoleTest/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public void TestVariousConsoleFunctions()
Console.WriteLine("Colored text :)");
Console.ResetColor();
Console.Write("Press enter to continue to the next step: "); Console.ReadLine();
Console.WriteLine("Press a key to move the cursor up");
Console.ReadKey();
var cursor = Console.GetCursorPosition();
Console.SetCursorPosition(cursor.Left, cursor.Top - 1);
}
}
}
15 changes: 11 additions & 4 deletions source/Cosmos.System2_Plugs/System/ConsoleImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Text;
using Cosmos.System;
using IL2CPU.API;
using IL2CPU.API.Attribs;

namespace Cosmos.System_Plugs.System
Expand Down Expand Up @@ -338,7 +337,7 @@ public static void Beep(int aFrequency, int aDuration)
/// Beep() is pure CIL
/// Default implementation beeps for 200 milliseconds at 800 hertz
/// In Cosmos, these are Cosmos.System.Duration.Default and Cosmos.System.Notes.Default respectively,
/// and are used when there are no params
/// and are used when there are no params
/// https://docs.microsoft.com/en-us/dotnet/api/system.console.beep?view=netcore-2.0
/// </summary>
public static void Beep()
Expand Down Expand Up @@ -421,11 +420,11 @@ public static ConsoleKeyInfo ReadKey(bool intercept)
}

//TODO: Plug HasFlag and use the next 3 lines instead of the 3 following lines

//bool xShift = key.Modifiers.HasFlag(ConsoleModifiers.Shift);
//bool xAlt = key.Modifiers.HasFlag(ConsoleModifiers.Alt);
//bool xControl = key.Modifiers.HasFlag(ConsoleModifiers.Control);

bool xShift = (key.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift;
bool xAlt = (key.Modifiers & ConsoleModifiers.Alt) == ConsoleModifiers.Alt;
bool xControl = (key.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control;
Expand Down Expand Up @@ -551,6 +550,14 @@ public static void SetCursorPosition(int left, int top)
set_CursorTop(top);
}

public static (int Left, int Top) GetCursorPosition()
{
int Left = get_CursorLeft();
int Top = get_CursorTop();

return (Left, Top);
}

//public static void SetError(TextWriter newError) {
// WriteLine("Not implemented: SetError");
//}
Expand Down