consoleui icon indicating copy to clipboard operation
consoleui copied to clipboard

Getting Input Values

Open diagrammer opened this issue 4 years ago • 3 comments

Hey,

I am making use of this project as it is a perfect temporary front end for the program I am working on : I could be being missing something, but in the result map in Basic.java, there does not seem to be a way of getting at the user input easily.

All object values are of the type of the marker interface PromptResultItemIF, and each kind of PromptResultItemIF, has it's own string type implementation.

I wonder if it would be worth adding a getValues() method which returns a new line separated list of values?

diagrammer avatar Jul 04 '20 08:07 diagrammer

Hi. Good point, but I don't see an easy way to have a result type which is suitable for all items. Let's figure out, what the result can be for the different prompt types:

  • A getValues() method for the InputPrompt may return a String.
  • A ListPrompt a getValue() method can return a String with the selected items key
  • A ChoicePrompt can return a String with the selected items key
  • A ConfirmPrompt can return a String with 'true' or 'false' or a boolean
  • A CheckboxPrompt needs to return a variable number of values. This can be an array of strings or a value separated string with all the choices.

OK. Most of the prompt elements can return a simple string. But CheckboxPrompt is different. How exactly would a getValues() method look like, especially the return type?

awegmann avatar Jul 07 '20 19:07 awegmann

Maybe a 'Result' object which contains two things:

(1) An enum representing the type of prompt (ListPrompt, InputPrompt etc)

(2) A List<String> which contains as many String values as necessary.

Just an inital thought.

diagrammer avatar Jul 07 '20 21:07 diagrammer

how about adding some .as(Class type) to allow you to map to the type of results you want/expect ?

.as(ChceckboxPrompt.class).get.. which if the type matches just return directly or otherwise do a best guess on mapping from one to the other and in case there is a bad loss throw execption.

That would at least give a (more) type safe interface.

maxandersen avatar Aug 11 '20 09:08 maxandersen