comp.lang.ada
 help / color / mirror / Atom feed
* Help for clear_screen
@ 1997-05-18  0:00 Xer
  1997-05-20  0:00 ` Jerry van Dijk
  0 siblings, 1 reply; 2+ messages in thread
From: Xer @ 1997-05-18  0:00 UTC (permalink / raw)



	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?.

	Thanks everybody!.




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Help for clear_screen
  1997-05-18  0:00 Help for clear_screen Xer
@ 1997-05-20  0:00 ` Jerry van Dijk
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry van Dijk @ 1997-05-20  0:00 UTC (permalink / raw)



In article <MPLANET.337f37e2xerman989683@diana.ibernet.es> 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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-05-20  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-18  0:00 Help for clear_screen Xer
1997-05-20  0:00 ` Jerry van Dijk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox