Closed zygimantus closed 6 years ago
Thanks @zygimantus ,
It is already possible to select a value from a list using the withNumberedPossibleValues method as shown below:
public void accept(TextIO textIO, RunnerData runnerData) {
TextTerminal<?> terminal = textIO.getTextTerminal();
String test = textIO.newStringInputReader()
.withNumberedPossibleValues(LIST)
.read("What element from list you want to choose?");
terminal.printf("\nYou chose %s", test);
textIO.dispose();
}
Other methods for selecting values from a list are: withPossibleValues
and withInlinePossibleValues
.
Usage examples (as Spock tests) can be found in TextIoReadSpec.groovy.
Nice, thanks for the information. I haven't noticed those methods. You should probably ignore this then. Btw, if a list is large it would be very handy to have an option to paginate it. What do you think - how hard or even would it be possible to do it in your lib?
Pagination is on my todo list, I also miss this feature. I want to find a way to seamlessly integrate it into the current API and at the same time to allow using advanced features such as read handlers and bookmarking for customizing the pagination for terminals with extended capabilities. I'm currently busy with the BootHub project (which, BTW, uses Text-IO to provide both a web interface and a CLI). But when I'm done with it I will take the time to implement the pagination.
It would be nice feature to have an option to select a value from a collection object. I have added this feature, maybe you will find it useful.