beryx / text-io

A library for creating interactive console applications in Java
http://text-io.beryx.org/
Apache License 2.0
342 stars 45 forks source link

Add: CollectionInputReader #11

Closed zygimantus closed 6 years ago

zygimantus commented 6 years ago

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.

siordache commented 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.

zygimantus commented 6 years ago

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?

siordache commented 6 years ago

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.