g_harrison@vger.nsu.edu ((George C. Harrison) Norfolk State University) (01/17/91)
In article <27954d2b.64e9@petunia.CalPoly.EDU>, ssenkere@polyslo.CalPoly.EDU (<Scimitar>) writes: > What I would like to know is... > > Is there a way to access the cursor keys in ADA. Let me re-phrase that. > Of course there IS a way... but with the standard packages provided... can > it be easily done. Is there something similiar to the PUT(ascii.bs); for > the backspace key....?? > > Also... Is there any commands in the standard packages to place the cursor ... Yes and No. ;-) These commands are machine/terminal dependent, but the following routines (and more) work on VT's: use ASCII; -- CLEAR SCREEN on VT100 terminals procedure CLS is begin PUT(ESC & "[H" & ESC & "[J"); end CLS; --GOTOXY moves the cursor to (X,Y), where X is the row value (0..24) and -- Y is the column value (0..80); procedure GOTOXY(ROW, COL : in INTEGER) is SLENGTH : constant POSITIVE := INTEGER'IMAGE(ROW)'LENGTH + INTEGER'IMAGE(COL )'LENGTH + 4; STR : STRING(1 .. SLENGTH) := ESC & "[" & INTEGER'IMAGE(ROW) & ";" & INTEGER'IMAGE(COL) & "H"; begin for I in 1 .. SLENGTH loop if STR(I) /= ' ' then PUT(STR(I)); end if; end loop; end GOTOXY; etc... -------------------------------------------------------------------------- -- George C. Harrison -------------- || -- Overworked, Underpaid, -------- ---|| Professor of Computer Science || -- Unappreciated, but enjoying --- ---|| Norfolk State University, ---- || -- it all. ----------------------- ---|| 2401 Corprew Avenue, Norfolk, Virginia 23504 ----------------------- ---|| INTERNET: g_harrison@vger.nsu.edu --------------------------------- -- || These are not necessarily the views of my employer, my family, or -- || even myself.
mfeldman@seas.gwu.edu (Michael Feldman) (01/18/91)
In article <27954d2b.64e9@petunia.CalPoly.EDU> ssenkere@polyslo.CalPoly.EDU (<Scimitar>) writes: > >Is there a way to access the cursor keys in ADA. Let me re-phrase that. >Of course there IS a way... but with the standard packages provided... can >it be easily done. Is there something similiar to the PUT(ascii.bs); for >the backspace key....?? There's nothing standard. Text_IO doesn't really provide this kind of stuff. If you are on a PC running Meridian Ada, say, I think they may have a package that does it. Have a look at their package "tty." > >Also... Is there any commands in the standard packages to place the cursor >at a specific spot on the screen? Like playing the cursor at the 10th >column, 10th row and then do a PUT at that spot. It is important not to >delete anything on the line previous to this 10th spot as well. (which is >why I ask about maybe the cursors being accessable) This is quite easy to do using ASCII characters. Assuming you have a VT100- compatible terminal (a PC with ANSI.SYS installed in CONFIG.SYS will do the same thing), here is a package to handle this. You can make whatever changes you need to make. Output is much easier than input! > By the way - getting a _single character_ from the keyboard is not part of Text_IO, which usually buffers input waiting for a CR. This has been discussed often on this group. Ada9x will, I presume, try to find a fix for this. ---- cut here for code ---- package VT100 is ---------------------------------------------------------- -- Procedures for drawing pictures of the solution on VDU. -- ClearScreen and SetCursorAt are device-specific ---------------------------------------------------------- SCREEN_DEPTH : constant INTEGER := 24; SCREEN_WIDTH : constant INTEGER := 80; subtype DEPTH is INTEGER range 1..SCREEN_DEPTH; subtype WIDTH is INTEGER range 1..SCREEN_WIDTH; procedure ClearScreen; procedure SetCursorAt( A: WIDTH; D : DEPTH); end VT100; with TEXT_IO; package body VT100 is package My_Int_IO is new Text_IO.Integer_IO(Integer); ---------------------------------------------------------- -- Procedures for drawing pictures on VT100 -- ClearScreen and SetCursorAt are terminal-specific ---------------------------------------------------------- procedure ClearScreen is begin Text_IO.PUT( ASCII.ESC & "[2J" ); end ClearScreen; procedure SetCursorAt(A: WIDTH; D : DEPTH) is begin Text_IO.NEW_LINE; -- the NEW_LINE clears the output buffer; most systems need this Text_IO.PUT( ASCII.ESC & "[" ); My_Int_IO.PUT( D, 1 ); Text_IO.PUT( ';' ); My_Int_IO.PUT( A, 1 ); Text_IO.PUT( 'f' ); end SetCursorAt; end VT100;
ae@sei.cmu.edu (Arthur Evans) (01/19/91)
Michael Feldman (mfeldman@seas.gwu.edu) says (in part): > By the way - getting a _single character_ from the keyboard is not > part of Text_IO, which usually buffers input waiting for a CR. Ada9x > will, I presume, try to find a fix for this. Requirement R4.6-A(1) requires improvement in interactive I/O. By way of example, it lists a few possible improvements; the Ada 9X Requirements Rationale (not yet published) will list more such candidates for improvement. The functionality referred to is included. Of course, we will not know what actually will be in 9X until the Mapping/Revision Team has done its work. Art Evans Software Engineering Institute Carnegie Mellon University