Skip to content

klakpin/DivaTerm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

41 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🩸 DivaTerm

"The terminal's power awakens."

Java terminal components with a Diva elegance


Maven Central Version License

✨ Features

  • Simplicity – This is not a framework for full-featured TUI rather than basic components for command-based CLI applications.
  • Sleek, Rich Styling – ANSI colors, bold prompts, and smooth animations.
  • JLine3-Powered – Sharp and precise.
  • Ready to use – Jump in straight to terminal components.
try (var presenter = ConsoleTerminalPresenter.standard()) {
   var actions = List.of("first", "second", "third", "fourth", "fifth");
   
   var choice = presenter.stringChoice("What action you want to perform?", actions);

   var confirmed = presenter.confirm(choice + " - are you sure?");

   if (confirmed) {
      presenter.successMessage("Action completed");
   }
}

🏰 Installation

Add the essence of DivaTerm to your project:

Gradle

dependencies {
    implementation("io.github.klakpin:divaterm:0.0.6")
}

Maven

<dependency>
    <groupId>io.github.klakpin</groupId>
    <artifactId>divaterm</artifactId>
    <version>0.0.6</version>
</dependency>

🩸 Quickstart

Awaken your terminal's power with the high-level presenter and use it directly:

var presenter = ConsoleTerminalPresenter.standard();

presenter.successMessage("Action completed");

Available components in presenter

Messages

  • plain
  • success
  • error
  • bracket
  • error bracket

Waiting

  • simple waiting
  • waiting with details
var waitingFuture = CompletableFuture.runAsync(() -> {
   try {
      Thread.sleep(5000);
   } catch (InterruptedException e) {
      throw new RuntimeException(e);
   }
});

presenter.waitWhile("Waiting 5 seconds", waitingFuture);

DivaTerm in action

Prompt

  • simple prompt
  • prompt with default value

Choice

  • string single choice
  • string multichoice
  • choice builder
var dessertsChoices = /* init choices */
        
var selectedChoice = presenter.choice(cb ->
   cb.withQuestion("What dessert you want to have today?")
          .withOptions(new ArrayList<>(dessertsChoices))
          .withMaxDisplayResults(5)
          .withFilteringEnabled(true)
          .withFilterSimilarityCutoff(0.7)
);

DivaTerm in action

var dessertsChoices = /* init choices */
        
var selectedChoice = presenter.multiChoice(cb ->
        cb.withQuestion("What dessert you want to have today?")
            .withOptions(new ArrayList<>(dessertsChoices))
            .withMaxDisplayResults(5)
            .withMaxSelectResults(3)
            .withFilteringEnabled(true)
        );

DivaTerm in action

Confirmation

presenter.confirm();

DivaTerm in action


πŸŒ™ Usage Options

DivaTerm offers three elegant ways to bring terminal magic to your Java applications:

  1. High-Level Presenter (Recommended)
    The simplest way to create beautiful terminal interfaces with minimal code:
    var presenter = ConsoleTerminalPresenter.standard();

Note: the high-level presenter assumes that application is run in interactive terminal with rich colors.

  1. Terminal Components Factory
    For more control, create individual components through our factory:

     // JLine terminal instance
     var terminal = new JlineTerminalFactory().buildTerminal();        
     // Color palette for elements                                                      
     var colorPalette = new DefaultTerminalColorPalette(Collections.emptyMap(), true);
     // Executor for drawing async updates, like in a waiting component
     var drawingExecutor = Executors.newSingleThreadScheduledExecutor();
    
     // Build components factory
     var factory = new TerminalComponentFactory(terminal, drawingExecutor, colorPalette);
    
     // Use factory to show the element
     factory.buildConfirm().confirm(confirmationText);

    Or get the components factory from the presenter

    var presenter = ConsoleTerminalPresenter.standard();
    vat factory = presenter.getComponentsFactory();
  2. Direct Components Usage
    For maximum flexibility, use components directly. Do not call the same component twice, most of them are single-use.

    // JLine terminal instance
    var terminal = new JlineTerminalFactory().buildTerminal();        
    // Color palette for elements                                                      
    var colorPalette = new DefaultTerminalColorPalette(Collections.emptyMap(), true);
    
    var messageComponent = new TerminalMessage(terminal, colorPalette);
    messageComponent.printMessage(message, ColorFeature.error);

🎢 Diva’s Hymn (Contributing)

This project thrives on elegant code and sharp fangs (bug reports).

  • Fork β†’ git clone β†’ Put your magic (code).
  • Submit a PR

βš”οΈ Chevalier (Sister Project)

For Micronaut/GraalVM warriors:
πŸ‘‰ Chevalier: The Elite CLI Runtime


πŸ“œ License

MIT – "Free as the night wind."

Attributions

This project uses:

"Sing, my Diva."

About

Set of terminal UI components for Java based on JLine 3

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages