keyMap = new KeyMap<>();
+ bindKeys(keyMap);
+ while (true) {
+ refreshDisplay(selectRow, selected);
+ Operation op = bindingReader.readBinding(keyMap);
+ switch (op) {
+ case FORWARD_ONE_LINE:
+ selectRow = nextRow(selectRow, firstItemRow, items);
+ break;
+ case BACKWARD_ONE_LINE:
+ selectRow = prevRow(selectRow, firstItemRow, items);
+ break;
+ case TOGGLE:
+ if (selected.contains(
+ items.get(selectRow - firstItemRow).getName())) {
+ selected.remove(items.get(selectRow - firstItemRow).getName());
+ } else {
+ selected.add(items.get(selectRow - firstItemRow).getName());
+ }
+ break;
+ case EXIT:
+ return new CheckboxResult(selected);
+ }
+ }
+ }
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/CheckboxResult.java b/console-ui/src/main/java/org/jline/consoleui/prompt/CheckboxResult.java
new file mode 100644
index 00000000..fd1b8046
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/CheckboxResult.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+import java.util.Set;
+
+/**
+ * Result of a checkbox choice. CheckboxResult contains a {@link java.util.Set} with the
+ * IDs of the selected checkbox items.
+ *
+ * User: Andreas Wegmann
+ * Date: 03.02.16
+ */
+public class CheckboxResult implements PromptResultItemIF {
+ Set selectedIds;
+
+ /**
+ * Default Constructor.
+ * @param selectedIds Selected IDs.
+ */
+ public CheckboxResult(Set selectedIds) {
+ this.selectedIds = selectedIds;
+ }
+
+ /**
+ * Returns the set with the IDs of selected checkbox items.
+ *
+ * @return set with IDs
+ */
+ public Set getSelectedIds() {
+ return selectedIds;
+ }
+
+ public String getResult() {
+ return selectedIds.toString();
+ }
+
+ @Override
+ public String toString() {
+ return "CheckboxResult{" + "selectedIds=" + selectedIds + '}';
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/ConfirmResult.java b/console-ui/src/main/java/org/jline/consoleui/prompt/ConfirmResult.java
new file mode 100644
index 00000000..c630832f
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/ConfirmResult.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+import org.jline.consoleui.elements.ConfirmChoice;
+
+/**
+ * Result of a confirmation choice. Holds a single value of 'yes' or 'no'
+ * from enum {@link ConfirmChoice.ConfirmationValue}.
+ *
+ * User: Andreas Wegmann
+ * Date: 03.02.16
+ */
+public class ConfirmResult implements PromptResultItemIF {
+ ConfirmChoice.ConfirmationValue confirmed;
+
+ /**
+ * Default constructor.
+ *
+ * @param confirm the result value to hold.
+ */
+ public ConfirmResult(ConfirmChoice.ConfirmationValue confirm) {
+ this.confirmed = confirm;
+ }
+
+ /**
+ * Returns the confirmation value.
+ * @return confirmation value.
+ */
+ public ConfirmChoice.ConfirmationValue getConfirmed() {
+ return confirmed;
+ }
+
+ public String getResult() {
+ return confirmed.toString();
+ }
+
+ @Override
+ public String toString() {
+ return "ConfirmResult{" + "confirmed=" + confirmed + '}';
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/ConsolePrompt.java b/console-ui/src/main/java/org/jline/consoleui/prompt/ConsolePrompt.java
new file mode 100644
index 00000000..7a740f5b
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/ConsolePrompt.java
@@ -0,0 +1,275 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import org.jline.builtins.Styles;
+import org.jline.consoleui.elements.*;
+import org.jline.consoleui.elements.items.ConsoleUIItemIF;
+import org.jline.consoleui.elements.items.impl.ChoiceItem;
+import org.jline.consoleui.prompt.AbstractPrompt.*;
+import org.jline.consoleui.prompt.builder.PromptBuilder;
+import org.jline.reader.LineReader;
+import org.jline.terminal.Attributes;
+import org.jline.terminal.Terminal;
+import org.jline.utils.*;
+
+/**
+ * ConsolePrompt encapsulates the prompting of a list of input questions for the user.
+ *
+ * @author Matti Rinta-Nikkola
+ */
+public class ConsolePrompt {
+ private final LineReader reader;
+ private final Terminal terminal;
+ private final UiConfig config;
+
+ /**
+ *
+ * @param terminal the terminal.
+ */
+ public ConsolePrompt(Terminal terminal) {
+ this(null, terminal, new UiConfig());
+ }
+ /**
+ *
+ * @param terminal the terminal.
+ * @param config ConsolePrompt cursor pointer and checkbox configuration
+ */
+ public ConsolePrompt(Terminal terminal, UiConfig config) {
+ this(null, terminal, config);
+ }
+ /**
+ *
+ * @param reader the lineReader.
+ * @param terminal the terminal.
+ * @param config ConsolePrompt cursor pointer and checkbox configuration
+ */
+ public ConsolePrompt(LineReader reader, Terminal terminal, UiConfig config) {
+ this.terminal = terminal;
+ this.config = config;
+ this.reader = reader;
+ if (reader != null) {
+ Map options = new HashMap<>();
+ for (LineReader.Option option : LineReader.Option.values()) {
+ options.put(option, reader.isSet(option));
+ }
+ config.setReaderOptions(options);
+ }
+ }
+
+ /**
+ * Prompt a list of choices (questions). This method takes a list of promptable elements, typically
+ * created with {@link PromptBuilder}. Each of the elements is processed and the user entries and
+ * answers are filled in to the result map. The result map contains the key of each promptable element
+ * and the user entry as an object implementing {@link PromptResultItemIF}.
+ *
+ * @param promptableElementList the list of questions / prompts to ask the user for.
+ * @return a map containing a result for each element of promptableElementList
+ * @throws IOException may be thrown by terminal
+ */
+ public Map prompt(List promptableElementList) throws IOException {
+ return prompt(new ArrayList<>(), promptableElementList);
+ }
+ /**
+ * Prompt a list of choices (questions). This method takes a list of promptable elements, typically
+ * created with {@link PromptBuilder}. Each of the elements is processed and the user entries and
+ * answers are filled in to the result map. The result map contains the key of each promptable element
+ * and the user entry as an object implementing {@link PromptResultItemIF}.
+ *
+ * @param header info to be displayed before first prompt.
+ * @param promptableElementList the list of questions / prompts to ask the user for.
+ * @return a map containing a result for each element of promptableElementList
+ * @throws IOException may be thrown by terminal
+ */
+ public Map prompt(
+ List header, List promptableElementList) throws IOException {
+ Attributes attributes = terminal.enterRawMode();
+ try {
+ terminal.puts(InfoCmp.Capability.enter_ca_mode);
+ terminal.puts(InfoCmp.Capability.keypad_xmit);
+ terminal.writer().flush();
+
+ Map resultMap = new HashMap<>();
+
+ for (PromptableElementIF pe : promptableElementList) {
+ AttributedStringBuilder message = new AttributedStringBuilder();
+ message.style(config.style(".pr")).append("? ");
+ message.style(config.style(".me")).append(pe.getMessage()).append(" ");
+ AttributedStringBuilder asb = new AttributedStringBuilder();
+ asb.append(message);
+ asb.style(AttributedStyle.DEFAULT);
+ PromptResultItemIF result;
+ if (pe instanceof ListChoice) {
+ ListChoice lc = (ListChoice) pe;
+ result = ListChoicePrompt.getPrompt(
+ terminal, header, asb.toAttributedString(), lc.getListItemList(), config)
+ .execute();
+ } else if (pe instanceof InputValue) {
+ InputValue ip = (InputValue) pe;
+ if (ip.getDefaultValue() != null) {
+ asb.append("(").append(ip.getDefaultValue()).append(") ");
+ }
+ result = InputValuePrompt.getPrompt(reader, terminal, header, asb.toAttributedString(), ip, config)
+ .execute();
+ } else if (pe instanceof ExpandableChoice) {
+ ExpandableChoice ec = (ExpandableChoice) pe;
+ asb.append("(");
+ for (ConsoleUIItemIF item : ec.getChoiceItems()) {
+ if (item instanceof ChoiceItem) {
+ ChoiceItem ci = (ChoiceItem) item;
+ if (ci.isSelectable()) {
+ asb.append(ci.isDefaultChoice() ? Character.toUpperCase(ci.getKey()) : ci.getKey());
+ }
+ }
+ }
+ asb.append("h) ");
+ try {
+ result = ExpandableChoicePrompt.getPrompt(
+ terminal, header, asb.toAttributedString(), ec, config)
+ .execute();
+ } catch (ExpandableChoiceException e) {
+ result = ListChoicePrompt.getPrompt(
+ terminal, header, message.toAttributedString(), ec.getChoiceItems(), config)
+ .execute();
+ }
+ } else if (pe instanceof Checkbox) {
+ Checkbox cb = (Checkbox) pe;
+ result = CheckboxPrompt.getPrompt(terminal, header, message.toAttributedString(), cb, config)
+ .execute();
+ } else if (pe instanceof ConfirmChoice) {
+ ConfirmChoice cc = (ConfirmChoice) pe;
+ if (cc.getDefaultConfirmation() == null) {
+ asb.append(config.resourceBundle().getString("confirmation_without_default"));
+ } else if (cc.getDefaultConfirmation() == ConfirmChoice.ConfirmationValue.YES) {
+ asb.append(config.resourceBundle().getString("confirmation_yes_default"));
+ } else {
+ asb.append(config.resourceBundle().getString("confirmation_no_default"));
+ }
+ asb.append(" ");
+ result = ConfirmPrompt.getPrompt(terminal, header, asb.toAttributedString(), cc, config)
+ .execute();
+ } else {
+ throw new IllegalArgumentException("wrong type of promptable element");
+ }
+ String resp = result.getResult();
+ if (result instanceof ConfirmResult) {
+ ConfirmResult cr = (ConfirmResult) result;
+ if (cr.getConfirmed() == ConfirmChoice.ConfirmationValue.YES) {
+ resp = config.resourceBundle().getString("confirmation_yes_answer");
+ } else {
+ resp = config.resourceBundle().getString("confirmation_no_answer");
+ }
+ }
+ message.style(config.style(".an")).append(resp);
+ header.add(message.toAttributedString());
+ resultMap.put(pe.getName(), result);
+ }
+ return resultMap;
+ } finally {
+ terminal.setAttributes(attributes);
+ terminal.puts(InfoCmp.Capability.exit_ca_mode);
+ terminal.puts(InfoCmp.Capability.keypad_local);
+ terminal.writer().flush();
+ for (AttributedString as : header) {
+ as.println(terminal);
+ }
+ terminal.writer().flush();
+ }
+ }
+
+ /**
+ * Creates a {@link PromptBuilder}.
+ *
+ * @return a new prompt builder object.
+ */
+ public PromptBuilder getPromptBuilder() {
+ return new PromptBuilder();
+ }
+
+ /**
+ * ConsoleUI configuration: colors, cursor pointer and selected/unselected/unavailable boxes.
+ * ConsoleUI colors are configurable using UI_COLORS environment variable
+ */
+ public static class UiConfig {
+ static final String DEFAULT_UI_COLORS = "cu=36:be=32:bd=37:pr=32:me=1:an=36:se=36:cb=100";
+ static final String UI_COLORS = "UI_COLORS";
+ private final AttributedString indicator;
+ private final AttributedString uncheckedBox;
+ private final AttributedString checkedBox;
+ private final AttributedString unavailable;
+ private final StyleResolver resolver;
+ private final ResourceBundle resourceBundle;
+ private Map readerOptions = new HashMap<>();
+
+ public UiConfig() {
+ this(null, null, null, null);
+ }
+
+ public UiConfig(String indicator, String uncheckedBox, String checkedBox, String unavailable) {
+ String uc = System.getenv(UI_COLORS);
+ String uiColors = uc != null && Styles.isStylePattern(uc) ? uc : DEFAULT_UI_COLORS;
+ this.resolver = resolver(uiColors);
+ this.indicator = toAttributedString(resolver, (indicator != null ? indicator : ">"), ".cu");
+ this.uncheckedBox = toAttributedString(resolver, (uncheckedBox != null ? uncheckedBox : " "), ".be");
+ this.checkedBox = toAttributedString(resolver, (checkedBox != null ? checkedBox : "x "), ".be");
+ this.unavailable = toAttributedString(resolver, (unavailable != null ? unavailable : "- "), ".bd");
+ this.resourceBundle = ResourceBundle.getBundle("consoleui_messages");
+ }
+
+ private static AttributedString toAttributedString(StyleResolver resolver, String string, String styleKey) {
+ AttributedStringBuilder asb = new AttributedStringBuilder();
+ asb.style(resolver.resolve(styleKey));
+ asb.append(string);
+ return asb.toAttributedString();
+ }
+
+ public AttributedString indicator() {
+ return indicator;
+ }
+
+ public AttributedString uncheckedBox() {
+ return uncheckedBox;
+ }
+
+ public AttributedString checkedBox() {
+ return checkedBox;
+ }
+
+ public AttributedString unavailable() {
+ return unavailable;
+ }
+
+ public AttributedStyle style(String key) {
+ return resolver.resolve(key);
+ }
+
+ public ResourceBundle resourceBundle() {
+ return resourceBundle;
+ }
+
+ protected void setReaderOptions(Map readerOptions) {
+ this.readerOptions = readerOptions;
+ }
+
+ public Map readerOptions() {
+ return readerOptions;
+ }
+
+ private static StyleResolver resolver(String style) {
+ Map colors = Arrays.stream(style.split(":"))
+ .collect(Collectors.toMap(
+ s -> s.substring(0, s.indexOf('=')), s -> s.substring(s.indexOf('=') + 1)));
+ return new StyleResolver(colors::get);
+ }
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/ExpandableChoiceResult.java b/console-ui/src/main/java/org/jline/consoleui/prompt/ExpandableChoiceResult.java
new file mode 100644
index 00000000..0f1423a8
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/ExpandableChoiceResult.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+/**
+ * Result of an expandable choice. ExpandableChoiceResult contains a String with the
+ * IDs of the selected item.
+ *
+ * User: Andreas Wegmann
+ * Date: 03.02.16
+ */
+public class ExpandableChoiceResult implements PromptResultItemIF {
+ String selectedId;
+
+ /**
+ * Default constructor.
+ *
+ * @param selectedId the selected id
+ */
+ public ExpandableChoiceResult(String selectedId) {
+ this.selectedId = selectedId;
+ }
+
+ /**
+ * Returns the selected id.
+ *
+ * @return selected id.
+ */
+ public String getSelectedId() {
+ return selectedId;
+ }
+
+ public String getResult() {
+ return selectedId;
+ }
+
+ @Override
+ public String toString() {
+ return "ExpandableChoiceResult{" + "selectedId='" + selectedId + '\'' + '}';
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/InputResult.java b/console-ui/src/main/java/org/jline/consoleui/prompt/InputResult.java
new file mode 100644
index 00000000..d34a8ff3
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/InputResult.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+/**
+ *
+ * User: Andreas Wegmann
+ * Date: 03.02.16
+ */
+public class InputResult implements PromptResultItemIF {
+ private final String input;
+
+ public InputResult(String input) {
+ this.input = input;
+ }
+
+ public String getInput() {
+ return input;
+ }
+
+ public String getResult() {
+ return input;
+ }
+
+ @Override
+ public String toString() {
+ return "InputResult{" + "input='" + input + '\'' + '}';
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/ListResult.java b/console-ui/src/main/java/org/jline/consoleui/prompt/ListResult.java
new file mode 100644
index 00000000..eabb2ebb
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/ListResult.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+/**
+ * Result of a list choice. Holds the id of the selected item.
+ *
+ * Created by Andreas Wegmann on 03.02.16.
+ */
+public class ListResult implements PromptResultItemIF {
+
+ String selectedId;
+
+ /**
+ * Returns the ID of the selected item.
+ *
+ * @return id of selected item
+ */
+ public String getSelectedId() {
+ return selectedId;
+ }
+
+ public String getResult() {
+ return selectedId;
+ }
+
+ /**
+ * Default constructor.
+ *
+ * @param selectedId id of selected item.
+ */
+ public ListResult(String selectedId) {
+ this.selectedId = selectedId;
+ }
+
+ @Override
+ public String toString() {
+ return "ListResult{" + "selectedId='" + selectedId + '\'' + '}';
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/PromptResultItemIF.java b/console-ui/src/main/java/org/jline/consoleui/prompt/PromptResultItemIF.java
new file mode 100644
index 00000000..26f85013
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/PromptResultItemIF.java
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+/**
+ * Created by Andreas Wegmann on 03.02.16.
+ */
+public interface PromptResultItemIF {
+ String getResult();
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/CheckboxItemBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/CheckboxItemBuilder.java
new file mode 100644
index 00000000..99fee53a
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/CheckboxItemBuilder.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import org.jline.consoleui.elements.items.CheckboxItemIF;
+import org.jline.consoleui.elements.items.impl.CheckboxItem;
+
+/**
+ * Created by andy on 22.01.16.
+ */
+public class CheckboxItemBuilder {
+ private final CheckboxPromptBuilder checkboxPromptBuilder;
+ private boolean checked;
+ private String name;
+ private String text;
+ private String disabledText;
+
+ public CheckboxItemBuilder(CheckboxPromptBuilder checkboxPromptBuilder) {
+ this.checkboxPromptBuilder = checkboxPromptBuilder;
+ }
+
+ public CheckboxItemBuilder name(String name) {
+ if (text == null) {
+ text = name;
+ }
+ this.name = name;
+ return this;
+ }
+
+ public CheckboxItemBuilder text(String text) {
+ if (this.name == null) {
+ this.name = text;
+ }
+ this.text = text;
+ return this;
+ }
+
+ public CheckboxPromptBuilder add() {
+ CheckboxItemIF item = new CheckboxItem(checked, text, disabledText, name);
+ checkboxPromptBuilder.addItem(item);
+ return checkboxPromptBuilder;
+ }
+
+ public CheckboxItemBuilder disabledText(String disabledText) {
+ this.disabledText = disabledText;
+ return this;
+ }
+
+ public CheckboxItemBuilder check() {
+ this.checked = true;
+ return this;
+ }
+
+ public CheckboxItemBuilder checked(boolean checked) {
+ this.checked = checked;
+ return this;
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/CheckboxPromptBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/CheckboxPromptBuilder.java
new file mode 100644
index 00000000..34ea8ffb
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/CheckboxPromptBuilder.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jline.consoleui.elements.Checkbox;
+import org.jline.consoleui.elements.PageSizeType;
+import org.jline.consoleui.elements.items.CheckboxItemIF;
+
+/**
+ * Created by andy on 22.01.16.
+ */
+public class CheckboxPromptBuilder {
+ private final PromptBuilder promptBuilder;
+ private String name;
+ private String message;
+ private int pageSize;
+ private PageSizeType pageSizeType;
+ private final List itemList;
+
+ public CheckboxPromptBuilder(PromptBuilder promptBuilder) {
+ this.promptBuilder = promptBuilder;
+ this.pageSize = 10;
+ this.pageSizeType = PageSizeType.ABSOLUTE;
+ itemList = new ArrayList<>();
+ }
+
+ void addItem(CheckboxItemIF checkboxItem) {
+ itemList.add(checkboxItem);
+ }
+
+ public CheckboxPromptBuilder name(String name) {
+ this.name = name;
+ if (message == null) {
+ message = name;
+ }
+ return this;
+ }
+
+ public CheckboxPromptBuilder message(String message) {
+ this.message = message;
+ if (name == null) {
+ name = message;
+ }
+ return this;
+ }
+
+ public CheckboxPromptBuilder pageSize(int absoluteSize) {
+ this.pageSize = absoluteSize;
+ this.pageSizeType = PageSizeType.ABSOLUTE;
+ return this;
+ }
+
+ public CheckboxPromptBuilder relativePageSize(int relativePageSize) {
+ this.pageSize = relativePageSize;
+ this.pageSizeType = PageSizeType.RELATIVE;
+ return this;
+ }
+
+ public CheckboxItemBuilder newItem() {
+ return new CheckboxItemBuilder(this);
+ }
+
+ public CheckboxItemBuilder newItem(String name) {
+ CheckboxItemBuilder checkboxItemBuilder = new CheckboxItemBuilder(this);
+ return checkboxItemBuilder.name(name);
+ }
+
+ public PromptBuilder addPrompt() {
+ Checkbox checkbox = new Checkbox(message, name, pageSize, pageSizeType, itemList);
+ promptBuilder.addPrompt(checkbox);
+ return promptBuilder;
+ }
+
+ public CheckboxSeparatorBuilder newSeparator() {
+ return new CheckboxSeparatorBuilder(this);
+ }
+
+ public CheckboxSeparatorBuilder newSeparator(String text) {
+ CheckboxSeparatorBuilder checkboxSeperatorBuilder = new CheckboxSeparatorBuilder(this);
+ return checkboxSeperatorBuilder.text(text);
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/CheckboxSeparatorBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/CheckboxSeparatorBuilder.java
new file mode 100644
index 00000000..f70617af
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/CheckboxSeparatorBuilder.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import org.jline.consoleui.elements.items.impl.Separator;
+
+/**
+ * Created by andy on 22.01.16.
+ */
+public class CheckboxSeparatorBuilder {
+ private final CheckboxPromptBuilder promptBuilder;
+ private String text;
+
+ public CheckboxSeparatorBuilder(CheckboxPromptBuilder checkboxPromptBuilder) {
+ this.promptBuilder = checkboxPromptBuilder;
+ }
+
+ public CheckboxPromptBuilder add() {
+ Separator separator = new Separator(text);
+ promptBuilder.addItem(separator);
+
+ return promptBuilder;
+ }
+
+ public CheckboxSeparatorBuilder text(String text) {
+ this.text = text;
+ return this;
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ConfirmPromptBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ConfirmPromptBuilder.java
new file mode 100644
index 00000000..3e753bcc
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ConfirmPromptBuilder.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import org.jline.consoleui.elements.ConfirmChoice;
+
+/**
+ * User: Andreas Wegmann
+ * Date: 24.01.16
+ */
+public class ConfirmPromptBuilder {
+ private final PromptBuilder promptBuilder;
+ private String name;
+ private String message;
+ private ConfirmChoice.ConfirmationValue defaultConfirmationValue;
+
+ public ConfirmPromptBuilder(PromptBuilder promptBuilder) {
+ this.promptBuilder = promptBuilder;
+ }
+
+ public ConfirmPromptBuilder name(String name) {
+ this.name = name;
+ if (message == null) {
+ message = name;
+ }
+ return this;
+ }
+
+ public ConfirmPromptBuilder message(String message) {
+ this.message = message;
+ if (name == null) {
+ name = message;
+ }
+ return this;
+ }
+
+ public ConfirmPromptBuilder defaultValue(ConfirmChoice.ConfirmationValue confirmationValue) {
+ this.defaultConfirmationValue = confirmationValue;
+ return this;
+ }
+
+ public PromptBuilder addPrompt() {
+ promptBuilder.addPrompt(new ConfirmChoice(message, name, defaultConfirmationValue));
+ return promptBuilder;
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ExpandableChoiceItemBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ExpandableChoiceItemBuilder.java
new file mode 100644
index 00000000..488bf9fb
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ExpandableChoiceItemBuilder.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import org.jline.consoleui.elements.items.impl.ChoiceItem;
+
+/**
+ * Created by andy on 22.01.16.
+ */
+public class ExpandableChoiceItemBuilder {
+ private final ExpandableChoicePromptBuilder choicePromptBuilder;
+ private String name;
+ private String message;
+ private Character key;
+ private boolean asDefault;
+
+ public ExpandableChoiceItemBuilder(ExpandableChoicePromptBuilder choicePromptBuilder) {
+ this.choicePromptBuilder = choicePromptBuilder;
+ }
+
+ public ExpandableChoiceItemBuilder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public ExpandableChoiceItemBuilder message(String message) {
+ this.message = message;
+ return this;
+ }
+
+ public ExpandableChoiceItemBuilder key(char key) {
+ this.key = key;
+ return this;
+ }
+
+ public ExpandableChoicePromptBuilder add() {
+ ChoiceItem choiceItem = new ChoiceItem(key, name, message, asDefault);
+ choicePromptBuilder.addItem(choiceItem);
+ return choicePromptBuilder;
+ }
+
+ public ExpandableChoiceItemBuilder asDefault() {
+ this.asDefault = true;
+ return this;
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ExpandableChoicePromptBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ExpandableChoicePromptBuilder.java
new file mode 100644
index 00000000..20858941
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ExpandableChoicePromptBuilder.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jline.consoleui.elements.ExpandableChoice;
+import org.jline.consoleui.elements.items.ChoiceItemIF;
+
+/**
+ * Created by andy on 22.01.16.
+ */
+public class ExpandableChoicePromptBuilder {
+ private final PromptBuilder promptBuilder;
+ private String name;
+ private String message;
+ private final List itemList;
+
+ public ExpandableChoicePromptBuilder(PromptBuilder promptBuilder) {
+ this.promptBuilder = promptBuilder;
+ this.itemList = new ArrayList<>();
+ }
+
+ void addItem(ChoiceItemIF choiceItem) {
+ this.itemList.add(choiceItem);
+ }
+
+ public ExpandableChoicePromptBuilder name(String name) {
+ this.name = name;
+ if (message == null) {
+ message = name;
+ }
+ return this;
+ }
+
+ public ExpandableChoicePromptBuilder message(String message) {
+ this.message = message;
+ if (name == null) {
+ name = message;
+ }
+ return this;
+ }
+
+ public ExpandableChoiceItemBuilder newItem() {
+ return new ExpandableChoiceItemBuilder(this);
+ }
+
+ public ExpandableChoiceItemBuilder newItem(String name) {
+ ExpandableChoiceItemBuilder expandableChoiceItemBuilder = new ExpandableChoiceItemBuilder(this);
+ return expandableChoiceItemBuilder.name(name);
+ }
+
+ public PromptBuilder addPrompt() {
+ ExpandableChoice expandableChoice = new ExpandableChoice(message, name, itemList);
+ promptBuilder.addPrompt(expandableChoice);
+ return promptBuilder;
+ }
+
+ public ExpandableChoiceSeparatorBuilder newSeparator(String text) {
+ ExpandableChoiceSeparatorBuilder expandableChoiceSeparatorBuilder = new ExpandableChoiceSeparatorBuilder(this);
+ return expandableChoiceSeparatorBuilder.text(text);
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ExpandableChoiceSeparatorBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ExpandableChoiceSeparatorBuilder.java
new file mode 100644
index 00000000..06f5ed74
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ExpandableChoiceSeparatorBuilder.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import org.jline.consoleui.elements.items.impl.Separator;
+
+/**
+ * Created by andy on 22.01.16.
+ */
+public class ExpandableChoiceSeparatorBuilder {
+ private final ExpandableChoicePromptBuilder expandableChoicePromptBuilder;
+ private String text;
+
+ public ExpandableChoiceSeparatorBuilder(ExpandableChoicePromptBuilder expandableChoicePromptBuilder) {
+ this.expandableChoicePromptBuilder = expandableChoicePromptBuilder;
+ }
+
+ public ExpandableChoiceSeparatorBuilder text(String text) {
+ this.text = text;
+ return this;
+ }
+
+ public ExpandableChoicePromptBuilder add() {
+ Separator separator = new Separator(text);
+ expandableChoicePromptBuilder.addItem(separator);
+
+ return expandableChoicePromptBuilder;
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/InputValueBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/InputValueBuilder.java
new file mode 100644
index 00000000..80c00f78
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/InputValueBuilder.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import org.jline.consoleui.elements.InputValue;
+import org.jline.reader.Completer;
+
+/**
+ * Created by andy on 22.01.16.
+ */
+public class InputValueBuilder {
+ private final PromptBuilder promptBuilder;
+ private String name;
+ private String defaultValue;
+ private String message;
+ private Character mask;
+ private Completer completer;
+
+ public InputValueBuilder(PromptBuilder promptBuilder) {
+ this.promptBuilder = promptBuilder;
+ }
+
+ public InputValueBuilder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public InputValueBuilder defaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ return this;
+ }
+
+ public InputValueBuilder message(String message) {
+ this.message = message;
+ return this;
+ }
+
+ public InputValueBuilder mask(char mask) {
+ this.mask = mask;
+ return this;
+ }
+
+ public PromptBuilder addPrompt() {
+ InputValue inputValue = new InputValue(name, message, null, defaultValue);
+ if (mask != null) {
+ inputValue.setMask(mask);
+ }
+ if (completer != null) {
+ inputValue.setCompleter(completer);
+ }
+ promptBuilder.addPrompt(inputValue);
+ return promptBuilder;
+ }
+
+ public InputValueBuilder addCompleter(Completer completer) {
+ this.completer = completer;
+ return this;
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ListItemBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ListItemBuilder.java
new file mode 100644
index 00000000..cef7f413
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ListItemBuilder.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import org.jline.consoleui.elements.items.impl.ListItem;
+
+/**
+ * Created by andy on 22.01.16.
+ */
+public class ListItemBuilder {
+ private final ListPromptBuilder listPromptBuilder;
+ private String text;
+ private String name;
+
+ public ListItemBuilder(ListPromptBuilder listPromptBuilder) {
+ this.listPromptBuilder = listPromptBuilder;
+ }
+
+ public ListItemBuilder text(String text) {
+ this.text = text;
+ return this;
+ }
+
+ public ListItemBuilder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public ListPromptBuilder add() {
+ listPromptBuilder.addItem(new ListItem(text, name));
+ return listPromptBuilder;
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ListPromptBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ListPromptBuilder.java
new file mode 100644
index 00000000..9c1ea352
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/ListPromptBuilder.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jline.consoleui.elements.ListChoice;
+import org.jline.consoleui.elements.PageSizeType;
+import org.jline.consoleui.elements.items.ListItemIF;
+import org.jline.consoleui.elements.items.impl.ListItem;
+
+/**
+ * Created by andy on 22.01.16.
+ */
+public class ListPromptBuilder {
+ private final PromptBuilder promptBuilder;
+ private String name;
+ private String message;
+ private int pageSize;
+ private PageSizeType pageSizeType;
+ private final List itemList = new ArrayList<>();
+
+ public ListPromptBuilder(PromptBuilder promptBuilder) {
+ this.promptBuilder = promptBuilder;
+ this.pageSize = 10;
+ this.pageSizeType = PageSizeType.ABSOLUTE;
+ }
+
+ public ListPromptBuilder name(String name) {
+ this.name = name;
+ if (message != null) {
+ this.message = name;
+ }
+ return this;
+ }
+
+ public ListPromptBuilder message(String message) {
+ this.message = message;
+ if (name == null) {
+ name = message;
+ }
+ return this;
+ }
+
+ public ListPromptBuilder pageSize(int absoluteSize) {
+ this.pageSize = absoluteSize;
+ this.pageSizeType = PageSizeType.ABSOLUTE;
+ return this;
+ }
+
+ public ListPromptBuilder relativePageSize(int relativePageSize) {
+ this.pageSize = relativePageSize;
+ this.pageSizeType = PageSizeType.RELATIVE;
+ return this;
+ }
+
+ public ListItemBuilder newItem() {
+ return new ListItemBuilder(this);
+ }
+
+ public ListItemBuilder newItem(String name) {
+ ListItemBuilder listItemBuilder = new ListItemBuilder(this);
+ return listItemBuilder.name(name).text(name);
+ }
+
+ public PromptBuilder addPrompt() {
+ ListChoice listChoice = new ListChoice(message, name, pageSize, pageSizeType, itemList);
+ promptBuilder.addPrompt(listChoice);
+ return promptBuilder;
+ }
+
+ void addItem(ListItem listItem) {
+ this.itemList.add(listItem);
+ }
+}
diff --git a/console-ui/src/main/java/org/jline/consoleui/prompt/builder/PromptBuilder.java b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/PromptBuilder.java
new file mode 100644
index 00000000..718b47a5
--- /dev/null
+++ b/console-ui/src/main/java/org/jline/consoleui/prompt/builder/PromptBuilder.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jline.consoleui.elements.PromptableElementIF;
+
+/**
+ * PromptBuilder is the builder class which creates
+ *
+ * Created by Andreas Wegmann
+ * on 20.01.16.
+ */
+public class PromptBuilder {
+ List promptList = new ArrayList<>();
+
+ public List build() {
+ return promptList;
+ }
+
+ public void addPrompt(PromptableElementIF promptableElement) {
+ promptList.add(promptableElement);
+ }
+
+ public InputValueBuilder createInputPrompt() {
+ return new InputValueBuilder(this);
+ }
+
+ public ListPromptBuilder createListPrompt() {
+ return new ListPromptBuilder(this);
+ }
+
+ public ExpandableChoicePromptBuilder createChoicePrompt() {
+ return new ExpandableChoicePromptBuilder(this);
+ }
+
+ public CheckboxPromptBuilder createCheckboxPrompt() {
+ return new CheckboxPromptBuilder(this);
+ }
+
+ public ConfirmPromptBuilder createConfirmPromp() {
+ return new ConfirmPromptBuilder(this);
+ }
+}
diff --git a/console-ui/src/main/resources/consoleui_messages.properties b/console-ui/src/main/resources/consoleui_messages.properties
new file mode 100644
index 00000000..a73f3793
--- /dev/null
+++ b/console-ui/src/main/resources/consoleui_messages.properties
@@ -0,0 +1,10 @@
+confirmation_without_default=(y/n)
+confirmation_no_default=(y/N)
+confirmation_yes_default=(Y/n)
+confirmation_yes_key=y
+confirmation_no_key=n
+
+help.list.all.options=Help, list all options
+please.enter.a.valid.command=Please enter a valid command
+confirmation_no_answer=no
+confirmation_yes_answer=yes
\ No newline at end of file
diff --git a/console-ui/src/main/resources/consoleui_messages_de_DE.properties b/console-ui/src/main/resources/consoleui_messages_de_DE.properties
new file mode 100644
index 00000000..1da57b1f
--- /dev/null
+++ b/console-ui/src/main/resources/consoleui_messages_de_DE.properties
@@ -0,0 +1,9 @@
+confirmation_without_default=(j/n)
+confirmation_no_default=(j/N)
+confirmation_yes_default=(J/n)
+confirmation_yes_key=j
+confirmation_no_key=n
+help.list.all.options=Hilfe. Listet alle Optionen.
+please.enter.a.valid.command=Bitte ein gültiges Kürzel eingeben.
+confirmation_no_answer=Nein
+confirmation_yes_answer=Ja
\ No newline at end of file
diff --git a/console-ui/src/test/java/org/jline/consoleui/examples/Basic.java b/console-ui/src/test/java/org/jline/consoleui/examples/Basic.java
new file mode 100644
index 00000000..ba8f2aa4
--- /dev/null
+++ b/console-ui/src/test/java/org/jline/consoleui/examples/Basic.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.examples;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jline.consoleui.elements.ConfirmChoice;
+import org.jline.consoleui.prompt.ConfirmResult;
+import org.jline.consoleui.prompt.ConsolePrompt;
+import org.jline.consoleui.prompt.PromptResultItemIF;
+import org.jline.consoleui.prompt.builder.PromptBuilder;
+import org.jline.reader.LineReader;
+import org.jline.reader.LineReaderBuilder;
+import org.jline.reader.impl.completer.StringsCompleter;
+import org.jline.terminal.Terminal;
+import org.jline.terminal.TerminalBuilder;
+import org.jline.utils.AttributedString;
+import org.jline.utils.AttributedStringBuilder;
+import org.jline.utils.AttributedStyle;
+import org.jline.utils.OSUtils;
+
+/**
+ * User: Andreas Wegmann
+ * Date: 29.11.15
+ */
+public class Basic {
+
+ private static void addInHeader(List header, String text) {
+ addInHeader(header, AttributedStyle.DEFAULT, text);
+ }
+
+ private static void addInHeader(List header, AttributedStyle style, String text) {
+ AttributedStringBuilder asb = new AttributedStringBuilder();
+ asb.style(style).append(text);
+ header.add(asb.toAttributedString());
+ }
+
+ public static void main(String[] args) {
+ List header = new ArrayList<>();
+ AttributedStyle style = new AttributedStyle();
+ addInHeader(header, style.italic().foreground(2), "Hello World!");
+ addInHeader(
+ header, "This is a demonstration of ConsoleUI java library. It provides a simple console interface");
+ addInHeader(
+ header,
+ "for querying information from the user. ConsoleUI is inspired by Inquirer.js which is written");
+ addInHeader(header, "in JavaScript.");
+ try (Terminal terminal = TerminalBuilder.builder().build()) {
+ ConsolePrompt.UiConfig config;
+ if (terminal.getType().equals(Terminal.TYPE_DUMB)
+ || terminal.getType().equals(Terminal.TYPE_DUMB_COLOR)) {
+ System.out.println(terminal.getName() + ": " + terminal.getType());
+ throw new IllegalStateException("Dumb terminal detected.\nConsoleUi requires real terminal to work!\n"
+ + "Note: On Windows Jansi or JNA library must be included in classpath.");
+ } else if (OSUtils.IS_WINDOWS) {
+ config = new ConsolePrompt.UiConfig(">", "( )", "(x)", "( )");
+ } else {
+ config = new ConsolePrompt.UiConfig("\u276F", "\u25EF ", "\u25C9 ", "\u25EF ");
+ }
+ //
+ // LineReader is needed only if you are adding JLine Completers in your prompts.
+ // If you are not using Completers you do not need to create LineReader.
+ //
+ LineReader reader = LineReaderBuilder.builder().terminal(terminal).build();
+ ConsolePrompt prompt = new ConsolePrompt(reader, terminal, config);
+ PromptBuilder promptBuilder = prompt.getPromptBuilder();
+
+ promptBuilder
+ .createInputPrompt()
+ .name("name")
+ .message("Please enter your name")
+ .defaultValue("John Doe")
+ // .mask('*')
+ .addCompleter(
+ // new Completers.FilesCompleter(() -> Paths.get(System.getProperty("user.dir"))))
+ new StringsCompleter("Jim", "Jack", "John", "Donald", "Dock"))
+ .addPrompt();
+
+ promptBuilder
+ .createListPrompt()
+ .name("pizzatype")
+ .message("Which pizza do you want?")
+ .newItem()
+ .text("Margherita")
+ .add() // without name (name defaults to text)
+ .newItem("veneziana")
+ .text("Veneziana")
+ .add()
+ .newItem("hawai")
+ .text("Hawai")
+ .add()
+ .newItem("quattro")
+ .text("Quattro Stagioni")
+ .add()
+ .addPrompt();
+
+ promptBuilder
+ .createCheckboxPrompt()
+ .name("topping")
+ .message("Please select additional toppings:")
+ .newSeparator("standard toppings")
+ .add()
+ .newItem()
+ .name("cheese")
+ .text("Cheese")
+ .add()
+ .newItem("bacon")
+ .text("Bacon")
+ .add()
+ .newItem("onions")
+ .text("Onions")
+ .disabledText("Sorry. Out of stock.")
+ .add()
+ .newSeparator()
+ .text("special toppings")
+ .add()
+ .newItem("salami")
+ .text("Very hot salami")
+ .check()
+ .add()
+ .newItem("salmon")
+ .text("Smoked Salmon")
+ .add()
+ .newSeparator("and our speciality...")
+ .add()
+ .newItem("special")
+ .text("Anchovies, and olives")
+ .checked(true)
+ .add()
+ .addPrompt();
+
+ promptBuilder
+ .createChoicePrompt()
+ .name("payment")
+ .message("How do you want to pay?")
+ .newItem()
+ .name("cash")
+ .message("Cash")
+ .key('c')
+ .asDefault()
+ .add()
+ .newItem("visa")
+ .message("Visa Card")
+ .key('v')
+ .add()
+ .newItem("master")
+ .message("Master Card")
+ .key('m')
+ .add()
+ .newSeparator("online payment")
+ .add()
+ .newItem("paypal")
+ .message("Paypal")
+ .key('p')
+ .add()
+ .addPrompt();
+
+ promptBuilder
+ .createConfirmPromp()
+ .name("delivery")
+ .message("Is this pizza for delivery?")
+ .defaultValue(ConfirmChoice.ConfirmationValue.YES)
+ .addPrompt();
+
+ Map result = prompt.prompt(header, promptBuilder.build());
+ System.out.println("result = " + result);
+
+ ConfirmResult delivery = (ConfirmResult) result.get("delivery");
+ if (delivery.getConfirmed() == ConfirmChoice.ConfirmationValue.YES) {
+ System.out.println("We will deliver the pizza in 5 minutes");
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/console-ui/src/test/java/org/jline/consoleui/examples/LongList.java b/console-ui/src/test/java/org/jline/consoleui/examples/LongList.java
new file mode 100644
index 00000000..5096bed2
--- /dev/null
+++ b/console-ui/src/test/java/org/jline/consoleui/examples/LongList.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.examples;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jline.consoleui.prompt.ConsolePrompt;
+import org.jline.consoleui.prompt.PromptResultItemIF;
+import org.jline.consoleui.prompt.builder.CheckboxPromptBuilder;
+import org.jline.consoleui.prompt.builder.ListPromptBuilder;
+import org.jline.consoleui.prompt.builder.PromptBuilder;
+import org.jline.terminal.Terminal;
+import org.jline.terminal.TerminalBuilder;
+import org.jline.utils.AttributedString;
+import org.jline.utils.AttributedStringBuilder;
+
+/**
+ * User: Andreas Wegmann
+ * Date: 29.11.15
+ */
+public class LongList {
+
+ public static void main(String[] args) {
+ List header = new ArrayList<>();
+ header.add(new AttributedStringBuilder()
+ .append("This is a demonstration of ConsoleUI java library. It provides a simple console interface")
+ .toAttributedString());
+ header.add(new AttributedStringBuilder()
+ .append("for querying information from the user. ConsoleUI is inspired by Inquirer.js which is written")
+ .toAttributedString());
+ header.add(new AttributedStringBuilder().append("in JavaScript.").toAttributedString());
+
+ try (Terminal terminal = TerminalBuilder.builder().build()) {
+ ConsolePrompt.UiConfig config = new ConsolePrompt.UiConfig(">", "( )", "(x)", "( )");
+ ConsolePrompt prompt = new ConsolePrompt(terminal, config);
+ PromptBuilder promptBuilder = prompt.getPromptBuilder();
+
+ ListPromptBuilder listPrompt = promptBuilder.createListPrompt();
+ listPrompt.name("longlist").message("What's your favourite Letter?").relativePageSize(66);
+
+ for (char letter = 'A'; letter <= 'C'; letter++)
+ for (char letter2 = 'A'; letter2 <= 'Z'; letter2++)
+ listPrompt.newItem().text("" + letter + letter2).add();
+ listPrompt.addPrompt();
+
+ CheckboxPromptBuilder checkboxPrompt = promptBuilder.createCheckboxPrompt();
+ checkboxPrompt
+ .name("longcheckbox")
+ .message("What's your favourite Letter? Select all you want...")
+ .relativePageSize(66);
+
+ for (char letter = 'A'; letter <= 'C'; letter++)
+ for (char letter2 = 'A'; letter2 <= 'Z'; letter2++)
+ checkboxPrompt.newItem().text("" + letter + letter2).add();
+ checkboxPrompt.addPrompt();
+
+ Map result = prompt.prompt(header, promptBuilder.build());
+ System.out.println("result = " + result);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/console-ui/src/test/java/org/jline/consoleui/examples/SimpleExample.java b/console-ui/src/test/java/org/jline/consoleui/examples/SimpleExample.java
new file mode 100644
index 00000000..21c28bcd
--- /dev/null
+++ b/console-ui/src/test/java/org/jline/consoleui/examples/SimpleExample.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.examples;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jline.consoleui.prompt.ConsolePrompt;
+import org.jline.consoleui.prompt.PromptResultItemIF;
+import org.jline.consoleui.prompt.builder.PromptBuilder;
+import org.jline.terminal.Terminal;
+import org.jline.terminal.TerminalBuilder;
+import org.jline.utils.AttributedString;
+import org.jline.utils.AttributedStringBuilder;
+
+/**
+ * User: Andreas Wegmann
+ * Date: 12.08.2020
+ */
+public class SimpleExample {
+
+ public static void main(String[] args) {
+ List header = new ArrayList<>();
+ header.add(new AttributedStringBuilder().append("Simple list example:").toAttributedString());
+
+ try (Terminal terminal = TerminalBuilder.builder().build()) {
+ ConsolePrompt prompt = new ConsolePrompt(terminal);
+ PromptBuilder promptBuilder = prompt.getPromptBuilder();
+
+ promptBuilder
+ .createListPrompt()
+ .name("pizzatype")
+ .message("Which pizza do you want?")
+ .newItem()
+ .text("Margherita")
+ .add() // without name (name defaults to text)
+ .newItem("veneziana")
+ .text("Veneziana")
+ .add()
+ .newItem("hawai")
+ .text("Hawai")
+ .add()
+ .newItem("quattro")
+ .text("Quattro Stagioni")
+ .add()
+ .addPrompt();
+
+ Map result = prompt.prompt(header, promptBuilder.build());
+ System.out.println("result = " + result);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/console-ui/src/test/java/org/jline/consoleui/prompt/CheckboxPromptTest.java b/console-ui/src/test/java/org/jline/consoleui/prompt/CheckboxPromptTest.java
new file mode 100644
index 00000000..d341e5da
--- /dev/null
+++ b/console-ui/src/test/java/org/jline/consoleui/prompt/CheckboxPromptTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jline.consoleui.elements.items.CheckboxItemIF;
+import org.jline.consoleui.elements.items.impl.CheckboxItem;
+import org.jline.consoleui.elements.items.impl.Separator;
+import org.junit.jupiter.api.Test;
+
+/**
+ * User: Andreas Wegmann
+ * Date: 07.12.15
+ */
+public class CheckboxPromptTest {
+ @Test
+ public void renderSimpleList() {
+ List list = new ArrayList<>();
+
+ list.add(new CheckboxItem("One"));
+ list.add(new CheckboxItem(true, "Two"));
+ CheckboxItem three = new CheckboxItem("Three");
+ three.setDisabled("not available");
+ list.add(three);
+ list.add(new Separator("some extra items"));
+ list.add(new CheckboxItem("Four"));
+ list.add(new CheckboxItem(true, "Five"));
+ }
+}
diff --git a/console-ui/src/test/java/org/jline/consoleui/prompt/ExpandableChoicePromptTest.java b/console-ui/src/test/java/org/jline/consoleui/prompt/ExpandableChoicePromptTest.java
new file mode 100644
index 00000000..04f9c4c8
--- /dev/null
+++ b/console-ui/src/test/java/org/jline/consoleui/prompt/ExpandableChoicePromptTest.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * User: Andreas Wegmann
+ * Date: 08.01.16
+ */
+public class ExpandableChoicePromptTest {
+
+ @Test
+ public void testPrompt() throws Exception {}
+}
diff --git a/console-ui/src/test/java/org/jline/consoleui/prompt/PromptBuilderTest.java b/console-ui/src/test/java/org/jline/consoleui/prompt/PromptBuilderTest.java
new file mode 100644
index 00000000..584bb4a5
--- /dev/null
+++ b/console-ui/src/test/java/org/jline/consoleui/prompt/PromptBuilderTest.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2024, the original author(s).
+ *
+ * This software is distributable under the BSD license. See the terms of the
+ * BSD license in the documentation provided with this software.
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+package org.jline.consoleui.prompt;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.jline.consoleui.elements.ConfirmChoice;
+import org.jline.consoleui.elements.PromptableElementIF;
+import org.jline.consoleui.prompt.builder.PromptBuilder;
+import org.jline.terminal.TerminalBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * User: Andreas Wegmann
+ * Date: 20.01.16
+ */
+public class PromptBuilderTest {
+
+ @Test
+ public void testBuilder() throws IOException {
+ ConsolePrompt prompt = new ConsolePrompt(TerminalBuilder.builder().build());
+ PromptBuilder promptBuilder = prompt.getPromptBuilder();
+
+ promptBuilder
+ .createConfirmPromp()
+ .name("wantapizza")
+ .message("Do you want to order a pizza?")
+ .defaultValue(ConfirmChoice.ConfirmationValue.YES)
+ .addPrompt();
+
+ promptBuilder
+ .createInputPrompt()
+ .name("name")
+ .message("Please enter your name")
+ .defaultValue("John Doe")
+ .addPrompt();
+
+ promptBuilder
+ .createListPrompt()
+ .name("pizzatype")
+ .message("Which pizza do you want?")
+ .newItem()
+ .text("Margherita")
+ .add() // without name (name defaults to text)
+ .newItem("veneziana")
+ .text("Veneziana")
+ .add()
+ .newItem("hawai")
+ .text("Hawai")
+ .add()
+ .newItem("quattro")
+ .text("Quattro Stagioni")
+ .add()
+ .addPrompt();
+
+ promptBuilder
+ .createCheckboxPrompt()
+ .name("topping")
+ .message("Please select additional toppings:")
+ .newSeparator("standard toppings")
+ .add()
+ .newItem()
+ .name("cheese")
+ .text("Cheese")
+ .add()
+ .newItem("bacon")
+ .text("Bacon")
+ .add()
+ .newItem("onions")
+ .text("Onions")
+ .disabledText("Sorry. Out of stock.")
+ .add()
+ .newSeparator()
+ .text("special toppings")
+ .add()
+ .newItem("salami")
+ .text("Very hot salami")
+ .check()
+ .add()
+ .newItem("salmon")
+ .text("Smoked Salmon")
+ .add()
+ .newSeparator("and our speciality...")
+ .add()
+ .newItem("special")
+ .text("Anchovies, and olives")
+ .checked(true)
+ .add()
+ .addPrompt();
+
+ assertNotNull(promptBuilder);
+ promptBuilder
+ .createChoicePrompt()
+ .name("payment")
+ .message("How do you want to pay?")
+ .newItem()
+ .name("cash")
+ .message("Cash")
+ .key('c')
+ .asDefault()
+ .add()
+ .newItem("visa")
+ .message("Visa Card")
+ .key('v')
+ .add()
+ .newItem("master")
+ .message("Master Card")
+ .key('m')
+ .add()
+ .newSeparator("online payment")
+ .add()
+ .newItem("paypal")
+ .message("Paypal")
+ .key('p')
+ .add()
+ .addPrompt();
+
+ List promptableElementList = promptBuilder.build();
+
+ // only for test. reset the default reader to a test reader to automate the input
+ // promptableElementList.get(0)
+
+ // HashMap result = prompt.prompt(promptableElementList);
+
+ }
+}
diff --git a/pom.xml b/pom.xml
index 16226135..45b262ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,6 +59,7 @@
terminal-jni
reader
builtins
+ console-ui
console
groovy
remote-ssh