Skip to content

A small Java library that allows you to collect user input with interactive CLI in console

License

Notifications You must be signed in to change notification settings

dinhtienloc/jquestion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JQuestion Build Status

A small Java library that provides some simple interactive CLI components for collecting user input

Overview

I was very impressed by the console interface when I use JHipster to create a new project. I found that it uses Inquirer.js to handle the console with interactive CLI behind the scene. I can't find any libraries similar to Inquirer.js except Console UI. However, Console UI is very low-maintenance and has some issue when running on Window. Therefore, I decide to create a new library with better API to use.

Usage

Initialization

Before using JQuestion, you have to install AnsiConsole to standard Java's System stream:

AnsiConsole.systemInstall();

JQuestion is using JLine3. JQuestion takes the LineReader instance from JLine and uses it to read user input. You can still use LineReader normally in other places without JQuestion:

Terminal terminal = TerminalBuilder.builder()
                        .system(true)
                        .encoding(StandardCharsets.UTF_8)
                        .jansi(true)
                        .build();
LineReader lr = LineReaderBuilder.builder().terminal(terminal).build();
JQuestion jQuestion = JQuestion.initialize(lr);

JQuestion is a singleton instance. Once you initialize, you can easily call it via JQuestion.instance().

Components

Input
String answer = jQuestion.input("title").prompt();
Selection
String answer = jQuestion.select("title", new String[]{"foo", "bar"}).prompt();
Confirmation
Boolean answer = jQuestion.confirm("title").prompt();

About

A small Java library that allows you to collect user input with interactive CLI in console

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages