Class CLIFormular

java.lang.Object
com.marcpg.libpg.formular.Formular
com.marcpg.libpg.formular.CLIFormular

public class CLIFormular extends Formular
Represents a CLI (Command Line Interface) 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:
  • Field Details

  • 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 the system output and system 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 the system output and system 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 into System.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 if System.console() returns something. If it returns null, it means this method won't work.
      Specified by:
      render in class Formular
    • clearOutput

      public void clearOutput()
      Clears System.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.