miniterm is the legacy Java 8+ implementation of the java-miniterm library — a minimal (~25KB) low-level terminal access library for Java.
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...
}
}
}var size = terminal.size();
System.out.println("The size of the terminal is " + size);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);
}
}//DEPS org.codejive.miniterm:miniterm:0.1.5<dependency>
<groupId>org.codejive.miniterm</groupId>
<artifactId>miniterm</artifactId>
<version>0.1.5</version>
</dependency>implementation("org.codejive.miniterm:miniterm:0.1.5")./mvnw clean installThe 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/runWindows:
examples\run.batThe 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