Package com.marcpg.libpg.formular
Class CLIFormular
java.lang.Object
com.marcpg.libpg.formular.Formular
com.marcpg.libpg.formular.CLIFormular
Represents a CLI (Command Line Interface)
The console needs to support ANSI formatting and needs to run on Windows or any UNIX system.
Note that most features will require you to manually implement the JNA dependency (>5.14.0)!
Formular
, that can be displayed inside of consoles. The console needs to support ANSI formatting and needs to run on Windows or any UNIX system.
Note that most features will require you to manually implement the JNA dependency (>5.14.0)!
- Since:
- 0.0.8
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.marcpg.libpg.formular.Formular
Formular.FormularException
-
Field Summary
Modifier and TypeFieldDescriptionfinal Ansi
The theme of the formular converted to anANSI color
.final RawConsoleInput
TheRawConsoleInput
manager used for getting input. -
Constructor Summary
ConstructorDescriptionCLIFormular
(String title, String description, @Nullable Color theme, Consumer<FormularResult> callback, @NotNull List<Question> questions) Creates a new console-based formular with the basic required options.CLIFormular
(String title, String description, @Nullable Color theme, Consumer<FormularResult> callback, Question... questions) Creates a new console-based formular with the basic required options. -
Method Summary
Modifier and TypeMethodDescriptionvoid
ClearsSystem.out
, using either "\033[H\033[2J", if ANSI is supported, or else printing 100 new lines.void
render()
Renders the current page/question intoSystem.out
.boolean
Checks if the current environment supports ANSI.Methods inherited from class com.marcpg.libpg.formular.Formular
addQuestion, addQuestions, addQuestions, currentQuestion, getCallback, getDescription, getPage, getQuestion, getQuestions, getTheme, getTitle, nextQuestion, setCallback, setDescription, setTheme, setTitle, toResult
-
Field Details
-
input
TheRawConsoleInput
manager used for getting input. -
ansiTheme
The theme of the formular converted to anANSI color
.
-
-
Constructor Details
-
CLIFormular
public CLIFormular(String title, String description, @Nullable @Nullable Color theme, Consumer<FormularResult> callback, @NotNull @NotNull List<Question> questions) Creates a new console-based formular with the basic required options.
The input and output will be thesystem output
andsystem input
.- Parameters:
title
- The formular's title.description
- A detailed description of the formular. (displayed on first page)theme
- The theme color. Will be used for decorations and as an accent color.callback
- What will be executed once the formular is fully filled out.questions
- A list of all questions in this formular.
-
CLIFormular
public CLIFormular(String title, String description, @Nullable @Nullable Color theme, Consumer<FormularResult> callback, Question... questions) Creates a new console-based formular with the basic required options.
The input and output will be thesystem output
andsystem input
.- Parameters:
title
- The formular's title.description
- A detailed description of the formular. (displayed on first page)theme
- The theme color. Will be used for decorations and as an accent color.callback
- What will be executed once the formular is fully filled out.questions
- All questions in this formular.
-
-
Method Details
-
render
public void render()Renders the current page/question intoSystem.out
.
For this to properly work, the runtime needs to have a valid input/output with a console, which means that it can't run on IDEs for example. You can test that by checking ifSystem.console()
returns something. If it returns null, it means this method won't work. -
clearOutput
public void clearOutput()ClearsSystem.out
, using either "\033[H\033[2J", if ANSI is supported, or else printing 100 new lines.- See Also:
-
supportsANSI
public boolean supportsANSI()Checks if the current environment supports ANSI. It does that the following way:
If the operating system is not windows, it will always return true.
If it's windows, it will return if the system environmental variable "TERM" is set to xterm.- Returns:
- If the current environment supports ANSI or not.
-