mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Implement Console.Clear
This commit is contained in:
parent
9ac84e12e9
commit
d162718c54
1 changed files with 58 additions and 3 deletions
|
@ -51,6 +51,11 @@ namespace System
|
||||||
public uint16[2] mMaximumWindowSize;
|
public uint16[2] mMaximumWindowSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[CRepr]
|
||||||
|
struct COORD : this(int16 X, int16 Y)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public static ref Event<delegate void (CancelKind cancelKind, ref bool terminate)> OnCancel
|
public static ref Event<delegate void (CancelKind cancelKind, ref bool terminate)> OnCancel
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -77,19 +82,26 @@ namespace System
|
||||||
}
|
}
|
||||||
|
|
||||||
[CLink, CallingConvention(.Stdcall)]
|
[CLink, CallingConvention(.Stdcall)]
|
||||||
static extern int SetConsoleTextAttribute(void* hConsoleOutput, uint16 wAttributes);
|
static extern Windows.IntBool SetConsoleTextAttribute(Windows.Handle hConsoleOutput, uint16 wAttributes);
|
||||||
|
|
||||||
[CLink, CallingConvention(.Stdcall)]
|
[CLink, CallingConvention(.Stdcall)]
|
||||||
static extern int GetConsoleScreenBufferInfo(void* hConsoleOutput, out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
|
static extern Windows.IntBool GetConsoleScreenBufferInfo(Windows.Handle hConsoleOutput, out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
|
||||||
|
|
||||||
[CLink, CallingConvention(.Stdcall)]
|
[CLink, CallingConvention(.Stdcall)]
|
||||||
static extern void* GetStdHandle(uint32 nStdHandle);
|
static extern Windows.Handle GetStdHandle(uint32 nStdHandle);
|
||||||
|
|
||||||
[CallingConvention(.Stdcall)]
|
[CallingConvention(.Stdcall)]
|
||||||
function Windows.IntBool ConsoleCtrlHandler(int32 ctrlType);
|
function Windows.IntBool ConsoleCtrlHandler(int32 ctrlType);
|
||||||
[CLink, CallingConvention(.Stdcall)]
|
[CLink, CallingConvention(.Stdcall)]
|
||||||
static extern Windows.IntBool SetConsoleCtrlHandler(ConsoleCtrlHandler handler, Windows.IntBool addHandler);
|
static extern Windows.IntBool SetConsoleCtrlHandler(ConsoleCtrlHandler handler, Windows.IntBool addHandler);
|
||||||
|
|
||||||
|
[CLink, CallingConvention(.Stdcall)]
|
||||||
|
static extern Windows.IntBool FillConsoleOutputCharacterW(Windows.Handle hConsoleOutput, char16 cCharacter, uint32 nLength, COORD dwWriteCoord, uint32* lpNumberOfCharsWritten);
|
||||||
|
[CLink, CallingConvention(.Stdcall)]
|
||||||
|
static extern Windows.IntBool FillConsoleOutputAttribute(Windows.Handle hConsoleOutput, uint16 wAttribute, uint32 nLength, COORD dwWriteCoord, uint32* lpNumberOfAttrsWritten);
|
||||||
|
[CLink, CallingConvention(.Stdcall)]
|
||||||
|
static extern Windows.IntBool SetConsoleCursorPosition(Windows.Handle hConsoleOutput, COORD dwCursorPosition);
|
||||||
|
|
||||||
public static this()
|
public static this()
|
||||||
{
|
{
|
||||||
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
@ -257,6 +269,49 @@ namespace System
|
||||||
#else
|
#else
|
||||||
Write("\x1B[{}m", ForegroundColor.AnsiCode);
|
Write("\x1B[{}m", ForegroundColor.AnsiCode);
|
||||||
Write("\x1B[{}m", BackgroundColor.AnsiCode + 10);
|
Write("\x1B[{}m", BackgroundColor.AnsiCode + 10);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Clear()
|
||||||
|
{
|
||||||
|
#if BF_PLATFORM_WINDOWS
|
||||||
|
Windows.Handle hStdOut;
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
|
uint32 count;
|
||||||
|
uint32 cellCount;
|
||||||
|
COORD homeCoords = .(0, 0);
|
||||||
|
|
||||||
|
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
|
||||||
|
if (hStdOut == .InvalidHandle)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Get the number of cells in the current buffer */
|
||||||
|
if (!GetConsoleScreenBufferInfo( hStdOut, out csbi ))
|
||||||
|
return;
|
||||||
|
cellCount = csbi.mSize[0] * csbi.mSize[1];
|
||||||
|
|
||||||
|
/* Fill the entire buffer with spaces */
|
||||||
|
if (!FillConsoleOutputCharacterW(
|
||||||
|
hStdOut,
|
||||||
|
' ',
|
||||||
|
cellCount,
|
||||||
|
homeCoords,
|
||||||
|
&count
|
||||||
|
)) return;
|
||||||
|
|
||||||
|
/* Fill the entire buffer with the current colors and attributes */
|
||||||
|
if (!FillConsoleOutputAttribute(
|
||||||
|
hStdOut,
|
||||||
|
csbi.mAttributes,
|
||||||
|
cellCount,
|
||||||
|
homeCoords,
|
||||||
|
&count
|
||||||
|
)) return;
|
||||||
|
|
||||||
|
/* Move the cursor home */
|
||||||
|
SetConsoleCursorPosition( hStdOut, homeCoords );
|
||||||
|
#else
|
||||||
|
Write("\x1B[H\x1B[J");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue