comp.lang.ada
 help / color / mirror / Atom feed
* Re: Terminal IO, and menus
  1999-03-30  0:00 Terminal IO, and menus Heath Isler
@ 1999-03-30  0:00 ` David C. Hoos, Sr.
  1999-03-31  0:00 ` Matthew Heaney
  1999-03-31  0:00 ` Jerry van Dijk
  2 siblings, 0 replies; 15+ messages in thread
From: David C. Hoos, Sr. @ 1999-03-30  0:00 UTC (permalink / raw)



Heath Isler wrote in message <7drb1p$48k$1@nw001t.infi.net>...
>Hello,
>
>I am new to ADA, I like it so far.  It seems to be one of the most readable
>Languages I have seen.
>
>My question is is there a way in the stadard packages to Clear the Screen
>and postition the cursor in a specific location, i.e. Locate_Cursor (x =>
>10, y =>15); ?  I am plan on using this for menus and data input.
>
>I have looked and haven't been able to find anything in the Standard
>Packages, if I missed something please let me know.
>
>I have also looked through alot of packages on the net, and some of them
>seem to fit my need.  I not sure if I should use one of the Terminal IO or
>menu packages.  Can anyone recommend a package to use?
>
You need to be more specific about on which platform(s) you want to run.
For example, DOS, Windows 3.1, Windows 9X and Most UNIXes have ANSI
terminal emulations which allow you to use escape sequences to position
the cursor.  A simplified exampl of using this is provided in the
diners program in the gnat examples.

On Windows NT, there is no ANS terminal emulator, so you would need to
use a pakage like Jerry van Dijk's NT Console, available at
http://stad.dsl.nl/~jvandyk

In short, the standard packages do not cover operating-system-specific
features.










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

* Terminal IO, and menus
@ 1999-03-30  0:00 Heath Isler
  1999-03-30  0:00 ` David C. Hoos, Sr.
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Heath Isler @ 1999-03-30  0:00 UTC (permalink / raw)


Hello,

I am new to ADA, I like it so far.  It seems to be one of the most readable
Languages I have seen.

My question is is there a way in the stadard packages to Clear the Screen
and postition the cursor in a specific location, i.e. Locate_Cursor (x =>
10, y =>15); ?  I am plan on using this for menus and data input.

I have looked and haven't been able to find anything in the Standard
Packages, if I missed something please let me know.

I have also looked through alot of packages on the net, and some of them
seem to fit my need.  I not sure if I should use one of the Terminal IO or
menu packages.  Can anyone recommend a package to use?

Thanks,
Heath






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

* Re: Terminal IO, and menus
  1999-03-30  0:00 Terminal IO, and menus Heath Isler
  1999-03-30  0:00 ` David C. Hoos, Sr.
  1999-03-31  0:00 ` Matthew Heaney
@ 1999-03-31  0:00 ` Jerry van Dijk
  1999-03-31  0:00   ` Tarjei Tj�stheim Jensen
  1999-04-01  0:00   ` Juergen Pfeifer
  2 siblings, 2 replies; 15+ messages in thread
From: Jerry van Dijk @ 1999-03-31  0:00 UTC (permalink / raw)


Heath Isler (isler@gfherald.infi.net) wrote:

: My question is is there a way in the stadard packages to Clear the Screen
: and postition the cursor in a specific location, i.e. Locate_Cursor (x =>
: 10, y =>15); ?  I am plan on using this for menus and data input.

This is an inherentely OS bounded question. For DOS, you can do this with
the conio binding that comes with EZ2LOAD, for Win32, NT_Console does this
sort of thing. For linux there is the curses binding, etc.

Two years ago I tried to get people to agree on a singe console control
package standard, but there was, alas, no interest in this...

--
-- Jerry van Dijk | Leiden, Holland
-- Team Ada       | jdijk@acm.org
-- see http://stad.dsl.nl/~jvandyk




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

* Re: Terminal IO, and menus
  1999-03-30  0:00 Terminal IO, and menus Heath Isler
  1999-03-30  0:00 ` David C. Hoos, Sr.
@ 1999-03-31  0:00 ` Matthew Heaney
  1999-04-01  0:00   ` Heath Isler
  1999-04-01  0:00   ` Bill Eriksson
  1999-03-31  0:00 ` Jerry van Dijk
  2 siblings, 2 replies; 15+ messages in thread
From: Matthew Heaney @ 1999-03-31  0:00 UTC (permalink / raw)


"Heath Isler" <isler@gfherald.infi.net> writes:

> My question is is there a way in the stadard packages to Clear the Screen
> and postition the cursor in a specific location, i.e. Locate_Cursor (x =>
> 10, y =>15); ?  I am plan on using this for menus and data input.

No, there's nothing in the Ada predefined packages to do that.
 
 
> I have also looked through a lot of packages on the net, and some of
> them seem to fit my need.  I not sure if I should use one of the
> Terminal IO or menu packages.  Can anyone recommend a package to use?

In the GNAT source distribution, the dining philosophers example does
terminal I/O using escape sequences.


--::::::::::
--screen.ads
--::::::::::
package Screen is

  -- simple ANSI terminal emulator
  -- Michael Feldman, The George Washington University
  -- July, 1995

  ScreenHeight : constant Integer := 24;
  ScreenWidth : constant Integer := 80;

  subtype Height is Integer range 1..ScreenHeight;
  subtype Width  is Integer range 1..ScreenWidth;

  type Position is record
    Row   : Height := 1;
    Column: Width := 1;
  end record;

  procedure Beep; 
  -- Pre:  none
  -- Post: the terminal beeps once
  
  procedure ClearScreen; 
  -- Pre:  none
  -- Post: the terminal screen is cleared
  
  procedure MoveCursor (To: in Position);
  -- Pre:  To is defined
  -- Post: the terminal cursor is moved to the given position
  
end Screen;   


--::::::::::
--screen.adb
--::::::::::
with Text_IO;
package body Screen is

  -- simple ANSI terminal emulator
  -- Michael Feldman, The George Washington University
  -- July, 1995

  -- These procedures will work correctly only if the actual
  -- terminal is ANSI compatible. ANSI.SYS on a DOS machine
  -- will suffice.

  package Int_IO is new Text_IO.Integer_IO (Num => Integer);

  procedure Beep is
  begin
    Text_IO.Put (Item => ASCII.BEL);
  end Beep;

  procedure ClearScreen is
  begin
    Text_IO.Put (Item => ASCII.ESC);
    Text_IO.Put (Item => "[2J");
  end ClearScreen;

  procedure MoveCursor (To: in Position) is
  begin                                                
    Text_IO.New_Line;
    Text_IO.Put (Item => ASCII.ESC);
    Text_IO.Put ("[");
    Int_IO.Put (Item => To.Row, Width => 1);
    Text_IO.Put (Item => ';');
    Int_IO.Put (Item => To.Column, Width => 1);
    Text_IO.Put (Item => 'f');
  end MoveCursor;  

end Screen;




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

* Re: Terminal IO, and menus
  1999-03-31  0:00 ` Jerry van Dijk
@ 1999-03-31  0:00   ` Tarjei Tj�stheim Jensen
  1999-04-02  0:00     ` Jerry van Dijk
  1999-04-01  0:00   ` Juergen Pfeifer
  1 sibling, 1 reply; 15+ messages in thread
From: Tarjei Tj�stheim Jensen @ 1999-03-31  0:00 UTC (permalink / raw)


Jerry van Dijk wrote:

>Two years ago I tried to get people to agree on a singe console control
>package standard, but there was, alas, no interest in this...

I'm very interested. My problem is mainly with time and lack of facilities. I'm
working to fix these two problems, so I can contribute. It is not fun to
program lying on your stomack. I need to do it sitting upright.


Greetings,


PS.
Your e-mail address does not work.







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

* Re: Terminal IO, and menus
  1999-03-31  0:00 ` Jerry van Dijk
  1999-03-31  0:00   ` Tarjei Tj�stheim Jensen
@ 1999-04-01  0:00   ` Juergen Pfeifer
  1999-04-02  0:00     ` Jerry van Dijk
  1 sibling, 1 reply; 15+ messages in thread
From: Juergen Pfeifer @ 1999-04-01  0:00 UTC (permalink / raw)


Jerry van Dijk wrote:
> 
> Heath Isler (isler@gfherald.infi.net) wrote:
> 
> : My question is is there a way in the stadard packages to Clear the Screen
> : and postition the cursor in a specific location, i.e. Locate_Cursor (x =>
> : 10, y =>15); ?  I am plan on using this for menus and data input.
> 
> This is an inherentely OS bounded question. For DOS, you can do this with
> the conio binding that comes with EZ2LOAD, for Win32, NT_Console does this
> sort of thing. For linux there is the curses binding, etc.
> 
> Two years ago I tried to get people to agree on a singe console control
> package standard, but there was, alas, no interest in this...
> 
Well, I'm very interested too. Of course I first suggest to port (n)curses
to DOS and Win32, which will be more simple with one of the next releases
of ncurses which redesigns some of the internals to base it on a "driver"
logic. This will make it very fast and thin on memory mapped devices like
DOS or Win32 consoles. For Ada you may then use the ncurses binding as
your cross-platform console I/O package that works on DOS, OS/2, Win32
and almost all UNIXes. 

It is for sure possible to write the above mentioned "Drivers" for the
coming new ncurses in Ada95. These drivers do only some very low level
operations on consoles.

J�rgen




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

* Re: Terminal IO, and menus
  1999-03-31  0:00 ` Matthew Heaney
@ 1999-04-01  0:00   ` Heath Isler
  1999-04-01  0:00     ` John J Cupak Jr
  1999-04-01  0:00   ` Bill Eriksson
  1 sibling, 1 reply; 15+ messages in thread
From: Heath Isler @ 1999-04-01  0:00 UTC (permalink / raw)


Hello,

I would like to thank everyone  for the input.  I have decided to use the
escape sequences for a ansi terminal since my target platforms are Win9X,
Dos, Unixes, I don't care at this point if it runs on Win NT since I don't
have it.

Heath

Matthew Heaney <matthew_heaney@acm.org> wrote in message
news:m3677if8ks.fsf@mheaney.ni.net...
> "Heath Isler" <isler@gfherald.infi.net> writes:
>
> > My question is is there a way in the stadard packages to Clear the
Screen
> > and postition the cursor in a specific location, i.e. Locate_Cursor (x
=>
> > 10, y =>15); ?  I am plan on using this for menus and data input.
>
> No, there's nothing in the Ada predefined packages to do that.
>
>
> > I have also looked through a lot of packages on the net, and some of
> > them seem to fit my need.  I not sure if I should use one of the
> > Terminal IO or menu packages.  Can anyone recommend a package to use?
>
> In the GNAT source distribution, the dining philosophers example does
> terminal I/O using escape sequences.
>
>
> --::::::::::
> --screen.ads
> --::::::::::
> package Screen is
>
>   -- simple ANSI terminal emulator
>   -- Michael Feldman, The George Washington University
>   -- July, 1995
>
>   ScreenHeight : constant Integer := 24;
>   ScreenWidth : constant Integer := 80;
>
>   subtype Height is Integer range 1..ScreenHeight;
>   subtype Width  is Integer range 1..ScreenWidth;
>
>   type Position is record
>     Row   : Height := 1;
>     Column: Width := 1;
>   end record;
>
>   procedure Beep;
>   -- Pre:  none
>   -- Post: the terminal beeps once
>
>   procedure ClearScreen;
>   -- Pre:  none
>   -- Post: the terminal screen is cleared
>
>   procedure MoveCursor (To: in Position);
>   -- Pre:  To is defined
>   -- Post: the terminal cursor is moved to the given position
>
> end Screen;
>
>
> --::::::::::
> --screen.adb
> --::::::::::
> with Text_IO;
> package body Screen is
>
>   -- simple ANSI terminal emulator
>   -- Michael Feldman, The George Washington University
>   -- July, 1995
>
>   -- These procedures will work correctly only if the actual
>   -- terminal is ANSI compatible. ANSI.SYS on a DOS machine
>   -- will suffice.
>
>   package Int_IO is new Text_IO.Integer_IO (Num => Integer);
>
>   procedure Beep is
>   begin
>     Text_IO.Put (Item => ASCII.BEL);
>   end Beep;
>
>   procedure ClearScreen is
>   begin
>     Text_IO.Put (Item => ASCII.ESC);
>     Text_IO.Put (Item => "[2J");
>   end ClearScreen;
>
>   procedure MoveCursor (To: in Position) is
>   begin
>     Text_IO.New_Line;
>     Text_IO.Put (Item => ASCII.ESC);
>     Text_IO.Put ("[");
>     Int_IO.Put (Item => To.Row, Width => 1);
>     Text_IO.Put (Item => ';');
>     Int_IO.Put (Item => To.Column, Width => 1);
>     Text_IO.Put (Item => 'f');
>   end MoveCursor;
>
> end Screen;






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

* Re: Terminal IO, and menus
  1999-03-31  0:00 ` Matthew Heaney
  1999-04-01  0:00   ` Heath Isler
@ 1999-04-01  0:00   ` Bill Eriksson
  1 sibling, 0 replies; 15+ messages in thread
From: Bill Eriksson @ 1999-04-01  0:00 UTC (permalink / raw)




As an alternative, you may use this (Compiled it from some Ada text-books):

package Screen is

   ---------------
   -- Types
   ---------------

   type Mode_Type is (Text, Ansi);

   type Text_Attribute_Type is (All_Off, Bold, Blinking, Inverse, Hidden);


   type Foreground_Color_Type is (Black, Red, Green, Yellow, Blue, Magenta,
                                  Cyan, White);

   type Background_Color_Type is (Black, Red, Green, Yellow, Blue, Magenta,
                                  Cyan, White);


   --------------------------------------
   -- Enumeration Representation Clauses:
   --------------------------------------

   for Text_Attribute_Type'Size use Integer'Size;

   for Text_Attribute_Type use (All_Off => 0, Bold => 1, Blinking => 5,
                                Inverse => 7, Hidden => 8);

      --Colors according to Standard ISO 6429 :

   for Foreground_Color_Type use (Black => 30, Red => 31, Green => 32,
                                  Yellow => 33, Blue => 34, Magenta => 35,
                                  Cyan => 36, White => 37);

   for Background_Color_Type use (Black => 40, Red => 41, Green => 42,
                                  Yellow => 43, Blue => 44, Magenta => 45,
                                  Cyan => 46, White => 47);

   -------------------------------------------------------------------
   procedure Set_Size(Max_Row, Max_Col : in Integer);
   --
   -- Purpose      - Sets Screen Size.
   --                Default Size: Max_Row :=24, Max_Col :=80
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   function Get_Max_Row return Integer;
   --
   -- Purpose      - Gets Max_Row.
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   function Get_Max_Col return Integer;
   --
   -- Purpose      - Gets Max_Col.
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   procedure Set_Mode(To : in Mode_Type);
   --
   -- Purpose      - Sets Screen Control Mode.
   --                Default Mode: Text
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   function Get_Mode return Mode_Type;
   --
   -- Purpose      - Gets Actual Screen Control Mode.
   --
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   procedure Clear;
   --
   -- Purpose      - Clear Screen
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   procedure Put(Text: in String);
   --
   -- Purpose      - Writes a String at actual position on Screen.
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   procedure Put_Line(Text: in String);
   --
   -- Purpose      - Writes a String at actual position on Screen and
   --                then executes New_Line.
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   procedure Position(In_row,In_col : in Integer);
   --
   -- Purpose      - Places the Cursor to specified position.
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   procedure Erase_To_Eol;
   --
   -- Purpose      - Erases from actual position to end of line.
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   procedure Bell;
   --
   -- Purpose      - Makes the "beep" sound.
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   procedure Set_Text_Attribute( To: Text_Attribute_Type);
   --
   -- Purpose      - Sets Text Attributes.
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------
   -------------------------------------------------------------------
   procedure Set_Color( Foreground : Foreground_Color_Type;
                        Background : Background_Color_Type);
   --
   -- Purpose      - Sets Color Attributes.
   --
   -- Exceptions   - None
   -- Others       - None
   -------------------------------------------------------------------

end Screen;


with Text_Io;
with Unchecked_Conversion;

package body Screen is

   --------------------------
   -- Types
   --------------------------

   type Screen_Type is record
            Max_Row       : Integer;
            Max_col       : Integer;
            Terminal_Mode : Mode_Type;
         end record;

   --------------------------
   -- Constants
   --------------------------

   Terminal_Clear       : constant String := Ascii.Esc & "[2J";
   Terminal_Bell        : constant String := " " & Ascii.Bel;
   Erase_To_End_Of_Line : constant String := Ascii.Esc & "[K";


   --------------------------
   -- Variables
   --------------------------

   Scr : Screen_Type := (24, 80, Text);  -- Default

   --------------------------
   -- Instantiations
   --------------------------

   function Text_Attribute_To_Integer is new
      Unchecked_Conversion(Text_Attribute_Type, Integer);

   function Fg_Color_To_Integer is new
      Unchecked_Conversion(Foreground_Color_Type, Integer);

   function Bg_Color_To_Integer is new
      Unchecked_Conversion(Background_Color_Type, Integer);

-------------------------------------------------------------------
   procedure Set_Size(Max_Row, Max_Col : in Integer) is
-------------------------------------------------------------------
   begin
      Scr.Max_Row := Max_Row;
      Scr.Max_Col := Max_Col;
   end Set_Size;
-------------------------------------------------------------------

-------------------------------------------------------------------
   function Get_Max_Row return Integer is
-------------------------------------------------------------------
   begin
      return Scr.Max_Row;
   end Get_Max_Row;
-------------------------------------------------------------------

-------------------------------------------------------------------
   function Get_Max_Col return Integer is
-------------------------------------------------------------------
   begin
      return Scr.Max_Col;
   end Get_Max_Col;
-------------------------------------------------------------------

-------------------------------------------------------------------
   procedure Set_Mode(To : in Mode_Type ) is
-------------------------------------------------------------------
   begin
      Scr.Terminal_Mode := To;
   end Set_Mode;
-------------------------------------------------------------------

-------------------------------------------------------------------
   function Get_Mode return Mode_Type is
-------------------------------------------------------------------
   begin
      return Scr.Terminal_Mode;
   end Get_Mode;
-------------------------------------------------------------------

-------------------------------------------------------------------
   procedure Clear is
-------------------------------------------------------------------
   begin                        -- Clear
      if Scr.Terminal_Mode = Ansi then
         Text_Io.Put(Terminal_Clear);
      else
         Text_Io.New_Page;
      end if;
   end Clear;
-------------------------------------------------------------------

-------------------------------------------------------------------
   procedure Put(Text: in String) is
-------------------------------------------------------------------
   begin                        -- Put
      Text_Io.Put(Text);
   end Put;
-------------------------------------------------------------------

-------------------------------------------------------------------
   procedure Put_Line(Text: in String) is
-------------------------------------------------------------------
   begin                        -- Put_Line
      Text_Io.Put_Line(Text);
   end Put_Line;
-------------------------------------------------------------------

-------------------------------------------------------------------
   procedure Position(In_Row, In_Col: in Integer) is
-------------------------------------------------------------------
   begin
      if Scr.Terminal_Mode = Ansi then
         Text_Io.Put(Ascii.Esc & '[' &
            Integer'Image(In_Row)(2..Integer'Image(In_Row)'Last) & ';' &
            Integer'Image(In_Col)(2..Integer'Image(In_Col)'Last) & 'H');
      else
         null; -- Text_Io's Set_Line and Set_Col will not solve this
      end if;
   end Position;
-------------------------------------------------------------------

-------------------------------------------------------------------
   procedure Erase_To_Eol is
-------------------------------------------------------------------
   begin
      if Scr.Terminal_Mode = Ansi then
         Text_Io.Put(Erase_To_End_Of_Line);
      else
         null;
      end if;
   end Erase_To_Eol;
-------------------------------------------------------------------

-------------------------------------------------------------------
   procedure Bell is
-------------------------------------------------------------------
   begin
      -- Will work in any mode ?
      Text_Io.Put(Terminal_Bell);
   end Bell;
-------------------------------------------------------------------

-------------------------------------------------------------------
   procedure Set_Text_Attribute(To: Text_Attribute_Type) is
-------------------------------------------------------------------
   Attr : constant String := Integer'Image(Text_Attribute_To_Integer(To));
   begin
      if Scr.Terminal_Mode = Ansi then
         Text_Io.Put(Ascii.Esc & "[" & Attr(2..Attr'Last) & "m");
      else
         null;
      end if;
   end Set_Text_Attribute;
-------------------------------------------------------------------
-------------------------------------------------------------------
   procedure Set_Color(Foreground: Foreground_Color_Type;
                       Background: Background_Color_Type) is
-------------------------------------------------------------------
   Fg : constant String := Integer'Image(Fg_Color_To_Integer(Foreground));
   Bg : constant String := Integer'Image(Bg_Color_To_Integer(Background));
   begin
      if Scr.Terminal_Mode = Ansi then
         Text_Io.Put(Ascii.Esc & "[" & Fg(2..Fg'Last) &
                  ";" & Bg(2..Bg'Last) & "m");
      else
         null;
      end if;
   end Set_Color;
-------------------------------------------------------------------

end Screen;

Matthew Heaney skrev:

> "Heath Isler" <isler@gfherald.infi.net> writes:
>
> > My question is is there a way in the stadard packages to Clear the Screen
> > and postition the cursor in a specific location, i.e. Locate_Cursor (x =>
> > 10, y =>15); ?  I am plan on using this for menus and data input.
>
> No, there's nothing in the Ada predefined packages to do that.
>
>
> > I have also looked through a lot of packages on the net, and some of
> > them seem to fit my need.  I not sure if I should use one of the
> > Terminal IO or menu packages.  Can anyone recommend a package to use?
>
> In the GNAT source distribution, the dining philosophers example does
> terminal I/O using escape sequences.
>
> --::::::::::
> --screen.ads
> --::::::::::
> package Screen is
>
>   -- simple ANSI terminal emulator
>   -- Michael Feldman, The George Washington University
>   -- July, 1995
>
>   ScreenHeight : constant Integer := 24;
>   ScreenWidth : constant Integer := 80;
>
>   subtype Height is Integer range 1..ScreenHeight;
>   subtype Width  is Integer range 1..ScreenWidth;
>
>   type Position is record
>     Row   : Height := 1;
>     Column: Width := 1;
>   end record;
>
>   procedure Beep;
>   -- Pre:  none
>   -- Post: the terminal beeps once
>
>   procedure ClearScreen;
>   -- Pre:  none
>   -- Post: the terminal screen is cleared
>
>   procedure MoveCursor (To: in Position);
>   -- Pre:  To is defined
>   -- Post: the terminal cursor is moved to the given position
>
> end Screen;
>
> --::::::::::
> --screen.adb
> --::::::::::
> with Text_IO;
> package body Screen is
>
>   -- simple ANSI terminal emulator
>   -- Michael Feldman, The George Washington University
>   -- July, 1995
>
>   -- These procedures will work correctly only if the actual
>   -- terminal is ANSI compatible. ANSI.SYS on a DOS machine
>   -- will suffice.
>
>   package Int_IO is new Text_IO.Integer_IO (Num => Integer);
>
>   procedure Beep is
>   begin
>     Text_IO.Put (Item => ASCII.BEL);
>   end Beep;
>
>   procedure ClearScreen is
>   begin
>     Text_IO.Put (Item => ASCII.ESC);
>     Text_IO.Put (Item => "[2J");
>   end ClearScreen;
>
>   procedure MoveCursor (To: in Position) is
>   begin
>     Text_IO.New_Line;
>     Text_IO.Put (Item => ASCII.ESC);
>     Text_IO.Put ("[");
>     Int_IO.Put (Item => To.Row, Width => 1);
>     Text_IO.Put (Item => ';');
>     Int_IO.Put (Item => To.Column, Width => 1);
>     Text_IO.Put (Item => 'f');
>   end MoveCursor;
>
> end Screen;







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

* Re: Terminal IO, and menus
  1999-04-01  0:00   ` Heath Isler
@ 1999-04-01  0:00     ` John J Cupak Jr
  0 siblings, 0 replies; 15+ messages in thread
From: John J Cupak Jr @ 1999-04-01  0:00 UTC (permalink / raw)
  To: Heath Isler

[-- Attachment #1: Type: text/plain, Size: 3496 bytes --]

Heath,

I have scoured the 'net for such a package, and other than Feldman's, couldn't
find just what I wanted. I also looked at the VT100/xterm escape sequences and
came up with a series of child packages to handle the different screen
properties. I've attached a screen_files.txt file to this message containing
all the packages - suitable for gnatchop (I checked it). Hope this help you..
and anyone else looking for this.

Yours in Ada95!

John J Cupak Jr, CCP

Heath Isler wrote:

> Hello,
>
> I would like to thank everyone  for the input.  I have decided to use the
> escape sequences for a ansi terminal since my target platforms are Win9X,
> Dos, Unixes, I don't care at this point if it runs on Win NT since I don't
> have it.
>
> Heath
>
> Matthew Heaney <matthew_heaney@acm.org> wrote in message
> news:m3677if8ks.fsf@mheaney.ni.net...
> > "Heath Isler" <isler@gfherald.infi.net> writes:
> >
> > > My question is is there a way in the stadard packages to Clear the
> Screen
> > > and postition the cursor in a specific location, i.e. Locate_Cursor (x
> =>
> > > 10, y =>15); ?  I am plan on using this for menus and data input.
> >
> > No, there's nothing in the Ada predefined packages to do that.
> >
> >
> > > I have also looked through a lot of packages on the net, and some of
> > > them seem to fit my need.  I not sure if I should use one of the
> > > Terminal IO or menu packages.  Can anyone recommend a package to use?
> >
> > In the GNAT source distribution, the dining philosophers example does
> > terminal I/O using escape sequences.
> >
> >
> > --::::::::::
> > --screen.ads
> > --::::::::::
> > package Screen is
> >
> >   -- simple ANSI terminal emulator
> >   -- Michael Feldman, The George Washington University
> >   -- July, 1995
> >
> >   ScreenHeight : constant Integer := 24;
> >   ScreenWidth : constant Integer := 80;
> >
> >   subtype Height is Integer range 1..ScreenHeight;
> >   subtype Width  is Integer range 1..ScreenWidth;
> >
> >   type Position is record
> >     Row   : Height := 1;
> >     Column: Width := 1;
> >   end record;
> >
> >   procedure Beep;
> >   -- Pre:  none
> >   -- Post: the terminal beeps once
> >
> >   procedure ClearScreen;
> >   -- Pre:  none
> >   -- Post: the terminal screen is cleared
> >
> >   procedure MoveCursor (To: in Position);
> >   -- Pre:  To is defined
> >   -- Post: the terminal cursor is moved to the given position
> >
> > end Screen;
> >
> >
> > --::::::::::
> > --screen.adb
> > --::::::::::
> > with Text_IO;
> > package body Screen is
> >
> >   -- simple ANSI terminal emulator
> >   -- Michael Feldman, The George Washington University
> >   -- July, 1995
> >
> >   -- These procedures will work correctly only if the actual
> >   -- terminal is ANSI compatible. ANSI.SYS on a DOS machine
> >   -- will suffice.
> >
> >   package Int_IO is new Text_IO.Integer_IO (Num => Integer);
> >
> >   procedure Beep is
> >   begin
> >     Text_IO.Put (Item => ASCII.BEL);
> >   end Beep;
> >
> >   procedure ClearScreen is
> >   begin
> >     Text_IO.Put (Item => ASCII.ESC);
> >     Text_IO.Put (Item => "[2J");
> >   end ClearScreen;
> >
> >   procedure MoveCursor (To: in Position) is
> >   begin
> >     Text_IO.New_Line;
> >     Text_IO.Put (Item => ASCII.ESC);
> >     Text_IO.Put ("[");
> >     Int_IO.Put (Item => To.Row, Width => 1);
> >     Text_IO.Put (Item => ';');
> >     Int_IO.Put (Item => To.Column, Width => 1);
> >     Text_IO.Put (Item => 'f');
> >   end MoveCursor;
> >
> > end Screen;



[-- Attachment #2: screen_files.txt --]
[-- Type: text/plain, Size: 9618 bytes --]

----------------------------------------------------------------------
--  The Screen Package (Specification)
--
--  Programmer : John Cupak
--  History    :  6Oct97 jcj Created
--               17Oct97 jcj "Base" types package 
--  Description: This package defines the xterm/VT100 size
----------------------------------------------------------------------

package Screen is

   Maximum_Rows    : constant := 24;
   Maximum_Columns : constant := 80;

   subtype Rows    is Positive range 1..Maximum_Rows;
   subtype Columns is Positive range 1..Maximum_Columns;

private

   -- Define constant for use by all child packages

   -- Command Sequence Introducer (CSI)
   -- (provides screen command prefix)

   CSI : constant String := ASCII.ESC & "[";

end Screen;
----------------------------------------------------------------------
--  The Screen Attributes Child Package (Specification)
--
--  Programmer : John Cupak
--  History    : 17Oct97 jcj Created
--  Description: Changes display attributes of characters
----------------------------------------------------------------------
package Screen.Attributes is
   -- Turn off attributes - normal video
   procedure Normal;
   -- Turn on underlined mode
   procedure Underlined;
   -- Turn on inverse video mode
   procedure Inverse;
  -- Turn on highlight video mode
   procedure Highlight;
  -- Turn on blink mode
   procedure Blink;

end Screen.Attributes;
----------------------------------------------------------------------
--  The Screen Colors Child Package (Specification)
--
--  Programmer : John Cupak
--  History    : 17Nov97 jcj Created
--  Description: Sets foreground and background color(s) 
----------------------------------------------------------------------

package Screen.Colors is

   type Color is (Black, 
                  Red, 
                  Green, 
                  Yellow, 
                  Blue, 
                  Magenta, 
                  Cyan, 
                  White, 
                  default); -- Original color

   -- Specify internal representations

   for Color use (Black   => 0,
                  Red     => 1,
                  Green   => 2,
                  Yellow  => 3,
                  Blue    => 4,
                  Magenta => 5,
                  Cyan    => 6,
                  White   => 7,
                  default => 9);
   procedure Set_Foreground(Choice : in Color := default);
   procedure Set_Background(Choice : in Color := default);

end Screen.Colors;
----------------------------------------------------------------------
--  The Screen Cursor Control Child Package (Specification)
--
--  Programmer : John Cupak
--  History    : 17Oct97 jcj Created
--  Description: Moves cursor from current position
----------------------------------------------------------------------

package Screen.Cursor is

   -- Move cursor "By" times - stop at top
   procedure Up   (By : in Positive := 1);

   -- Move cursor down "By" times - stop at bottom
   procedure Down (By : in Positive := 1);

   -- Move cursor right "By" times - stop at far right
   procedure Right(By : in Positive := 1);

   -- Move cursor left "By" times - stop at far left
   procedure Left (By : in Positive := 1);

   -- Set cursor position - Column=X, Row=Y
   procedure Position(Column : Columns;  
                      Row    : Rows   ); -- Line

   -- Set cursor home (1,1)
   procedure Home;

end Screen.Cursor;
----------------------------------------------------------------------
--  The Screen Erase Child Package (Specification)
--
--  Programmer : John Cupak
--  History    : 17Oct97 jcj Created
--  Description: Erases lines and screens
----------------------------------------------------------------------

package Screen.Erase is

   procedure To_End_Of_Line; -- Inclusive
   procedure EOF renames To_End_Of_Line;

   procedure To_Beginning_Of_Line; -- Inclusive
   procedure BOL renames To_Beginning_Of_Line;

   procedure Entire_Line; -- Cursor doesn't move
   procedure Line renames Entire_Line;

   procedure To_End_Of_Screen; -- Inclusive
   procedure EOS renames To_End_Of_Screen;

   procedure To_Beginning_Of_Screen; -- Inclusive;
   procedure BOS renames To_Beginning_Of_Screen;

   procedure Entire_Screen; -- Cursor doesn't move
   procedure Clear renames Entire_Screen;

end Screen.Erase;
----------------------------------------------------------------------
--  The Screen Graphics Child Package (Specification)
--
--  Programmer : John Cupak
--  History    : 17Oct97 jcj Created
--  Description: Sets modes and draws lines 
----------------------------------------------------------------------

package Screen.Graphics is

   procedure Set_Character_Mode; -- Turn off drawing
   procedure Set_Line_Mode;      -- Turn on drawing 

   procedure Corner_UL; -- Draw Upper-Left corner
   procedure Corner_UR; -- Draw Upper-Right corner
   procedure Corner_LL; -- Draw Lower_Left corner
   procedure Corner_LR; -- Draw Lower_Right corner

   procedure Tee_Right; -- Vertical line, right connector
   procedure Tee_Left;  -- Vertical line, left connector
   procedure Tee_Up;    -- Horizontal line, up connector
   procedure Tee_Down;  -- Horizontal line, down connector

   procedure Cross;     -- Intersecting lines

   procedure Vertical;  -- Vertical line

   subtype Position is Positive range 1..5; -- Top to Bottom
   procedure Horizontal(Line : in Position := 3);

end Screen.Graphics;   
with Ada.Text_IO;
use  Ada.Text_IO;
package body Screen.Attributes is

   procedure Normal     is
   begin
      Put(CSI & "0m");
   end Normal;

   procedure Highlight  is
   begin
      Put(CSI & "1m");
   end Highlight;

   procedure Underlined is
   begin
      Put(CSI & "4m");
   end Underlined;

   procedure Blink      is
   begin
      Put(CSI & "5m");
   end Blink;

   procedure Inverse    is
   begin
      Put(CSI & "7m");
   end Inverse;

end Screen.Attributes;   
with Ada.Text_IO;
package body Screen.Colors is

   package Color_IO is new Ada.Text_IO.Enumeration_IO(Color);

   use Ada.Text_IO;
   use Color_IO;

   procedure Set_Foreground(Choice : in Color := default) is
   begin
      Put(CSI);    -- Control Sequence Introducer
      Put("3;");   -- Foreground
      Put(Choice); -- specified color
      Put('m');    -- Character attribute
   end Set_Foreground;

   procedure Set_Background(Choice : in Color := default) is
   begin
      Put(CSI);    -- Control Sequence Introducer
      Put("4;");   -- Background
      Put(Choice); -- Specified color
      Put('m');    -- Character attribute
   end Set_Background;

end Screen.Colors;   
with Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;
package body Screen.Cursor is

   procedure Up   (By : in Positive := 1) is
   begin
      Put(CSI);Put(By,0);Put("A");
   end Up;

   procedure Down (By : in Positive := 1) is
   begin
      Put(CSI);Put(By,0);Put("B");
   end Down;

   procedure Right(By : in Positive := 1) is
   begin
      Put(CSI);Put(By,0);Put("C");
   end Right;

   procedure Left (By : in Positive := 1) is
   begin
      Put(CSI);Put(By,0);Put("D");
   end Left;

   procedure Position(Column : in Columns;
                      Row    : in Rows   ) is
   
   begin                                                
      Put(Item => CSI);
      Put(Item => Row,    Width => 0);
      Put(Item => ';');
      Put(Item => Column, Width => 0);
      Put(Item => 'H');
   end Position;

   procedure Home is
   begin
      Put(CSI & "H");
   end Home;

end Screen.Cursor;   
with Ada.Text_IO;
use Ada.Text_IO;
package body Screen.Erase is

   procedure To_End_Of_Line is
   begin
      Put(CSI & "0K");
   end To_End_Of_Line;

   procedure To_Beginning_Of_Line is
   begin
      Put(CSI & "1K");
   end To_Beginning_Of_Line;
   procedure Entire_Line is
   begin
      Put(CSI & "2K");
   end Entire_Line;
   procedure To_End_Of_Screen is
   begin
      Put(CSI & "0J");
   end To_End_Of_Screen;
   procedure To_Beginning_Of_Screen is
   begin
      Put(CSI & "1J");
   end To_Beginning_Of_Screen;
   procedure Entire_Screen is
   begin
      Put(CSI & "2J" );
   end Entire_Screen;

end Screen.Erase;   
with Ada.Text_IO;
with Ada.Characters.Latin_1; -- for SI and SO

use  Ada.Text_IO;
package body Screen.Graphics is

   procedure Set_Character_Mode is
   begin
      Put(Ada.Characters.Latin_1.SI); -- Shift In
   end Set_Character_Mode;
   procedure Set_Line_Mode is
   begin
      Put(Ada.Characters.Latin_1.SO); -- Shift out
   end Set_Line_Mode;

  -- The following procedures assume that the user
  -- has called Set_Line_Mode first.
   procedure Corner_UL is
   begin
      Put('l');
   end Corner_UL;
   procedure Corner_UR is
   begin
      Put('k');
   end Corner_UR;
   procedure Corner_LL is
   begin
      Put('m');
   end Corner_LL;

   procedure Corner_LR is
   begin
      Put('j');
   end Corner_LR;

   procedure Tee_Right is
   begin
      Put('t');
   end Tee_Right;
   procedure Tee_Left is
   begin
      Put('u');
   end Tee_Left;
   procedure Tee_Up is
   begin
      Put('v');
   end Tee_Up;
   procedure Tee_Down is
   begin
      Put('w');
   end Tee_Down;

   procedure Cross is
   begin
      Put('n');
   end Cross;

   procedure Vertical is
   begin
      Put('x');
   end Vertical;

   procedure Horizontal(Line : in Position := 3) is
   begin
    -- Convert Line Position value to
    --  characters 'o' through 's'
      Put(Character'Val(Character'Pos('n') + Line));
   end Horizontal;

begin -- Initialization

   Put(ASCII.ESC & "(B"); -- Set US char set as G0
   Put(ASCII.ESC & ")0"); -- Set line char set as G1

end Screen.Graphics;

[-- Attachment #3: Card for John J Cupak Jr --]
[-- Type: text/x-vcard, Size: 428 bytes --]

begin:          vcard
fn:             John J Cupak Jr
n:              Cupak Jr;John J
org:            Raytheon Systems Company
adr:            50 Apple Hill Road;;T3MN35;Tewksbury;MA;01876;USA
email;internet: John_J_Cupak@res.raytheon.com
title:          Software Engineering Instructor
tel;work:       978.858.1222
tel;fax:        978.858.4336
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard


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

* Re: Terminal IO, and menus
  1999-04-01  0:00   ` Juergen Pfeifer
@ 1999-04-02  0:00     ` Jerry van Dijk
  1999-04-02  0:00       ` dennison
  1999-04-04  0:00       ` Juergen Pfeifer
  0 siblings, 2 replies; 15+ messages in thread
From: Jerry van Dijk @ 1999-04-02  0:00 UTC (permalink / raw)


Juergen Pfeifer (Juergen.Pfeifer@t-online.de) wrote:

: Well, I'm very interested too. Of course I first suggest to port (n)curses
: to DOS and Win32, which will be more simple with one of the next releases
: of ncurses which redesigns some of the internals to base it on a "driver"
: logic. This will make it very fast and thin on memory mapped devices like
: DOS or Win32 consoles. For Ada you may then use the ncurses binding as
: your cross-platform console I/O package that works on DOS, OS/2, Win32
: and almost all UNIXes. 

Well, there is at least a pdcurses binding available, and I believe also
an ncurses (check the PAL). However, I think that however useful, ncurses
has a steep learning curve, if you do not know the curses library. SLANG
(also now available on more than linux) might be another option. In any
case the problem will be Ada-based documentation and some example programs.

--
-- Jerry van Dijk | Leiden, Holland
-- Team Ada       | jdijk@acm.org
-- see http://stad.dsl.nl/~jvandyk




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

* Re: Terminal IO, and menus
  1999-03-31  0:00   ` Tarjei Tj�stheim Jensen
@ 1999-04-02  0:00     ` Jerry van Dijk
  0 siblings, 0 replies; 15+ messages in thread
From: Jerry van Dijk @ 1999-04-02  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 246 bytes --]

Tarjei Tj�stheim Jensen (tarjei@online.no) wrote:

: PS.
: Your e-mail address does not work.

For the record, it is working again.

--
-- Jerry van Dijk | Leiden, Holland
-- Team Ada       | jdijk@acm.org
-- see http://stad.dsl.nl/~jvandyk




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

* Re: Terminal IO, and menus
  1999-04-02  0:00     ` Jerry van Dijk
@ 1999-04-02  0:00       ` dennison
  1999-04-03  0:00         ` Jerry van Dijk
  1999-04-04  0:00       ` Juergen Pfeifer
  1 sibling, 1 reply; 15+ messages in thread
From: dennison @ 1999-04-02  0:00 UTC (permalink / raw)


In article <F9KEC0.5q@jvdsys.stuyts.nl>,
  jerry@jvdsys.stuyts.nl (Jerry van Dijk) wrote:
> Well, there is at least a pdcurses binding available, and I believe also
> an ncurses (check the PAL). However, I think that however useful, ncurses
> has a steep learning curve, if you do not know the curses library. SLANG
> (also now available on more than linux) might be another option. In any

Another nifty idea would be a port of DEC's SMG library. SMG is much
higer-level than curses, and thus is a lot easier to get into.


T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Terminal IO, and menus
  1999-04-02  0:00       ` dennison
@ 1999-04-03  0:00         ` Jerry van Dijk
  1999-04-04  0:00           ` Tarjei Tj�stheim Jensen
  0 siblings, 1 reply; 15+ messages in thread
From: Jerry van Dijk @ 1999-04-03  0:00 UTC (permalink / raw)


dennison@telepath.com wrote:
: In article <F9KEC0.5q@jvdsys.stuyts.nl>,

:   jerry@jvdsys.stuyts.nl (Jerry van Dijk) wrote:
: > Well, there is at least a pdcurses binding available, and I believe also
: > an ncurses (check the PAL). However, I think that however useful, ncurses
: > has a steep learning curve, if you do not know the curses library. SLANG
: > (also now available on more than linux) might be another option. In any

: Another nifty idea would be a port of DEC's SMG library. SMG is much
: higer-level than curses, and thus is a lot easier to get into.

Ok, I will admit publically I have used VMS a lot (even to the point of having 
a DCL shell on my PC :-), so this sounds interesting. Any info on it ?
Like: is there free documentation and what the copyright status is ?

--
-- Jerry van Dijk | Leiden, Holland
-- Team Ada       | jdijk@acm.org
-- see http://stad.dsl.nl/~jvandyk




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

* Re: Terminal IO, and menus
  1999-04-03  0:00         ` Jerry van Dijk
@ 1999-04-04  0:00           ` Tarjei Tj�stheim Jensen
  0 siblings, 0 replies; 15+ messages in thread
From: Tarjei Tj�stheim Jensen @ 1999-04-04  0:00 UTC (permalink / raw)




Jerry van Dijk wrote:

> dennison@telepath.com wrote:
> : Another nifty idea would be a port of DEC's SMG library. SMG is much
> : higer-level than curses, and thus is a lot easier to get into.
>
> Ok, I will admit publically I have used VMS a lot (even to the point of having
> a DCL shell on my PC :-), so this sounds interesting. Any info on it ?
> Like: is there free documentation and what the copyright status is ?

SMG ocumentation: http://www.openvms.digital.com:8000/72final/5935/5935pro.html
General VMS documentation: http://www.openvms.digital.com:8000/

There is more than one thing to this. Not only will one have to create a SMG
clone, but also one needs to do something about terminal handling. E.g. something
that recognizes that <esc>[ and <csi> is the same. In short; this sounds
interesting.

For a reasonable vt terminal emulator have a look at kermit. There are versions of
it (at least for os/2) which can be used to test how well one is doing. I assume
that the DOS version is as good as the os/2 version as far as emulation goes.
Neither of them can do double width/height stuff.

It would be nice to be able to use VT terminals in 8 bit mode.


Greetings,







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

* Re: Terminal IO, and menus
  1999-04-02  0:00     ` Jerry van Dijk
  1999-04-02  0:00       ` dennison
@ 1999-04-04  0:00       ` Juergen Pfeifer
  1 sibling, 0 replies; 15+ messages in thread
From: Juergen Pfeifer @ 1999-04-04  0:00 UTC (permalink / raw)


Jerry van Dijk wrote:
> 
> Juergen Pfeifer (Juergen.Pfeifer@t-online.de) wrote:
> 
> : Well, I'm very interested too. Of course I first suggest to port (n)curses
> : to DOS and Win32, which will be more simple with one of the next releases
> : of ncurses which redesigns some of the internals to base it on a "driver"
> : logic. This will make it very fast and thin on memory mapped devices like
> : DOS or Win32 consoles. For Ada you may then use the ncurses binding as
> : your cross-platform console I/O package that works on DOS, OS/2, Win32
> : and almost all UNIXes.
> 
> Well, there is at least a pdcurses binding available, and I believe also
> an ncurses (check the PAL). However, I think that however useful, ncurses
> has a steep learning curve, if you do not know the curses library. SLANG
> (also now available on more than linux) might be another option. In any
> case the problem will be Ada-based documentation and some example programs.
> 
The PAL version of ncurses binding is completely out of date and I know that
because I'm the author:-) I agree that (n)curses is a  bit hard to learn,
but instead building the (n+1)th new Terminal I/O library or cloning SMG
I suggest to use the (thin) (n)curses binding and produce a thick OO-style
binding for Terminal I/O on top of it. (n)curses has the advantage of being
very portable and efficient.

Cheers
J�rgen




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

end of thread, other threads:[~1999-04-04  0:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-30  0:00 Terminal IO, and menus Heath Isler
1999-03-30  0:00 ` David C. Hoos, Sr.
1999-03-31  0:00 ` Matthew Heaney
1999-04-01  0:00   ` Heath Isler
1999-04-01  0:00     ` John J Cupak Jr
1999-04-01  0:00   ` Bill Eriksson
1999-03-31  0:00 ` Jerry van Dijk
1999-03-31  0:00   ` Tarjei Tj�stheim Jensen
1999-04-02  0:00     ` Jerry van Dijk
1999-04-01  0:00   ` Juergen Pfeifer
1999-04-02  0:00     ` Jerry van Dijk
1999-04-02  0:00       ` dennison
1999-04-03  0:00         ` Jerry van Dijk
1999-04-04  0:00           ` Tarjei Tj�stheim Jensen
1999-04-04  0:00       ` Juergen Pfeifer

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