comp.lang.ada
 help / color / mirror / Atom feed
* Re: Automatic issue of carriage return
  2000-11-22  6:07 Automatic issue of carriage return mountainman
@ 2000-11-22  0:00 ` tmoran
  2000-11-22  0:00 ` Egil Harald Hoevik
  1 sibling, 0 replies; 3+ messages in thread
From: tmoran @ 2000-11-22  0:00 UTC (permalink / raw)


>I would like to recieve a user's input to a prompt and then
>automatically issue a CR or LF. so the user does not have to hit the
>enter key
  and won't have an opportunity to do a backspace and change his input.
Is that really for sure what you want?  If so, check out
Ada.Text_IO.Get_Immediate of Character.




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

* Re: Automatic issue of carriage return
  2000-11-22  6:07 Automatic issue of carriage return mountainman
  2000-11-22  0:00 ` tmoran
@ 2000-11-22  0:00 ` Egil Harald Hoevik
  1 sibling, 0 replies; 3+ messages in thread
From: Egil Harald Hoevik @ 2000-11-22  0:00 UTC (permalink / raw)


mountainman wrote:
> 
> Thanks for all that responded to my last message. I have another one
> for you all. It should be pretty simple for you ada guru's out there.
> I would like to recieve a user's input to a prompt and then
> automatically issue a CR or LF. so the user does not have to hit the
> enter key
> 
> Im using a subtype as variable (example)
> type continue_type is (y,n)
> package continue_IO is new text_io.enumeration_IO(continue_type);
> 
> continue_IO.get(flag);
> ????
> any help would be helpfull
> Thanks

In ada.text_io there is a procedure Get_Immediate, which gets one
character from the 
keyboard, and returns without you having to press enter. You could
perhaps create 
your own package, with a procedure doing the same for your enumeration
type by using this procedure.

	Example:

	with ada.text_io;

	procedure enumerate is
	
	generic
	   type Enum is (<>);
	  package my_enumeration_io is
	    package convert is new ada.text_io.enumeration_io(Enum);
	-- new procedure handling enumeration types
	    procedure my_get(Item : out Enum);
	  end my_enumeration_io; 

	  package body my_enumeration_io is
	    procedure my_get(Item : out Enum) is
	      input : character;
	      last : positive; -- dummy; we only handle single-value
enumerations
	    begin
	-- get one character from the keyboard with get_immediate
	      ada.text_io.get_immediate(input);
	-- convert the string to your enumeration type
	      convert.get(input & "", Item, last);
	    end my_get;
	  end my_enumeration_io;


Then this should work:

	 type continue_type is (y,n);
	 package continue_IO is new my_enumeration_IO(continue_type);
	 flag : continue_type;
	begin
	 continue_IO.my_get(flag);
	end enumerate;

This package has limits, of course.
In your case you have simple, single-character values in your
enumeration (y,n).
You would have to do some more work with enumerations of
multiple-character values (yes,no). If you need such functionality, mail
me, I'll see what I can do.

Note: If you type in a value not part of the enumeration (any other
character than y,n),
the program will raise ada.io_exceptions.data_error. So you should have
an exception handler that perhaps prompts the user again if he/she types
wrong.


~egilhh
-- 
"The world we have made as a result of the level of thinking
we have done this far, creates problems that we cannot solve
at the same level at which we created them."
Albert Einstein.




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

* Automatic issue of carriage return
@ 2000-11-22  6:07 mountainman
  2000-11-22  0:00 ` tmoran
  2000-11-22  0:00 ` Egil Harald Hoevik
  0 siblings, 2 replies; 3+ messages in thread
From: mountainman @ 2000-11-22  6:07 UTC (permalink / raw)


Thanks for all that responded to my last message. I have another one
for you all. It should be pretty simple for you ada guru's out there.
I would like to recieve a user's input to a prompt and then
automatically issue a CR or LF. so the user does not have to hit the
enter key

Im using a subtype as variable (example)
type continue_type is (y,n)
package continue_IO is new text_io.enumeration_IO(continue_type);

continue_IO.get(flag);
????
any help would be helpfull
Thanks



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

end of thread, other threads:[~2000-11-22  6:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-22  6:07 Automatic issue of carriage return mountainman
2000-11-22  0:00 ` tmoran
2000-11-22  0:00 ` Egil Harald Hoevik

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