CRT.Read/ReadLn procedures added

This commit is contained in:
Владислав Джавадов 2020-06-20 22:19:49 +03:00
parent 55bb2a8451
commit c44fe51b0b

View File

@ -14,6 +14,10 @@ type
X, Y: Integer; X, Y: Integer;
end; end;
TKey = record
CharCode, ScanCode: Byte;
end;
const const
Black = 0; Black = 0;
Blue = 1; Blue = 1;
@ -64,6 +68,10 @@ procedure WriteLn(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer = 1);
procedure WriteLn(const Str: ShortString; LineBreaks: Integer = 1); overload; procedure WriteLn(const Str: ShortString; LineBreaks: Integer = 1); overload;
function WriteLn(Format: PKolibriChar; const Args: array of const; LineBreaks: Integer = 1): Integer; overload; function WriteLn(Format: PKolibriChar; const Args: array of const; LineBreaks: Integer = 1): Integer; overload;
procedure Read(var Result: KolibriChar); overload;
procedure Read(var Result: TKey); overload;
procedure ReadLn(var Result: ShortString);
function CursorBig: Integer; function CursorBig: Integer;
function CursorHeight: Integer; overload; function CursorHeight: Integer; overload;
function CursorHeight(Height: Integer): Integer; overload; function CursorHeight(Height: Integer): Integer; overload;
@ -79,6 +87,9 @@ procedure Delay(Milliseconds: LongWord);
implementation implementation
uses
SysUtils;
var var
CloseWindow: Boolean; CloseWindow: Boolean;
@ -86,6 +97,9 @@ var
ClrScrProc: procedure; stdcall; ClrScrProc: procedure; stdcall;
ConsoleExit: procedure(CloseWindow: Boolean); stdcall; ConsoleExit: procedure(CloseWindow: Boolean); stdcall;
ConsoleInit: procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Caption: PKolibriChar); stdcall; ConsoleInit: procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Caption: PKolibriChar); stdcall;
GetCh: function: Integer; stdcall;
GetCh2: function: Word; stdcall;
GetS: function(Str: PKolibriChar; Length: Integer): PKolibriChar; stdcall;
GetCursorHeight: function: Integer; stdcall; GetCursorHeight: function: Integer; stdcall;
GetFlags: function: LongWord; stdcall; GetFlags: function: LongWord; stdcall;
GetFontHeight: function: Integer; stdcall; GetFontHeight: function: Integer; stdcall;
@ -107,6 +121,9 @@ begin
ClrScrProc := GetProcAddress(hConsole, 'con_cls'); ClrScrProc := GetProcAddress(hConsole, 'con_cls');
ConsoleExit := GetProcAddress(hConsole, 'con_exit'); ConsoleExit := GetProcAddress(hConsole, 'con_exit');
ConsoleInit := GetProcAddress(hConsole, 'con_init'); ConsoleInit := GetProcAddress(hConsole, 'con_init');
GetCh := GetProcAddress(hConsole, 'con_getch');
GetCh2 := GetProcAddress(hConsole, 'con_getch2');
GetS := GetProcAddress(hConsole, 'con_gets');
GetCursorHeight := GetProcAddress(hConsole, 'con_get_cursor_height'); GetCursorHeight := GetProcAddress(hConsole, 'con_get_cursor_height');
GetFlags := GetProcAddress(hConsole, 'con_get_flags'); GetFlags := GetProcAddress(hConsole, 'con_get_flags');
GetFontHeight := GetProcAddress(hConsole, 'con_get_font_height'); GetFontHeight := GetProcAddress(hConsole, 'con_get_font_height');
@ -293,6 +310,35 @@ begin
WriteLn(LineBreaks); WriteLn(LineBreaks);
end; end;
procedure Read(var Result: KolibriChar);
begin
Result := Chr(GetCh);
end;
procedure Read(var Result: TKey);
var
K: Word;
begin
K := GetCh2;
with WordRec(K), Result do
begin
CharCode := Lo;
ScanCode := Hi;
end;
end;
procedure ReadLn(var Result: ShortString);
var
P, Limit: PKolibriChar;
begin
P := PKolibriChar(@Result[1]);
GetS(P, High(Byte));
Limit := P + High(Byte);
while (P < Limit) and not (P^ in [#0, #10]) do
Inc(P);
PByte(@Result)^ := P - PKolibriChar(@Result[1]);
end;
function KeyPressed: Boolean; function KeyPressed: Boolean;
begin begin
Result := KeyPressedFunc; Result := KeyPressedFunc;