JLine is a Java library for handling console input.
JLine is a Java library for handling console input. It’s similar to GNU Readline but with a focus on portability, flexibility, and integration with Java applications. See https://jline.org for its documentation.
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
<version>3.30.0</version>
</dependency>
implementation 'org.jline:jline:3.30.0'
Here’s a simple example to get you started:
import org.jline.reader.*;
import org.jline.reader.impl.*;
import org.jline.terminal.*;
import org.jline.terminal.impl.*;
public class HelloJLine {
public static void main(String[] args) {
try {
// Create a terminal
Terminal terminal = TerminalBuilder.builder()
.system(true)
.build();
// Create line reader
LineReader reader = LineReaderBuilder.builder()
.terminal(terminal)
.build();
// Prompt and read input
String line = reader.readLine("JLine > ");
// Print the result
System.out.println("You entered: " + line);
} catch (Exception e) {
e.printStackTrace();
}
}
}
JLine is organized into several modules:
JLine is licensed under the BSD License.
Contributions are welcome! Please feel free to submit a Pull Request.