I'd like to use a question maker with some property then<div><br></div><div>  Â  Â  Â Val = xxx:ask_integer('What number do you want? ')</div><div><br></div><div>is defined in</div><div><br></div><div>  Â  Â  Â ask_integer(Question) -></div>
<div>  Â  Â  Â  Â  Â  Â Asker = ask([{'Format', fun my_format:is_num/1}]),</div><div>  Â  Â  Â  Â  Â  Â Asker(Question).</div><div><br></div><div>Another type of asker is like</div><div><br></div><div>  Â  Â  Â ask_enumerated(Question) -></div>
<div>  Â  Â  Â  Â  Â  Â Asker = ask([{'Format', fun my_format:in_enum/1}]),</div><div>  Â  Â  Â  Â  Â  Â Asker(Question).</div><div><br></div><div>The ask/1 is the core to serve customized dialogues.</div><div><br></div><div>
  Â  Â  Â ask(Options) -></div><div>  Â  Â  Â  Â  Â  fun (Question) -></div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â Reply = io:get_line(Question);</div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â case Reply of</div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â eof -> stop;</div>
<div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â {error, Reason} -> {error, Reason};</div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â "\n" -> stop;</div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Data -></div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  case proplists:lookup('Format', Options) of</div>
<div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â none -> {error, 'bad format'};</div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â {'Format', Func} -></div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Word = string:left(Data, string:len(Data)-1),</div>
<div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â case Func(Word) of</div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  {ok, Value) -> value;</div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  {error, Reason} -> {error, Reason}</div>
<div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â end</div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  end</div><div>  Â  Â  Â  Â  Â  Â  Â  Â  Â end</div><div>  Â  Â  Â  Â  Â  end.</div><div><br></div><div>Then format functions my_format:is_num/1, my_format:in_enum/1, and at el.</div>
<div>are written to check if a word fits the corresponding format. Parsers may be</div><div>used in a format function for complicate format.</div><div><br></div><div>Best Regards,</div><div>-yau</div><div><br><div class="gmail_quote">
On Mon, Feb 27, 2012 at 3:32 AM, Joe Armstrong <span dir="ltr"><<a href="mailto:erlang@gmail.com">erlang@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Has anybody written any code that makes inputting data from the shell<br>
less painful?<br>
<br>
Id like to say something like<br>
<br>
 Â  Val = xxx:read_integer([{prompt,'Port<br>
number:'},{expect,integer,1000,2000},{default,1234}, ....<br>
<br>
 I'd like to customize what happens if the user does not enter an<br>
integer etc. (ie ask again, abort, etc.)<br>
<br>
 Â also read_enumerated([....., {expect, ["foo","bar",friends"]} ,,,,<br>
<br>
 Â (this would only accept one of the three strings in the command and<br>
give me tab completion etc.)<br>
<br>
I'd like to make a text interface that asks questions, and takes<br>
reasonable actions if the user enters<br>
bad data, without writing zillions of lines of code. Any pointers?<br>
<br>
Cheers<br>
<br>
/Joe<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><br></div>Best Regards.<div><br></div><div>--- Y-H. H.</div><div><br></div><br>
</div>