From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,38dab1777379dea5 X-Google-Attributes: gid103376,public From: jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk) Subject: Re: Help for clear_screen Date: 1997/05/20 Message-ID: <864107715.26snx@jvdsys.nextjk.stuyts.nl> X-Deja-AN: 243100129 Distribution: world References: Organization: *JerryWare HQ*, Leiden, Holland Newsgroups: comp.lang.ada Date: 1997-05-20T00:00:00+00:00 List-Id: In article xerman@ribernet.es writes: > Hi!. I'm learning ADA95. I'm making a program with >GNAT304a, and I need to clear the screen and to put the cursor >in a defined position (all in text mode), but the problem is >that I don't know the name of the functions to do these things, >and in which package they are. Could you help me?. Manipulation the cursor and such are really OS dependent, and therefor not addressed by Ada. However, since you mention GNAT 3.04, I presume you are running Windows95. Supprising as it may sound, the Win95 console does support some of the functionality we know from DOS. More specifically, it has both a subset of the familiar conio functions (in the CRT -C RunTime- part of the Win32 binding). The console also supports a limited set of ANSI operations to manipulate the cursor. Now, I'm not sure if it's really needed, but to make sure ANSI is supported add: DEVICEHIGH=C:\WINDOWS\COMMAND\ANSI.SYS to your config.sys file. Then you can use the following package (tested with GNAT 3.09, an upgrade seems wise...) to handle the cursor: package Ansi_Screen is type Attribute is (None, Bold, Dim, Underline, Blink, Inverse); procedure Set_Attribute (A : in Attribute); procedure Clear_Screen; procedure Clear_To_End_Of_Line; procedure Cursor_Up (Lines : in Natural := 1); procedure Cursor_Left (Chars : in Natural := 1); procedure Cursor_Down (Lines : in Natural := 1); procedure Cursor_Right (Chars : in Natural := 1); procedure Cursor_To (X : in Natural; Y : in Natural); end Ansi_Screen; with Ada.Text_IO; package body Ansi_Screen is ----------------------------------------------------------------------- -- Return string representation of string with leading space removed -- -- PRE: N is an valid integer -- -- POST: a constant string representing the integer -- ----------------------------------------------------------------------- function To_String (N : Integer) return String is Result : String := Integer'Image (N); begin return Result (2 .. Result'Last); end To_String; pragma Inline (To_String); ----------------------------------------------------------------------- -- Output ANSI command sequence to the current output stream -- -- PRE: S is a valid ANSI sequence without escape sequence in front -- -- Current output stream is a valid ANSI-able output device -- -- POST: ANSI sequence with escape sequence added up front written -- ----------------------------------------------------------------------- procedure Output_Command (S : in String) is begin Ada.Text_IO.Put (ASCII.ESC & '[' & S); end Output_Command; pragma Inline (Output_Command); --------------------------------------------------------------- -- Erase the display without moving the cursor -- -- POST: display is erased to current fore/background colors -- --------------------------------------------------------------- procedure Clear_Screen is begin Output_Command ("2J"); end Clear_Screen; ----------------------------------------------------- -- Erase the current line from (including) current -- -- cursor position up to the end of the line -- -- POST: current line erased from cursor position -- -- using current fore/background colors -- ----------------------------------------------------- procedure Clear_To_End_Of_Line is begin Output_Command ("K"); end Clear_To_End_Of_Line; -------------------------------------------------------------- -- Move the Cursor up 'Lines' lines, until at top of screen -- -- POST: cursor moved up one line or/and at top of screen -- -------------------------------------------------------------- procedure Cursor_Up (Lines : in Natural := 1) is begin Output_Command (To_String (Lines) & 'A'); end Cursor_Up; ------------------------------------------------------------------- -- Move the Cursor down 'Lines' lines, until at bottom of screen -- -- POST: cursor moved down one line or/and at bottom of screen -- ------------------------------------------------------------------- procedure Cursor_Down (Lines : in Natural := 1) is begin Output_Command (To_String (Lines) & 'B'); end Cursor_Down; -------------------------------------------------------------------- -- Move the Cursor right 'Chars' characters, until at end of line -- -- POST: cursor moved right one character or/and at end of line -- -------------------------------------------------------------------- procedure Cursor_Right (Chars : in Natural := 1) is begin Output_Command (To_String (Chars) & 'C'); end Cursor_Right; --------------------------------------------------------------------- -- Move the Cursor left 'Chars' characters, until at begin of line -- -- POST: cursor moved left one character or/and at begin of line -- --------------------------------------------------------------------- procedure Cursor_Left (Chars : in Natural := 1) is begin Output_Command (To_String (Chars) & 'D'); end Cursor_Left; ------------------------------------------------------------- -- Move cursor to screen position X, Y -- -- PRE: X, Y is a valid screen coordinate -- -- POST: cursor moved to X,Y or encountered edge of screen -- ------------------------------------------------------------- procedure Cursor_To (X : in Natural; Y : in Natural) is begin Output_Command (To_string (Y) & ';' & To_String (X) & 'H'); end Cursor_To; ---------------------------------------------------- -- Set new cumulative screen attribute -- -- PRE: A is a valid attribute -- -- POST: screen attribute for new output set to A -- ---------------------------------------------------- procedure Set_Attribute (A : in Attribute) is Attribute_Value : array (Attribute) of String(1 .. 1) := ("0", "1", "2", "4", "5", "7"); begin Output_Command (Attribute_Value(A) & 'm'); end Set_Attribute; end Ansi_Screen; Hope this helps... -- -- Jerry van Dijk | Leiden, Holland -- Consultant | Team Ada -- Ordina Finance | jdijk@acm.org