Sebastian

clear the screen in Modula-2

3 posts in this topic

Hey. As I can clear the screen in Modula-2 ?. For example, as was done in Pascal with the procedure ClrScr. The procedure Clear Window Library of TSCP is not working. Thank you.

Share this post


Link to post
Share on other sites

If you are talking about a text screen, I have an ANSI module that I did up. Need to remember where I posted it online. If anyone wants it, I can make it available again somewhere. This is the DEF file. (What the heck, I'll just post the source file in the next post, rather than putting it online somewhere.)

DEFINITION MODULE ANSI2;

 (* For many of the options, there are two ways of         
 **	accomplishing the same thing.  One way is to use
 **	the constant value with WriteString.  For example, 
 **	if you wanted to print 'Hello World, it is me.' with
 **	'World' in red text on a yellow background, you 
 **	could use:
 **	  WriteString("Hello "+redf+yellowb+"World"+reset+", it is me.");
 **	or:
 **	  WriteString("Hello ");
 **	  WriteString(redf);
 **	  WriteString(yellowb);
 **	  WriteString("World");
 **	  WriteString(reset);
 **	  WriteString(", it is me.");
 **
 **   	If you wanted to do it with the PROCEDURE calls, it might
 ** 	be similar to:
 **	  WriteString("Hello ");
 **	  RedF; YellowB; WriteString("World"); Reset;
 **	  WriteString(", it is me.");
 **
 **	The same applies to the attribute settings such as bold,
 **	inverse, etc.
 **
 **	The cursor controls are similar, in that you can call them
 **	both ways.  However, when you call the cursor controls
 **	with a constant, you will be using the defaults. For
 **	example, homeCur will position the cursor in the upper-left
 **	part of the terminal. upCur will move the cursor up 1 row.
 **	
 **	When you use the PROCEDURE calls, you may specify what you want.
 **	Home; and HomeCur(0, 0); are equivalent. Up; and UpCur(1);
 **  	are eqivalent.  Moving the cursor down three lines can be
 **	accomplished with:
 **	
 **	  1)  CONST str := +downCur+downCur+downCur;
 **	      WriteString(str);
 **
 **	  2)  Down; Down; Down;
 **
 **	  3)  DownCur(3);
 **
 *)


CONST
 esc     = 33C;

 (* Set Display Attributes:
 **    Change the foreground or background colors, or
 **    the the attributes of text in the terminal          *)


 reset    = esc+"[0m";  (* Reset  all attributes           *) 

 defaultf = esc+"[39m"; (* Set foreground color to default *)
 blackf   = esc+"[30m"; (* Set foreground color to black   *)
 redf     = esc+"[31m"; (* Set foreground color to red     *)
 greenf   = esc+"[32m"; (* Set foreground color to green   *)
 yellowf  = esc+"[33m"; (* Set foreground color to yellow  *)
 bluef    = esc+"[34m"; (* set foreground color to blue    *)
 purplef  = esc+"[35m"; (* set foreground color to magenta *)
 cyanf    = esc+"[36m"; (* set foreground color to cyan    *)
 whitef   = esc+"[37m"; (* set foreground color to white   *)

 defaultb = esc+"[49m"; (* Set background color to default *)
 blackb   = esc+"[40m"; (* Set background color to black   *)
 redb     = esc+"[41m"; (* Set background color to red     *)
 greenb   = esc+"[42m"; (* Set background color to green   *)
 yellowb  = esc+"[43m"; (* Set background color to yellow  *)
 blueb    = esc+"[44m"; (* Set background color to blue    *)
 purpleb  = esc+"[45m"; (* Set background color to magenta *)
 cyanb    = esc+"[46m"; (* Set background color to cyan    *)
 whiteb   = esc+"[47m"; (* Set background color to white   *)

 boldon    = esc+"[1m";   boldoff    = esc+"[22m";
 italicson = esc+"[3m";   italicsoff = esc+"[23m";
 ulon      = esc+"[4m";   uloff      = esc+"[24m";
 invon     = esc+"[7m";   invoff     = esc+"[27m";

 (* Cursor Control - These use defaults, to set the cursor to
                     a particular position, I will be adding
	      PROCEDURES eventually.                     *)
 homeCur     = esc+"[H"; (* Sets the cursor to the upper left   *)
 upCur       = esc+"[A"; (* Move cursor up one row              *)
 downCur     = esc+"[b"; (* Move cursor down one row            *)
 saveCur     = esc+"[s"; (* Save cursor position                *)
 unsaveCur   = esc+"[u"; (* Restore saved cursor position                                                                                                                                                                                                                                                                                                                        *)
 saveCAtt    = esc+"7";  (* Save cursor position and attributes *)
 restoreCAtt = esc+"8";  (* Restore cursor pos'n and attributes *)

 eraseScr    = esc+"[2J"; (* erase screen, move cursor to home  *)
 eraseLn     = esc+"[2K"; (* erase current line                 *)

PROCEDURE Reset;

PROCEDURE DefaultF;
PROCEDURE BlackF;
PROCEDURE RedF;
PROCEDURE GreenF;
PROCEDURE YellowF;
PROCEDURE BlueF;
PROCEDURE PurpleF;
PROCEDURE CyanF;
PROCEDURE WhiteF;

PROCEDURE DefaultB;
PROCEDURE BlackB;
PROCEDURE RedB;
PROCEDURE GreenB;
PROCEDURE YellowB;
PROCEDURE BlueB;
PROCEDURE PurpleB;
PROCEDURE CyanB;
PROCEDURE WhiteB;

(* Attributes *)
PROCEDURE BoldOn;
PROCEDURE BoldOff;
PROCEDURE ItalicsOn;
PROCEDURE ItalicsOff;
PROCEDURE ULOn;
PROCEDURE ULOff;
PROCEDURE InvOn;
PROCEDURE InvOff;


(* Cursor control *)

PROCEDURE Home;
 (* Sets the cursor to the Home (upper left) position. Does not 
    clear the screen. *) 
PROCEDURE HomeCur(row, col : CARDINAL);
 (* Sets the cursor to the specified position. Does not clear the
    screen. The rows and columns start at 1 *)
PROCEDURE Up;
 (* Moves the cursor up by 1 row, does not wrap or scroll,
    stops at top *)
PROCEDURE Down;
 (* Moves the cursor down by 1 row, does not wrap or scroll,
    stops at bottom *)
PROCEDURE Right;
 (* Moves the cursor forward by 1 column. Does not wrap or scroll,
    stops at right edge *)
PROCEDURE Left;
 (* Moves the cursor backward by 1 column. Stops at left edge *)
PROCEDURE Save;
 (* *)
PROCEDURE Restore;
PROCEDURE SaveCA;
PROCEDURE RestoreCA;
PROCEDURE Cls;
PROCEDURE EraseLn;

END ANSI2.

Share this post


Link to post
Share on other sites

Here is the source file. ANSI2.MOD

IMPLEMENTATION MODULE ANSI2;

FROM STextIO  IMPORT WriteString;
FROM WholeStr IMPORT CardToStr;
FROM Strings  IMPORT Append;

TYPE
 strT = ARRAY [0..19] OF CHAR;
VAR
 RowStr, ColStr, CodeStr : strT;


PROCEDURE set(code : ARRAY OF CHAR);
BEGIN
 WriteString(esc);
 WriteString(code);
END set;


PROCEDURE Reset;
BEGIN
 set("[0m");
END Reset;  


PROCEDURE DefaultF;
BEGIN
 set("[39m");
END DefaultF;  

PROCEDURE BlackF;
BEGIN
 set("[30m");
END BlackF;  

PROCEDURE RedF;
BEGIN
 set("[31m");
END RedF;  

PROCEDURE GreenF;
BEGIN
 set("[32m");
END GreenF;

PROCEDURE YellowF;
BEGIN
 set("[33m");
END YellowF;

PROCEDURE BlueF;
BEGIN
 set("[34m");
END BlueF;

PROCEDURE PurpleF;
BEGIN
 set("[35m");
END PurpleF;

PROCEDURE CyanF;
BEGIN
 set("[36m");
END CyanF;

PROCEDURE WhiteF;
BEGIN
 set("[37m");
END WhiteF;


PROCEDURE DefaultB;
BEGIN
 set("[49m");
END DefaultB;  

PROCEDURE BlackB;
BEGIN
 set("[40m");
END BlackB;  

PROCEDURE RedB;
BEGIN
 set("[41m");
END RedB;  

PROCEDURE GreenB;
BEGIN
 set("[42m");
END GreenB;  

PROCEDURE YellowB;
BEGIN
 set("[43m");
END YellowB;  

PROCEDURE BlueB;
BEGIN
 set("[44m");
END BlueB;  

PROCEDURE PurpleB;
BEGIN
 set("[45m");
END PurpleB;  

PROCEDURE CyanB;
BEGIN
 set("[46m");
END CyanB;  

PROCEDURE WhiteB;
BEGIN
 set("[47m");
END WhiteB;  

(* Attributes *)

PROCEDURE BoldOn;
BEGIN
 set("[1m")
END BoldOn;

PROCEDURE BoldOff;
BEGIN
 set("[22m");
END BoldOff;

PROCEDURE ItalicsOn;
BEGIN
 set("[3m");
END ItalicsOn;

PROCEDURE ItalicsOff;
BEGIN
 set("[23m");
END ItalicsOff;

PROCEDURE ULOn;
BEGIN
 set("[4m");
END ULOn;

PROCEDURE ULOff;
BEGIN
 set("[24m");
END ULOff;

PROCEDURE InvOn;
BEGIN
 set("[7m");
END InvOn;

PROCEDURE InvOff;
BEGIN
 set("[27m");
END InvOff;  


(* Cursor control *)

PROCEDURE Home;
BEGIN
 set("[H");
END Home;

PROCEDURE generate(row, col : CARDINAL) : strT;
VAR
 RowStr, ColStr, WholeStr : strT;
BEGIN
 CardToStr(row, RowStr);
 CardToStr(col, ColStr);
 WholeStr := "[";
 Append(RowStr,WholeStr);
 Append(";",WholeStr);
 Append(ColStr,WholeStr);
 RETURN WholeStr;
END generate;
PROCEDURE HomeCur(row, col : CARDINAL);
BEGIN
 CodeStr := generate(row, col);
 Append("H", CodeStr);
 set(CodeStr);
END HomeCur;

PROCEDURE Up;
BEGIN
 set("[A");
END Up;

PROCEDURE Down;
BEGIN
 set("[b");
END Down;

PROCEDURE Right;
BEGIN
 set("[C");
END Right;

PROCEDURE Left;
BEGIN
 set("[D");
END Left;  

PROCEDURE Save;
BEGIN
 set("[s");
END Save;

PROCEDURE Restore;
BEGIN
 set("[u");
END Restore;

PROCEDURE SaveCA;
BEGIN
 set("7");
END SaveCA;

PROCEDURE RestoreCA;
BEGIN
 set("8");
END RestoreCA;

PROCEDURE Cls;
BEGIN
 set("[2J");
END Cls;  

PROCEDURE EraseLn;
BEGIN
 set("[2K");
END EraseLn;  
END ANSI2.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now