JTerminal documentation Help

LineReader

The LineReader class contains settings for reading out command lines as well as the current state of the line input.

Flags

Certain options can be selected when reading the lines:

LineReader lineReader = terminal.lineReader(); lineReader.flags(LineReader.FLAG_???);

Flag (byte)

Description

(0x01) FLAG_INSERT_MODE

All characters to the right of the text cursor are moved to the right when they are entered.

(0x02) FLAG_ECHO_MODE

When entering the line value, all characters are displayed.

(0x04) FLAG_QUICK_DELETE

Pressing the Backspace key deletes the entire line.

(0x08) FLAG_KEEP_LINE

When the Enter key is pressed, the line entered remains visible.

(0x10) FLAG_NAVIGABLE_CURSOR

The text cursor can be moved freely within the line using the arrow keys.

Default flags: FLAG_INSERT_MODE, FLAG_ECHO_MODE, FLAG_KEEP_LINE, FLAG_NAVIGABLE_CURSOR

Input History

The input history saves all lines and these can be called up using the up/down arrow keys. to call them up.

LineReader lineReader = terminal.lineReader(); lineReader.inputHistory(InputHistory.create(true));

TabCompleter

The TabCompleter specifies strings at certain positions. These suggestions can be called up using the tabulator key.

RawTabCompleter tabCompleter = new RawTabCompleter(0); tabCompleter.addSuggestions("Test", "house", "console"); LineReader lineReader = terminal.lineReader(); lineReader.tabCompleter(tabCompleter);

Read lines

There are several ways to read lines:

LineReader lineReader = terminal.lineReader(); String value = lineReader.readLine();
terminal.eventBus().subscribe(LineReleaseEvent.class, event -> { terminal.writeLine("Line released: " + event.line()); });
terminal.readLine(prefix...) terminal.readPassword(prefix...)

Line Renderer

There are ways to change the display of the command line. Prefixes are often used in the command line, which are displayed on the left-hand side of the line. To add your own, the following setting must be made:

LineReader lineReader = terminal.lineReader(); lineReader.lineRenderer(new PrefixedLineRenderer(() -> TermString.builder() .foregroundColor(TerminalColor.RED) .append(">> ") .resetStyle() .build()));
Last modified: 01 Juni 2025