comp.lang.ada
 help / color / mirror / Atom feed
* GOTOXY in Ada ?
@ 1994-12-07 12:36 Jan Ahlers
  1994-12-08 13:04 ` Philip Brashear
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jan Ahlers @ 1994-12-07 12:36 UTC (permalink / raw)


Hi all !

I know this is a rather simple question, but I'll ask it anyways ;-)

Is there an equivalent in Ada to the gotoxy command in Pascal (-> put the
cursor at column x, row y) ? Answers would be greatly appreciated !

Best regards,
Jan

Jan C. Ahlers =============================================== Phone: 0251/89215
Bentelerstr. 8           CARPE NOCTEM !       
48149 Muenster
GERMANY ===================================== email: Jan.Ahlers@uni-muenster.de




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

* Re: GOTOXY in Ada ?
  1994-12-07 12:36 GOTOXY in Ada ? Jan Ahlers
@ 1994-12-08 13:04 ` Philip Brashear
  1994-12-09  4:19   ` Dave Retherford
  1994-12-09  2:59 ` Michael Feldman
  1994-12-09 15:22 ` Do-While Jones
  2 siblings, 1 reply; 9+ messages in thread
From: Philip Brashear @ 1994-12-08 13:04 UTC (permalink / raw)


In article <3c4a9a$1lts@obelix.uni-muenster.de> ahlersj@comix.uni-muenster.de (Jan Ahlers) writes:
>
>Is there an equivalent in Ada to the gotoxy command in Pascal (-> put the
>cursor at column x, row y) ? Answers would be greatly appreciated !
>

Jan, let me point out that Pascal has no such command either.  The particular
Pascal implementation (compiler/environment/libraries) that you are using is
kind enough to supply you with cursor movement operations.  You must realize
that such things are completely dependent on the kind of display device you
are using.  Since Pascal is intended to be portable, the language definition
doesn't specify such things.

That being said, it should be obvious that Ada doesn't specify cursor control
either.  However, it's simple enough to write your own, provided that you can
track down the appropriate "escape sequences" that make your terminal do what
you want.  Just do text_io "put" to the screen, sending a string like

       ASCII.ESC & "[6;14H"

If you're using an ANSI standard terminal, will send the cursor to line 6,
column 14.

DISCLAIMER:  I didn't try this precisely -- I depended on memory and an out-
of-date reference manual for a particular terminal.  Nevertheless, the idea
works.  I've used it several times.

Good hunting!

Phil Brashear
CTA INCORPORATED





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

* Re: GOTOXY in Ada ?
  1994-12-07 12:36 GOTOXY in Ada ? Jan Ahlers
  1994-12-08 13:04 ` Philip Brashear
@ 1994-12-09  2:59 ` Michael Feldman
  1994-12-09 15:22 ` Do-While Jones
  2 siblings, 0 replies; 9+ messages in thread
From: Michael Feldman @ 1994-12-09  2:59 UTC (permalink / raw)


In article <3c4a9a$1lts@obelix.uni-muenster.de>,
Jan Ahlers <ahlersj@comix.uni-muenster.de> wrote:
>Hi all !
>
>I know this is a rather simple question, but I'll ask it anyways ;-)
>
>Is there an equivalent in Ada to the gotoxy command in Pascal (-> put the
>cursor at column x, row y) ? Answers would be greatly appreciated !

gotoxy is in no way a Pascal command. Some implementers (e.g. Borland)
put it in as a predefined procedure, but it is certainly not part of
the language. It is also not part of Ada, but it's quite easy to do
with a small package. This package assumes a vt100-ish terminal,
such as ansi.sys on your PC.

This package will get you started; you can add terminal capabilities
as you choose. 

Mike Feldman

--- cut here ---

-- spec
PACKAGE Screen IS

-- Procedures for drawing pictures on ANSI Terminal Screen
-- Michael Feldman, The George Washington University, Washington, DC

  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;   

-- body

WITH Text_IO;
PACKAGE BODY Screen IS

-- Michael Feldman, The George Washington University, Washington, DC

  PACKAGE My_Int_IO IS NEW Text_IO.Integer_IO (Num => Integer);

-- Procedures for drawing pictures on ANSI Terminal Screen
-- These procedures will work correctly only if the actual
-- terminal is ANSI compatible. ANSI.SYS on a DOS machine
-- will suffice.

  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;  -- this avoids OS terminal buffer overflow
    Text_IO.Put (Item => ASCII.ESC);
    Text_IO.Put ("[");
    My_Int_IO.Put (Item => To.Row, Width => 1);
    Text_IO.Put (Item => ';');
    My_Int_IO.Put (Item => To.Column, Width => 1);
    Text_IO.Put (Item => 'f');
  END MoveCursor;  

END Screen;



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

* Re: GOTOXY in Ada ?
  1994-12-08 13:04 ` Philip Brashear
@ 1994-12-09  4:19   ` Dave Retherford
  1994-12-12  8:45     ` Keith Thompson
  1994-12-13 10:09     ` Andre Spiegel
  0 siblings, 2 replies; 9+ messages in thread
From: Dave Retherford @ 1994-12-09  4:19 UTC (permalink / raw)


In article <1994Dec8.080423.3368@sei.cmu.edu>,
Philip Brashear <brashear@ajpo.sei.cmu.edu> wrote:
> In article <3c4a9a$1lts@obelix.uni-muenster.de> ahlersj@comix.uni-muenster.de (Jan Ahlers) writes:
> >
> >Is there an equivalent in Ada to the gotoxy command in Pascal (-> put the
> >cursor at column x, row y) ? Answers would be greatly appreciated !
> >
> 
> Jan, let me point out that Pascal has no such command either.  The particular
> Pascal implementation (compiler/environment/libraries) that you are using is
> kind enough to supply you with cursor movement operations.  You must realize
> that such things are completely dependent on the kind of display device you
> are using.  Since Pascal is intended to be portable, the language definition
> doesn't specify such things.
> 
> That being said, it should be obvious that Ada doesn't specify cursor control
> either.  However, it's simple enough to write your own, provided that you can
> track down the appropriate "escape sequences" that make your terminal do what
> you want.  Just do text_io "put" to the screen, sending a string like
> 
>        ASCII.ESC & "[6;14H"
> 
> If you're using an ANSI standard terminal, will send the cursor to line 6,
> column 14.
> 
> DISCLAIMER:  I didn't try this precisely -- I depended on memory and an out-
> of-date reference manual for a particular terminal.  Nevertheless, the idea
> works.  I've used it several times.
> 
> Good hunting!
> 
> Phil Brashear
> CTA INCORPORATED
> 
> 

Or you could 'roll your own' version:

--------

package cursor_control is

   procedure gotoxy(x : in positive_count, y : in positive_count);

end cursor_control;


with text_io;
package body cursor_control is

   procedure gotoxy(x : in positive_count, y : in positive_count) is
   begin

      text_io.set_col(to => x);
      text_io.set_line(to => y);

   end gotoxy;

end cursor_control;

----------

Of course this will only give you cursor control at a character 
positioning level.  Also, this works with whatever the standard output 
file (or rather default one) which in most cases will be the screen (at 
least it is on the compilers I use).

Hope this helps.

Dave.


-- 
 _________________________________________________________________________
| Dave Retherford                      |"Remember this:  the guy down     |
|  Daver@Neosoft.com  or:              | there kissing your butt could be | 
|  Dave_Retherford@hso.link.com [work] | just as easily biting it too."   |
|                                      |       -- Forestt Gump            |
|______________________________________|__________________________________|



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

* Re: GOTOXY in Ada ?
  1994-12-07 12:36 GOTOXY in Ada ? Jan Ahlers
  1994-12-08 13:04 ` Philip Brashear
  1994-12-09  2:59 ` Michael Feldman
@ 1994-12-09 15:22 ` Do-While Jones
  1994-12-10 21:00   ` Michael Feldman
  2 siblings, 1 reply; 9+ messages in thread
From: Do-While Jones @ 1994-12-09 15:22 UTC (permalink / raw)


In article <3c4a9a$1lts@obelix.uni-muenster.de> ahlersj@comix.uni-muenster.de (Jan Ahlers) writes:

>
>Is there an equivalent in Ada to the gotoxy command in Pascal (-> put the
>cursor at column x, row y) ? Answers would be greatly appreciated !
>

Sort of.  It isn't a part of the language, but it is easily done using 
the VIRTUAL_TERMINAL package.

VIRTUAL_TERMINAL.Move_Cursor_To(LINE => Y, COL => X);

FAQ: Where do I find the VIRTUAL_TERMINAL package?
It is in the book Ada in Action.

FAQ: But isn't Ada in Action out of print?
Yes, but it about to appear on the net in electronic form Real Soon Now.
Watch this space for an announcment.



-- 
            +--------------------------------+
            |    Know                 Ada    |
            |        [Ada's Portrait]        |
            |    Will              Travel    |
            | wire do_while@ridgecrest.ca.us |
            +--------------------------------+



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

* Re: GOTOXY in Ada ?
  1994-12-09 15:22 ` Do-While Jones
@ 1994-12-10 21:00   ` Michael Feldman
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Feldman @ 1994-12-10 21:00 UTC (permalink / raw)


In article <D0JupK.L0p@ridgecrest.ca.us>,
Do-While Jones <do_while@owens.ridgecrest.ca.us> wrote:

[snip]

>FAQ: But isn't Ada in Action out of print?
>Yes, but it about to appear on the net in electronic form Real Soon Now.
>Watch this space for an announcment.

Excellent! This is good stuff, Ada fans.

Mike Feldman

PS - it's really nice to see you on the net, Do-While.



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

* Re: GOTOXY in Ada ?
  1994-12-09  4:19   ` Dave Retherford
@ 1994-12-12  8:45     ` Keith Thompson
  1994-12-13 10:09     ` Andre Spiegel
  1 sibling, 0 replies; 9+ messages in thread
From: Keith Thompson @ 1994-12-12  8:45 UTC (permalink / raw)


In <3c8lsq$rhu@Starbase.NeoSoft.COM> daver@Starbase.NeoSoft.COM (Dave Retherford) writes:
> Or you could 'roll your own' version:
> 
> --------
> 
> package cursor_control is
>    procedure gotoxy(x : in positive_count, y : in positive_count);
> end cursor_control;
> 
> with text_io;
> package body cursor_control is
> 
>    procedure gotoxy(x : in positive_count, y : in positive_count) is
>    begin
>       text_io.set_col(to => x);
>       text_io.set_line(to => y);
>    end gotoxy;
> 
> end cursor_control;

Sorry, this won't work.  The Set_Col and Set_Line routines won't move the
cursor to a previous line or to a previous column on the current line.
For example, if the current column number is 20, Text_IO.Set_Col(10) will
call New_Line and then output 10 spaces; likewise, Set_Line calls New_Page
if necessary (which may or may not clear the screen; typically it won't).

Note that some Unix Ada compilers provide an interface to the curses
library.

-- 
Keith Thompson (The_Other_Keith)  kst@alsys.com
TeleSoft^H^H^H^H^H^H^H^H Alsys, Inc.
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
/user/kst/.signature: I/O error (core dumped)



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

* Re: GOTOXY in Ada ?
  1994-12-09  4:19   ` Dave Retherford
  1994-12-12  8:45     ` Keith Thompson
@ 1994-12-13 10:09     ` Andre Spiegel
  1 sibling, 0 replies; 9+ messages in thread
From: Andre Spiegel @ 1994-12-13 10:09 UTC (permalink / raw)


Dave Retherford writes:

  [ suggestion to position the cursor using Text_IO.Set_Col, Set_Line ]

> Of course this will only give you cursor control at a character 
> positioning level.  Also, this works with whatever the standard output 
> file (or rather default one) which in most cases will be the screen (at 
> least it is on the compilers I use).

I wonder if what you say here is clear enough; let me stress that this
is almost certainly not what the original poster wanted, because
Set_Col and Set_Line can only *advance* the cursor, by putting out
whitespace (Blanks and Newlines). So for example, if you want to write
at column 30, but the current "cursor column" happens to be 40, then 

    Set_Col (30);

will move the "cursor" to column 30 on the *next* line. Trying to set
the line number to a value less than the current one causes a form
feed, i.e. a new page is started, and then the "cursor" is moved to
the given line, by putting out Newlines.

Although this works with any text file, I haven't seen any useful
application of it, yet. (Set_Col can be used to create columns of
numbers, or the like; advancing to the next line is sensible if an
entry happens to be wider than the space allowed; but I can hardly 
imagine what Set_Line could be good for.) I still remember my first
Ada program, in which I tried to move the cursor with Text_IO. The
output looked very strange... :-)

So, actual cursor positioning has to be done using the previously
suggested method (escape sequences to the terminal). The sequence
given by Phil Brashear is correct, BTW: 

  Put (Ascii.Esc & "[" & Line_Number_As_String & ";" 
                       & Column_Number_As_String & "H");

Note, however, that the output is (generally?) not flushed if you do
this. Text_IO only flushes after a Newline (and in some other
situations). If you want to see the output immediately, you also have
to look out for a flush procedure -- which is not part of Text_IO, and
can only be implemented "foreignly" (ioctl, for example). Some
compiler vendors supply such a procedure. There also is one the
IEEE Posix binding.

--
Andre Spiegel                     |  This life is a test. It is only a test.
                                  |  Had this been an actual life, you would
University of Stuttgart, Germany  |  have received further instructions as to
Computer Science                  |  where to go and what to do.
                                                            -- Author unknown

	   e-mail: spiegel@bruessel.informatik.uni-stuttgart.de








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

* RE: GOTOXY IN ADA ?
@ 1994-12-20  2:06 Michael Hagerty
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Hagerty @ 1994-12-20  2:06 UTC (permalink / raw)


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

On 12-12-94, Keith Thompson responded to Dave Retherford:

KT> Sorry, this won't work.  The Set_Col and Set_Line routines won't move the
  > cursor to a previous line or to a previous column on the current line.
  > For example, if the current column number is 20, Text_IO.Set_Col(10) will
  > call New_Line and then output 10 spaces; likewise, Set_Line calls New_Page
  > if necessary (which may or may not clear the screen; typically it won't).

An easier method might be to get the AdaSAGE library for your library.  There
is a gotoxy equivalent routine in there, although it does assume that your
screen is only 2-digit columns wide.  I fixed it for ours and it handles
screens up to 999 columns wide.

Regards, Mikey <michael.hagerty@nitelog.com>
PGP Fingerprint =  56 12 CF A9 0E 53 A4 C4  49 F2 AF E7 F1 D3 47 5F
---
 � MR/2 #63 � Crusoe got everything done by Friday.  Can you?



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

end of thread, other threads:[~1994-12-20  2:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-12-20  2:06 GOTOXY IN ADA ? Michael Hagerty
  -- strict thread matches above, loose matches on Subject: below --
1994-12-07 12:36 GOTOXY in Ada ? Jan Ahlers
1994-12-08 13:04 ` Philip Brashear
1994-12-09  4:19   ` Dave Retherford
1994-12-12  8:45     ` Keith Thompson
1994-12-13 10:09     ` Andre Spiegel
1994-12-09  2:59 ` Michael Feldman
1994-12-09 15:22 ` Do-While Jones
1994-12-10 21:00   ` Michael Feldman

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