From: Egil Harald Hoevik <egil.harald.hoevik@kongsberg.com>
Subject: Re: Automatic issue of carriage return
Date: 2000/11/22
Date: 2000-11-22T00:00:00+00:00 [thread overview]
Message-ID: <3A1BFB09.C79FAF2F@kongsberg.com> (raw)
In-Reply-To: 9mom1ts4v0uv6ff3bf0750p9jqe5kbaohd@4ax.com
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.
prev parent reply other threads:[~2000-11-22 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox