2020-05-25 22:48:33 +02:00
|
|
|
(*
|
|
|
|
BSD 2-Clause License
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
Copyright (c) 2019-2020, Anton Krotov
|
2020-05-25 22:48:33 +02:00
|
|
|
All rights reserved.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE Console;
|
|
|
|
|
|
|
|
IMPORT SYSTEM, WINAPI, In, Out;
|
|
|
|
|
|
|
|
|
|
|
|
CONST
|
|
|
|
|
|
|
|
Black* = 0; Blue* = 1; Green* = 2; Cyan* = 3;
|
|
|
|
Red* = 4; Magenta* = 5; Brown* = 6; LightGray* = 7;
|
|
|
|
DarkGray* = 8; LightBlue* = 9; LightGreen* = 10; LightCyan* = 11;
|
|
|
|
LightRed* = 12; LightMagenta* = 13; Yellow* = 14; White* = 15;
|
|
|
|
|
|
|
|
|
|
|
|
VAR
|
|
|
|
|
|
|
|
hConsoleOutput: INTEGER;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE SetCursor* (X, Y: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
WINAPI.SetConsoleCursorPosition(hConsoleOutput, X + Y * 65536)
|
|
|
|
END SetCursor;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE GetCursor* (VAR X, Y: INTEGER);
|
|
|
|
VAR
|
|
|
|
ScrBufInfo: WINAPI.TConsoleScreenBufferInfo;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
WINAPI.GetConsoleScreenBufferInfo(hConsoleOutput, ScrBufInfo);
|
|
|
|
X := ORD(ScrBufInfo.dwCursorPosition.X);
|
|
|
|
Y := ORD(ScrBufInfo.dwCursorPosition.Y)
|
|
|
|
END GetCursor;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Cls*;
|
|
|
|
VAR
|
|
|
|
fill: INTEGER;
|
|
|
|
ScrBufInfo: WINAPI.TConsoleScreenBufferInfo;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
WINAPI.GetConsoleScreenBufferInfo(hConsoleOutput, ScrBufInfo);
|
|
|
|
fill := ORD(ScrBufInfo.dwSize.X) * ORD(ScrBufInfo.dwSize.Y);
|
2020-10-13 09:58:51 +02:00
|
|
|
WINAPI.FillConsoleOutputCharacterA(hConsoleOutput, 20H, fill, 0, SYSTEM.ADR(fill));
|
2020-05-25 22:48:33 +02:00
|
|
|
WINAPI.FillConsoleOutputAttribute(hConsoleOutput, ORD(ScrBufInfo.wAttributes), fill, 0, SYSTEM.ADR(fill));
|
|
|
|
SetCursor(0, 0)
|
|
|
|
END Cls;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE SetColor* (FColor, BColor: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
IF (FColor IN {0..15}) & (BColor IN {0..15}) THEN
|
|
|
|
WINAPI.SetConsoleTextAttribute(hConsoleOutput, LSL(BColor, 4) + FColor)
|
|
|
|
END
|
|
|
|
END SetColor;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE GetCursorX* (): INTEGER;
|
|
|
|
VAR
|
|
|
|
ScrBufInfo: WINAPI.TConsoleScreenBufferInfo;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
WINAPI.GetConsoleScreenBufferInfo(hConsoleOutput, ScrBufInfo)
|
|
|
|
RETURN ORD(ScrBufInfo.dwCursorPosition.X)
|
|
|
|
END GetCursorX;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE GetCursorY* (): INTEGER;
|
|
|
|
VAR
|
|
|
|
ScrBufInfo: WINAPI.TConsoleScreenBufferInfo;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
WINAPI.GetConsoleScreenBufferInfo(hConsoleOutput, ScrBufInfo)
|
|
|
|
RETURN ORD(ScrBufInfo.dwCursorPosition.Y)
|
|
|
|
END GetCursorY;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE open*;
|
|
|
|
BEGIN
|
|
|
|
WINAPI.AllocConsole;
|
|
|
|
hConsoleOutput := WINAPI.GetStdHandle(-11);
|
|
|
|
In.Open;
|
|
|
|
Out.Open
|
|
|
|
END open;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE exit* (b: BOOLEAN);
|
|
|
|
BEGIN
|
|
|
|
WINAPI.FreeConsole
|
|
|
|
END exit;
|
|
|
|
|
|
|
|
|
|
|
|
END Console.
|