Interface LineReader

All Known Implementing Classes:
LineReaderImpl

public interface LineReader
Read lines from the console, with input editing.

Thread safety

The LineReader implementations are not thread safe, thus you should not attempt to use a single reader in several threads. Any attempt to call one of the readLine call while one is already executing in a different thread will immediately result in an IllegalStateException being thrown. Other calls may lead to unknown behaviors. There is one exception though: users are allowed to call printAbove(String) or printAbove(AttributedString) at any time to allow text to be printed above the current prompt.

Prompt strings

It is traditional for an interactive console-based program to print a short prompt string to signal that the user is expected to type a command. JLine supports 3 kinds of prompt string:
  • The normal prompt at the start (left) of the initial line of a command.
  • An optional right prompt at the right border of the initial line.
  • A start (left) prompt for continuation lines. I.e. the lines after the first line of a multi-line command.

All of these are specified with prompt templates, which are similar to printf format strings, using the character '%' to indicate special functionality.

The pattern may include ANSI escapes. It may include these template markers:
%N
A line number. This is the sum of getLineNumber() and a counter starting with 1 for the first continuation line.
%M
A short word explaining what is "missing". This is supplied from the EOFError.getMissing() method, if provided. Defaults to an empty string.
%nPc
Insert padding at this position, repeating the following character c as needed to bring the total prompt column width as specified by the digits n.
%Pc
As before, but use width from the initial prompt.
%%
A literal '%'.
%{
%}
Text between a %{...%} pair is printed as part of a prompt, but not interpreted by JLine (except that '%'-escapes are processed). The text is assumed to take zero columns (not move the cursor). If it changes the style, you're responsible for changing it back. Standard ANSI escape sequences do not need to be within a %{...%} pair (though can be) since JLine knows how to deal with them. However, these delimiters are needed for unusual non-standard escape sequences.