Skip to content

Commit

Permalink
Prepare merge
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 23, 2024
1 parent 2f162bc commit e5a491a
Show file tree
Hide file tree
Showing 62 changed files with 2,856 additions and 2,581 deletions.
11 changes: 0 additions & 11 deletions console-ui/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion console-ui/.travis.yml

This file was deleted.

41 changes: 11 additions & 30 deletions console-ui/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<img src="./doc/ConsoleUI-Logo.png" width="200" align="right" alt="ConsoleUI logo">

[![Build Status](https://travis-ci.org/awegmann/consoleui.svg?branch=master)](https://travis-ci.org/awegmann/consoleui)

# ConsoleUI

[![Join the chat at https://gitter.im/awegmann/consoleui](https://badges.gitter.im/awegmann/consoleui.svg)](https://gitter.im/awegmann/consoleui?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Tiny java library that provides simple UI elements on ANSI console based terminals. ConsoleUI is inspired by
[Inquirer.js](https://github.com/SBoudrias/Inquirer.js) which is written in JavaScript.

ConsoleUI has been initially implemented using JLine2 by Andreas Wegmann. After ConsoleUI has been upgraded to use JLine3
it has been merged into JLine3.

# Intention

I was impressed by JavaScript based Yeoman which leads the user through the process of creating new projects
by querying with a simple user interface on the console. An investigation how this is done, brought
me to Inquirer.js which implements a very simple and intuitive set of controls for checkbox, list and text input.

Because I didn't found anything comparable to this in the Java eco system, I decided to write `Console UI`
Because I didn't find anything comparable to this in the Java ecosystem, I decided to write `Console UI`
as a library with the same easy 'look and feel'. Some parts of the API are also comparable, but Console UI is not
a Java clone of Inquirer.js.

Expand All @@ -29,33 +28,28 @@ a Java clone of Inquirer.js.
- Expandable Choices (multiple key based answers for a question with help and optional list navigation)
- Yes/No-Questions

A screen recording of the basic elements demo can be fund on Youtube [console UI demo](https://youtu.be/6dB3CyOX9rU).
A screen recording of the basic elements demo can be fund on YouTube [console UI demo](https://youtu.be/6dB3CyOX9rU).

# Dependencies

Console UI uses jansi and jline for the dirty console things.
Console UI uses JLine for the dirty console things.

# Maven artefact

ConsoleUI releases are available at Maven Central [de.codeshelf.consoleui » consoleui](https://search.maven.org/artifact/de.codeshelf.consoleui/consoleui)
ConsoleUI releases are available at Maven Central [org.jline.console-ui » console-ui](https://search.maven.org/artifact/org.jline.console-ui/console-ui)

# Test Run

You can get an idea how the project works by looking at `de.codeshelf.consoleui.Basic`.
You can get an idea how the project works by looking at `org.jline.consoleui.examples.Basic`.
You can run this by executing the following from the project root:

gradlew fatJar
java -jar build/libs/consoleui-all-0.0.10.jar # <- replace with the latest version
./jline-console-ui.sh

# Usage

*Hint: see the [how to](doc/howto.md) to get a more detailed documentation how to use ConsoleUI.*


Before you can use ConsoleUI the AnsiConsole library has to be initialized.

AnsiConsole.systemInstall();

Entry point to the builder classes is to create a new object of type `ConsolePrompt`.

ConsolePrompt prompt = new ConsolePrompt();
Expand All @@ -72,28 +66,15 @@ From with this `PromptBuilder` you can access UI builder with the following meth
- createChoicePrompt()
* creates a choice prompt. This prompt lets the user choose one from a given number of possible answers.
- createConfirmPromp()
* creates a confirm prompt. This prompt lets the user answer with 'yes' or 'no' to a given question.
* creates a confirmation prompt. This prompt lets the user answer with 'yes' or 'no' to a given question.
- createInputPrompt()
* creates a input prompt. This prompt is a classic entry line like a shell. Because of the underlying readline
* creates an input prompt. This prompt is a classic entry line like a shell. Because of the underlying readline
implementation it offers you to provide completers (like file name completer or string completer). In addition
to his, you can define a mask character which is printed on the screen instead of the typed keys like used
for hidden password entry.
- createListPrompt()
* creates a list prompt. This prompt lets the user choose one item from a given list.


# Changes

### Version 0.0.13

- Fixed bug #22: lists are not rendered correctly

### Version 0.0.12

- Fixed Bug #20: Lists higher than the terminal height were not handled correctly.
ConsoleUI now supports scrolling for checkbox promt and list prompt.
To configure the height of the view port, either an absolute number of lines or a fraction (percentage) of the
screen height can be defined.



1 change: 0 additions & 1 deletion console-ui/_config.yml

This file was deleted.

110 changes: 0 additions & 110 deletions console-ui/build.gradle

This file was deleted.

101 changes: 51 additions & 50 deletions console-ui/doc/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,71 +18,72 @@ Console UI currently supports:

## A small example

The following code presents a simple, but complete code example to use CosoleUI for selecting an item from a list.
The following code presents a simple, but complete code example to use ConsoleUI for selecting an item from a list.

```java
package de.codeshelf.consoleui;

import de.codeshelf.consoleui.prompt.ConsolePrompt;
import de.codeshelf.consoleui.prompt.PromtResultItemIF;
import de.codeshelf.consoleui.prompt.builder.PromptBuilder;
import jline.TerminalFactory;
import org.fusesource.jansi.AnsiConsole;
package org.jline.consoleui.examples;

import java.io.IOException;
import java.util.HashMap;

import static org.fusesource.jansi.Ansi.ansi;
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) throws InterruptedException {
AnsiConsole.systemInstall(); // #1
System.out.println(ansi().eraseScreen().render("Simple list example:"));

try {
ConsolePrompt prompt = new ConsolePrompt(); // #2
PromptBuilder promptBuilder = prompt.getPromptBuilder(); // #3

promptBuilder.createListPrompt() // #4
.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();

HashMap<String, ? extends PromtResultItemIF> result = prompt.prompt(promptBuilder.build()); // #5
System.out.println("result = " + result);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
TerminalFactory.get().restore();
} catch (Exception e) {
e.printStackTrace();
public static void main(String[] args) {
List<AttributedString> 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<String, PromptResultItemIF> result = prompt.prompt(header, promptBuilder.build());
System.out.println("result = " + result);
} catch (IOException e) {
e.printStackTrace();
}
}
}}
}
}

```

Basic steps:

1. ConsoleUI uses [jansi](https://github.com/fusesource/jansi), so you have to initialize it first
2. Create a new `ConsolePrompt` object.
3. Create a `PromptBuilder`. All user interactions can be created with the prompt builder object.
4. In this example, we create a `ListPrompt`
1. Create a new `ConsolePrompt` object.
2. Create a `PromptBuilder`. All user interactions can be created with the prompt builder object.
3. In this example, we create a `ListPrompt`
1. give it a name ('pizzatype')
2. assign a prompt message ("Which pizza do you want?")
3. create items with and name (optional) and a text and add them to the ListPrompt
4. to finish call `addPrompt()` to create the ListPrompt and add it to the prompt builder object.
5. calling `prompt.prompt(promptBuilder.build())` builds all the prompts (in this example only one) and enters the user interaction. After all prompts are processes, the `prompt()` method returns an object with the user input results.
4. calling `prompt.prompt(promptBuilder.build())` builds all the prompts (in this example only one) and enters the user interaction. After all prompts are processes, the `prompt()` method returns an object with the user input results.

# Prompting for user input

Expand Down Expand Up @@ -148,7 +149,7 @@ Description:
4. Add items to the list. If you call `newItem()` without a name for the item, the text of the item is used in the result.
5. Add items with `newItem(<item_name>)` to give the item a name which makes it possible to use a technical key or another value instead of the printed text as a result.
6. (optional) For long lists, you can use `pageSize()` to set an absolute number of items to display (default is 10). Even if you choose a higher value than the terminal, the list will never exceed the terminal height.
7. (optional) Further you can use `relativePageSize()` to set a percentual size of the terminal as height. In this example, 66 is 66/100 or 2/3 of the terminal used for the list items. At least one line is displayed, even when you select a very low value.
7. (optional) Further you can use `relativePageSize()` to set a percentage size of the terminal as height. In this example, 66 is 66/100 or 2/3 of the terminal used for the list items. At least one line is displayed, even when you select a very low value.

#### Console

Expand Down Expand Up @@ -198,7 +199,7 @@ Description:
8. Use the `check()` method to pre-check the corresponding item.
9. For more flexibility, you can use `checked()` with a boolean value to select if the item is checked by default.
10. (optional) For long lists, you can use `pageSize()` to set an absolute number of items to display (default is 10). Even if you choose a higher value than the terminal, the list will never exceed the terminal height.
11. (optional) Further you can use `relativePageSize()` to set a percentual size of the terminal as height. In this example, 66 is 66/100 or 2/3 of the terminal used for the list items. At least one line is displayed even when you select a very low value.
11. (optional) Further you can use `relativePageSize()` to set a percentage size of the terminal as height. In this example, 66 is 66/100 or 2/3 of the terminal used for the list items. At least one line is displayed even when you select a very low value.

#### Console

Expand Down
4 changes: 0 additions & 4 deletions console-ui/gradle.properties

This file was deleted.

Binary file removed console-ui/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 0 additions & 6 deletions console-ui/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

0 comments on commit e5a491a

Please sign in to comment.