Package net.morimekta.console.terminal
Class InputSelection<E>
- java.lang.Object
-
- net.morimekta.console.terminal.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 theInputSelection
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 aReaction
. Note that any runtime exception thrown while handling an action exits the selection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
InputSelection.Action<E>
The command action interface.static class
InputSelection.Command<E>
Command.static interface
InputSelection.EntryPrinter<E>
Interface for the entry printer.static class
InputSelection.Reaction
Command reaction enum.
-
Constructor Summary
Constructors Constructor Description 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.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.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
select()
E
select(E initial)
-
-
-
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.
-
-