Skip to content

Latest commit

 

History

History
95 lines (70 loc) · 2.03 KB

File metadata and controls

95 lines (70 loc) · 2.03 KB

miniterm

miniterm is the legacy Java 8+ implementation of the java-miniterm library — a minimal (~25KB) low-level terminal access library for Java.

Usage

import org.codejive.miniterm.Terminal;

public class Example {
    public static void main(String[] args) throws Exception {
        try (Terminal terminal = Terminal.create()) {
            // Do terminal stuff here...
        }
    }
}

Get terminal size

var size = terminal.size();
System.out.println("The size of the terminal is " + size);

Read key presses

terminal.enableRawMode();
while (true) {
    int key = terminal.read(1000);
    if (key == -1 || key == 3) { // Ctrl+C
        break; // End of stream
    } else if (key >= 0) {
        System.out.println("Key pressed: " + key);
    }
}

Adding the dependency

JBang

//DEPS org.codejive.miniterm:miniterm:0.1.5

Maven

<dependency>
    <groupId>org.codejive.miniterm</groupId>
    <artifactId>miniterm</artifactId>
    <version>0.1.5</version>
</dependency>

Gradle

implementation("org.codejive.miniterm:miniterm:0.1.5")

Building

./mvnw clean install

Running examples

The examples/ folder in the project root contains several ready-to-run examples. Use the provided scripts to pick and run one interactively:

Linux/macOS:

./examples/run

Windows:

examples\run.bat

The scripts will list the available examples and let you choose one to run:

  • FunShootingGallery - simplistic game showing usage of the different APIs
  • PrintAnsi — prints the the ANSI sequence of each key pressed
  • PrintCaps — prints the capabilities that the terminal supports
  • PrintColors — detects and prints the colors that the terminal supports
  • PrintKeys — prints the code of each key pressed
  • PrintMouse — prints mouse events
  • PrintSize — prints the current terminal dimensions
  • WatchSize — watches and prints terminal size changes in real time