From cefc8dff59b72f3ff55f34dead19bf0eb4e2a923 Mon Sep 17 00:00:00 2001 From: j vh Date: Wed, 25 Jan 2023 14:46:30 +0100 Subject: [PATCH 1/2] added GetCursorPosition --- BeefLibs/corlib/src/Console.bf | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/BeefLibs/corlib/src/Console.bf b/BeefLibs/corlib/src/Console.bf index 7d93868a..a5856818 100644 --- a/BeefLibs/corlib/src/Console.bf +++ b/BeefLibs/corlib/src/Console.bf @@ -127,6 +127,17 @@ namespace System } SetConsoleOutputCP(/*CP_UTF8*/65001); } + + public static uint16[2] GetConsoleCursorPosition() + { + let handle = GetStdHandle(STD_OUTPUT_HANDLE); + CONSOLE_SCREEN_BUFFER_INFO consoleInfo = .(); + if (GetConsoleScreenBufferInfo(handle, out consoleInfo) != 0) + { + return consoleInfo.mCursorPosition; + } + return uint16[2](0,0); + } #endif static StreamWriter OpenStreamWriter(Platform.BfpFileStdKind stdKind, ref StreamWriter outStreamWriter) From b2d1d98f1a92b14fd2bed6fc52c551e93329684f Mon Sep 17 00:00:00 2001 From: j vh Date: Wed, 25 Jan 2023 15:30:42 +0100 Subject: [PATCH 2/2] added console left and top properties --- BeefLibs/corlib/BeefSpace.toml | 5 ---- BeefLibs/corlib/src/Console.bf | 44 +++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 13 deletions(-) delete mode 100644 BeefLibs/corlib/BeefSpace.toml diff --git a/BeefLibs/corlib/BeefSpace.toml b/BeefLibs/corlib/BeefSpace.toml deleted file mode 100644 index dae97147..00000000 --- a/BeefLibs/corlib/BeefSpace.toml +++ /dev/null @@ -1,5 +0,0 @@ -FileVersion = 1 -Projects = {corlib = {Path = "."}} - -[Workspace] -StartupProject = "corlib" diff --git a/BeefLibs/corlib/src/Console.bf b/BeefLibs/corlib/src/Console.bf index a5856818..6e895987 100644 --- a/BeefLibs/corlib/src/Console.bf +++ b/BeefLibs/corlib/src/Console.bf @@ -127,16 +127,44 @@ namespace System } SetConsoleOutputCP(/*CP_UTF8*/65001); } - - public static uint16[2] GetConsoleCursorPosition() - { - let handle = GetStdHandle(STD_OUTPUT_HANDLE); - CONSOLE_SCREEN_BUFFER_INFO consoleInfo = .(); - if (GetConsoleScreenBufferInfo(handle, out consoleInfo) != 0) + + public static int32 CursorTop + { + public get { - return consoleInfo.mCursorPosition; + let handle = GetStdHandle(STD_OUTPUT_HANDLE); + CONSOLE_SCREEN_BUFFER_INFO consoleInfo = .(); + GetConsoleScreenBufferInfo(handle,out consoleInfo); + return consoleInfo.mCursorPosition[1]; //1 = y position + } + public set + { + //This has to be done afaik to ensure x stays the same + let handle = GetStdHandle(STD_OUTPUT_HANDLE); + CONSOLE_SCREEN_BUFFER_INFO consoleInfo = .(); + GetConsoleScreenBufferInfo(handle,out consoleInfo); + + SetConsoleCursorPosition(handle, COORD((.)consoleInfo.mCursorPosition[0], (.)value)); + } + } + public static int32 CursorLeft + { + public get + { + let handle = GetStdHandle(STD_OUTPUT_HANDLE); + CONSOLE_SCREEN_BUFFER_INFO consoleInfo = .(); + GetConsoleScreenBufferInfo(handle,out consoleInfo); + return consoleInfo.mCursorPosition[0]; //1 = y position + } + public set + { + //This has to be done afaik to ensure x stays the same + let handle = GetStdHandle(STD_OUTPUT_HANDLE); + CONSOLE_SCREEN_BUFFER_INFO consoleInfo = .(); + GetConsoleScreenBufferInfo(handle,out consoleInfo); + + SetConsoleCursorPosition(handle, COORD((.)value,(.)consoleInfo.mCursorPosition[0])); } - return uint16[2](0,0); } #endif