1- # miniterm
1+ # java- miniterm
22
3- A minimal terminal library.
3+ miniterm is a Java library that provides low-level terminal access. Its main selling point is that it is extremely small (~ 25KB), making it ideal for CLI tools and applications where keeping dependencies lightweight matters.
4+
5+ Two variants are available:
6+ - ** ` miniterm ` ** — legacy implementation, works with Java 8+
7+ - ** ` miniterm-ffm ` ** — modern implementation using the Foreign Function & Memory API, requires Java 22+
8+
9+ ## Usage
10+
11+ ``` java
12+ import org.codejive.miniterm.Terminal ;
13+
14+ public class Example {
15+ public static void main (String [] args ) throws Exception {
16+ try (Terminal terminal = Terminal . create()) {
17+ // Do terminal stuff here...
18+ }
19+ }
20+ }
21+ ```
22+
23+ ### Get terminal size
24+
25+ ``` java
26+ var size = terminal. getSize();
27+ System . out. println(" The size of the terminal is " + size);
28+ ```
29+
30+ ### Read key presses
31+
32+ ``` java
33+ terminal. enableRawMode();
34+ while (true ) {
35+ int key = terminal. read(1000 );
36+ if (key == - 1 || key == 3 ) { // Ctrl+C
37+ break ; // End of stream
38+ } else if (key >= 0 ) {
39+ System . out. println(" Key pressed: " + key);
40+ }
41+ }
42+ ```
43+
44+ ## Adding the dependency
45+
46+ ### JBang
47+
48+ ``` java
49+ // DEPS org.codejive.miniterm:miniterm:0.1.0
50+ ```
51+
52+ For the FFM variant (Java 22+):
53+
54+ ``` java
55+ // DEPS org.codejive.miniterm:miniterm-ffm:0.1.0
56+ ```
57+
58+ ### Maven
59+
60+ ``` xml
61+ <dependency >
62+ <groupId >org.codejive.miniterm</groupId >
63+ <artifactId >miniterm</artifactId >
64+ <version >0.1.0</version >
65+ </dependency >
66+ ```
67+
68+ For the FFM variant (Java 22+):
69+
70+ ``` xml
71+ <dependency >
72+ <groupId >org.codejive.miniterm</groupId >
73+ <artifactId >miniterm-ffm</artifactId >
74+ <version >0.1.0</version >
75+ </dependency >
76+ ```
77+
78+ ### Gradle
79+
80+ ``` kotlin
81+ implementation(" org.codejive.miniterm:miniterm:0.1.0" )
82+ ```
83+
84+ For the FFM variant (Java 22+):
85+
86+ ``` kotlin
87+ implementation(" org.codejive.miniterm:miniterm-ffm:0.1.0" )
88+ ```
489
590## Building
691
@@ -10,8 +95,30 @@ A minimal terminal library.
1095
1196## Running examples
1297
98+ The ` examples/ ` folder contains several ready-to-run examples. Use the provided scripts to pick and run one interactively:
99+
100+ ** Linux/macOS:**
101+
13102``` bash
14- ./jbang --java 22+ -R--enable-native-access=ALL-UNNAMED --cp target/miniterm-* .jar src/test/java/examples/PrintKeys.java
15- ./jbang --java 22+ -R--enable-native-access=ALL-UNNAMED --cp target/miniterm-* .jar src/test/java/examples/PrintSize.java
16- ./jbang --java 22+ -R--enable-native-access=ALL-UNNAMED --cp target/miniterm-* .jar src/test/java/examples/WatchSize.java
103+ # Using the legacy (Java 8+) implementation
104+ ./examples/run
105+
106+ # Using the FFM (Java 22+) implementation
107+ ./examples/run-ffm
17108```
109+
110+ ** Windows:**
111+
112+ ``` batch
113+ :: Using the legacy (Java 8+) implementation
114+ examples\run.bat
115+
116+ :: Using the FFM (Java 22+) implementation
117+ examples\run-ffm.bat
118+ ```
119+
120+ The scripts will list the available examples and let you choose one to run:
121+
122+ - ** PrintSize** — prints the current terminal dimensions
123+ - ** WatchSize** — watches and prints terminal size changes in real time
124+ - ** PrintKeys** — prints the code of each key pressed (Ctrl+C to exit)
0 commit comments