2,6 → 2,7 |
|
procedure OpenStdout(var f: TextRec); forward; |
procedure WriteStdout(var f: TextRec); forward; |
procedure FlushStdout(var f: TextRec); forward; |
procedure CloseStdout(var f: TextRec); forward; |
|
procedure OpenStdin(var f: TextRec); forward; |
20,7 → 21,7 |
procedure OpenStdout(var f: TextRec); |
begin |
TextRec(f).InOutFunc := @WriteStdout; |
TextRec(f).FlushFunc := @WriteStdout; |
TextRec(f).FlushFunc := @FlushStdout; |
TextRec(f).CloseFunc := @CloseStdout; |
end; |
|
34,6 → 35,12 |
Konsole.Write(msg); |
end; |
|
procedure FlushStdout(var f: TextRec); |
begin |
WriteStdout(f); |
Konsole.Flush; |
end; |
|
procedure CloseStdout(var f: TextRec); |
begin |
end; |
114,6 → 121,7 |
while not Console^.FTerminate do |
begin |
Event := kos_getevent(); |
Console^.FOnAir := True; |
if not Console^.FTerminate then |
case Event of |
SE_PAINT: Console^.Paint(); |
120,6 → 128,7 |
SE_KEYBOARD: Console^.ProcessKeyboard(kos_getkey()); |
SE_IPC: while Console^.ReceiveMessage(Message) do Console^.ProcessMessage(Message); |
end; |
Console^.FOnAir := False; |
end; |
Console^.FOpened := False; |
end; |
143,6 → 152,7 |
FMaxLines := 150; |
FTerminate := False; |
FOpened := False; |
FOnAir := False; |
FIPCBufferSize := SizeOf(TKosIPC) + IPC_SIZE; |
FIPCBuffer := GetMem(FIPCBufferSize); |
FIPCBuffer^.Lock := False; |
151,7 → 161,6 |
FThreadID := BeginThread(TThreadFunc(@KonsoleThreadMain), @Self); |
if FThreadID <> 0 then |
{XXX: ¬®¦¥â § ¢¨áãâì} |
{®, â ª ¨ ¥áâì ¢ 2.2.0.} |
while not FOpened do ThreadSwitch; |
end; |
|
164,10 → 173,11 |
if FOpened then |
begin |
FOpened := False; |
FOnAir := False; |
KillThread(FThreadID); |
end; |
FreeMem(FIPCBuffer); |
SetLength(FLines, 0); |
{FreeMem(FIPCBuffer); |
SetLength(FLines, 0);} |
end; |
|
function TKonsole.ReceiveMessage(var Message: ShortString): Boolean; |
176,9 → 186,10 |
PMsg: PKosMessage; |
Size: Longword; |
begin |
FIPCBuffer^.Lock := True; |
|
if FIPCBuffer^.Size > 0 then |
begin |
FIPCBuffer^.Lock := True; |
PMsg := Pointer(Longword(FIPCBuffer) + SizeOf(TKosIPC)); |
{TODO: ¯à®¢¥àª PMsg^.SenderID} |
{Size := PMsg^.Size; |
210,38 → 221,25 |
procedure TKonsole.ProcessMessage(Message: ShortString); |
{뢥á⨠ᮮ¡é¥¨¥ ª®á®«ì} |
var |
S: String; |
LinesCount: Word; |
CR, LF, W: Word; |
BottomRow: Boolean = True; |
begin |
if Length(Message) < 1 then Exit; |
OnlyBottomLine: Boolean = True; |
|
repeat |
CR := Pos(#13, Message); |
LF := Pos(#10, Message); |
if (CR > 0) and ((CR < LF) or (LF <= 0)) then |
W := CR else |
if LF > 0 then |
W := LF else |
W := Length(Message) + 1; |
if W > 0 then |
procedure PutChar(C: Char); |
var |
LinesCount: Longint; |
PLine: PShortString; |
I: Longint; |
begin |
if W > 1 then |
{ ¯¥à¥¢®¤ ª®à¥âª¨ ¯®§¨æ¨î ¢«¥¢® } |
if C = #8 then |
begin |
S := Copy(Message, 1, W - 1); |
Delete(FLines[FCursor.Y], FCursor.X, Length(FLines[FCursor.Y]) - FCursor.X); |
Insert(S, FLines[FCursor.Y], FCursor.X); |
Inc(FCursor.X, Length(S)); |
end; |
Delete(Message, 1, W); |
if W = CR then |
{¯¥à¥¢®¤ ª®à¥âª¨ ¢ ç «® áâப¨} |
FCursor.X := 1 else |
if W = LF then |
if FCursor.X > 1 then |
Dec(FCursor.X); |
end else |
|
{ ¯¥à¥¢®¤ ª®à¥âª¨ á«¥¤ãîéãî áâபã } |
if C = #10 then |
begin |
{¯¥à¥¢®¤ ª®à¥âª¨ á«¥¤ãîéãî áâபã} |
BottomRow := False; |
OnlyBottomLine := False; |
Inc(FCursor.Y); |
LinesCount := Length(FLines); |
while FCursor.Y >= FMaxLines do Dec(FCursor.Y, FMaxLines); |
252,13 → 250,48 |
FLines[LinesCount] := ''; |
Inc(LinesCount); |
end; |
end else |
|
{ ¯¥à¥¢®¤ ª®à¥âª¨ ¢ ç «® áâப¨ } |
if C = #13 then |
FCursor.X := 1 else |
|
{ ¯®¬¥é¥¨¥ ᨬ¢®« ¢ áâபã } |
begin |
if FCursor.X > 200 then |
begin |
PutChar(#13); |
PutChar(#10); |
end; |
|
{ FIXME:
᫨ ¢ PascalMain ⮫쪮 ®¤¨ Write/Ln, â® § ¢¨á®. |
á¬. FPC_DO_EXIT, InternalExit } |
PLine := @FLines[FCursor.Y]; |
I := Length(PLine^); |
if FCursor.X > I then |
begin |
SetLength(PLine^, FCursor.X); |
Inc(I); |
while I < FCursor.X do |
begin |
PLine^[I] := ' '; |
Inc(I); |
end; |
until Length(Message) <= 0; |
end; |
FLines[FCursor.Y][FCursor.X] := C; |
|
Paint(BottomRow); |
Inc(FCursor.X); |
end; |
end; |
|
var |
I: Longint; |
begin |
for I := 1 to Length(Message) do |
PutChar(Message[I]); |
Paint(OnlyBottomLine); |
end; |
|
procedure TKonsole.ProcessKeyboard(Key: Word); |
begin |
FKeyPressed := Key; |
351,3 → 384,8 |
end; |
end; |
end; |
|
procedure TKonsole.Flush(); |
begin |
while FOnAir do ThreadSwitch; |
end; |