[fpc-pascal] terminal width/height

miller at psy.otago.ac.nz miller at psy.otago.ac.nz
Sat May 14 05:34:28 CEST 2005


Quoting David Emerson <dle3ab at angelbase.com>:
> Is there a function to query the terminal width and height, as a number of
> characters?

If you "use CRT", you can make use of gotoxy() and WhereX plus WhereY
to find out.  Below is a unit I sometimes use for this purpose.

Hope this helps,

Unit UWinSize;

{
This unit determines the size of a text window.
Just include it, and the variables will be set automatically.
}

Interface

Uses CRT;

Var ScreenMaxX, ScreenMaxY : Integer;

Procedure SetScreenMax;

Implementation

Var Current, Increment : Integer;

Function Biggest(UseX : Boolean) : Integer;
Var Done : Boolean;
Begin
Repeat
   If UseX Then Begin
      GotoXY(Current,1);
      Done:= Current <> WhereX;
      End
    Else Begin
      GotoXY(1,Current);
      Done:= Current <> WhereY;
      End;
   If Not Done Then Current := Current + Increment;
 Until Done;
Biggest := Current - Increment;
End;

Procedure SetScreenMax;
Begin
Current := 10;
Increment := 10;
Current := Biggest(True);
Increment := 1;
ScreenMaxX := Biggest(True);
Current := 10;
Increment := 10;
Current := Biggest(False);
Increment := 1;
ScreenMaxY := Biggest(False);
End;

Var StartingX, StartingY : Integer;

Begin
StartingX := WhereX;
StartingY := WhereY;
SetScreenMax;
GotoXY(StartingX,StartingY);
End.




More information about the fpc-pascal mailing list