Class InputSelection<E>


  • public class InputSelection<E>
    extends java.lang.Object
    Tabular selection with simple navigation. It displays a list of items in a table that can be paginated and navigated between using the arrow keys, numbers, pg-up, pg-down etc.
    
     {message}: [c=command, o=overview]
      1 {line 1}
      2 {line 2}
      3 {line 3}
     Your choice (1..N or c,o):
     

    When doing actions, it is possible to add extra output to the user, this will be printed below the `Your choice` line with a LinePrinter connected back to the InputSelection instance.

    By default there are no actions on the items, even exit is not provided. Actions are specified using a list of "commands", that each have an action, where each action has a Reaction. Note that any runtime exception thrown while handling an action exits the selection.

    • Constructor Detail

      • InputSelection

        public InputSelection​(Terminal terminal,
                              java.lang.String prompt,
                              java.util.List<E> entries,
                              java.util.List<InputSelection.Command<E>> commands,
                              InputSelection.EntryPrinter<E> printer)
        Create a selection instance.
        Parameters:
        terminal - The terminal to print to.
        prompt - The prompt to introduce the selection with.
        entries - The list of entries.
        commands - The list of commands.
        printer - The entry printer.
      • InputSelection

        public InputSelection​(Terminal terminal,
                              java.lang.String prompt,
                              java.util.List<E> entries,
                              java.util.List<InputSelection.Command<E>> commands,
                              InputSelection.EntryPrinter<E> printer,
                              int pageSize,
                              int pageMargin,
                              int lineWidth)
        Create a selection instance.
        Parameters:
        terminal - The terminal to print to.
        prompt - The prompt to introduce the selection with.
        entries - The list of entries.
        commands - The list of commands.
        printer - The entry printer.
        pageSize - The max number of entries per page.
        pageMargin - The number of entries above page size needed to trigger paging.
        lineWidth - The number of columns to print on.
      • InputSelection

        public InputSelection​(Terminal terminal,
                              java.lang.String prompt,
                              java.util.List<E> entries,
                              java.util.List<InputSelection.Command<E>> commands,
                              InputSelection.EntryPrinter<E> printer,
                              java.time.Clock clock,
                              int pageSize,
                              int pageMargin,
                              int lineWidth)
        Create a selection instance.
        Parameters:
        terminal - The terminal to print to.
        prompt - The prompt to introduce the selection with.
        entries - The list of entries.
        commands - The list of commands.
        printer - The entry printer.
        clock - The system clock.
        pageSize - The max number of entries per page.
        pageMargin - The number of entries above page size needed to trigger paging.
        lineWidth - The number of columns to print on.
    • Method Detail

      • select

        public E select()
      • select

        public E select​(E initial)