Skip to content

Tiny Java library for producing interactive command line prompts

Notifications You must be signed in to change notification settings

academia-de-codigo/prompt-view

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prompt View

Tiny Java library for producing interactive command line prompts

Examples

You can grab an integer input between 3 and 6 from the user using:

// Create a new prompt attached to standard input/output
Prompt prompt = new Prompt(System.in, System.out);

// Instantiate an input scanner for integers between 3 and 6
IntegerRangeInputScanner scanner = new IntegerRangeInputScanner(3, 6);

// Grab the user in a loop until a valid input is inserted
int userInput = prompt.getUserInput(scanner);

Displaying a menu with a couple of options is achieved by using a different type of input scanner instance:

// Define some options for the menu
String[] options = {"Deposit", "Withdraw"};

// Create a new prompt attached to standard input/output
Prompt prompt = new Prompt(System.in, System.out);

// Instantiate a menu scanner 
MenuInputScanner scanner = new MenuInputScanner(options);

// Setup the menu prompt message
scanner.setMessage("Choose an option: ");

// Grab the user in a loop until a valid input is inserted
int userInput = prompt.getUserInput(scanner);

Hide your password from prying eyes:

// Create a new prompt attached to standard input/output
Prompt prompt = new Prompt(System.in, System.out);

// Instantiate a password input scanner 
PasswordInputScanner scanner = new PasswordInputScanner();

// Grab that password 
String password = prompt.getUserInput(scanner);

Password Masking might not work and fallback to clear text on IDEs or other environments where the java virtual machine does not have a console.


The examples folder contains working examples for other input scanner types.

About

Tiny Java library for producing interactive command line prompts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages