Top Description Inners Fields Constructors Methods
org.python.util

public Class JLineConsole

extends PlainConsole
Class Inheritance
Imports
java.io.EOFException, .File, .FileDescriptor, .FileInputStream, .FilterInputStream, .IOException, .InputStream, .PrintStream, java.util.Arrays, .List, jline.console.ConsoleReader, jline.WindowsTerminal, jline.console.history.FileHistory, jnr.constants.platform.Errno, org.python.core.PlainConsole, .PyObject, .Py

This class uses JLine to provide readline like functionality to its console without requiring native readline support.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class
JLineConsole.Stream

Class to wrap the line-oriented interface to JLine with an InputStream that can replace System.in.

Field Summary

Modifier and TypeField and Description
protected static final String
CTRL_Z

The ctrl-z character String.

private ConsoleOutputStream
outWrapper

Stream wrapping System.out in order to capture the last prompt.

protected PyObject
pre_input_hook

Not currently set by readline.set_pre_input_hook.

public ConsoleReader
reader

Main interface to JLine.

protected PyObject
startup_hook

Callable object set by readline.set_startup_hook.

private static final List<String>
SUSPENDED_STRERRORS

Errno strerrors possibly caused by a SIGSTP (ctrl-z).

private boolean
windows

Whether reader is a WindowsTerminal.

Inherited from org.python.core.PlainConsole:
encodingencodingCharset

Constructor Summary

AccessConstructor and Description
public
JLineConsole(String
name of a supported encoding or null for Charset.defaultCharset()
encoding
)

Construct an instance of the console class specifying the character encoding.

Method Summary

Modifier and TypeMethod and Description
private boolean
fromSuspend(IOException ioe)

Determine if the IOException was likely caused by a SIGSTP (ctrl-z).

public ConsoleReader

Returns:

the JLine console reader associated with this interpreter
getReader
()

public PyObject

Returns:

the startup hook (called prior to each readline)
getStartupHook
()

public void
install()

Overrides org.python.core.PlainConsole.install.

Implements org.python.core.Console.install.

Complete initialization and (optionally) install a stream object with line-editing as the replacement for System.in.

private boolean
isEOF(String line)

Determine if line denotes an EOF.

private String

Returns:

line of text read in
readerReadLine
(String
to display
prompt
)

Wrapper on reader.readLine(prompt) that deals with retries (on Unix) when the user enters ctrl-Z to background Jython, then brings it back to the foreground.

public void
setStartupHook(PyObject hook)

Sets the startup hook (called prior to each readline)

Inherited from org.python.core.PlainConsole:
getEncodinggetEncodingCharsetuninstall

Field Detail

CTRL_Zback to summary
protected static final String CTRL_Z

The ctrl-z character String.

outWrapperback to summary
private ConsoleOutputStream outWrapper

Stream wrapping System.out in order to capture the last prompt.

pre_input_hookback to summary
protected PyObject pre_input_hook

Not currently set by readline.set_pre_input_hook. Why not?

readerback to summary
public ConsoleReader reader

Main interface to JLine.

startup_hookback to summary
protected PyObject startup_hook

Callable object set by readline.set_startup_hook.

SUSPENDED_STRERRORSback to summary
private static final List<String> SUSPENDED_STRERRORS

Errno strerrors possibly caused by a SIGSTP (ctrl-z). They may propagate up to IOException messages.

windowsback to summary
private boolean windows

Whether reader is a WindowsTerminal.

Constructor Detail

JLineConsoleback to summary
public JLineConsole(String encoding)

Construct an instance of the console class specifying the character encoding. This encoding must be one supported by the JVM.

Most of the initialisation is deferred to the install() method so that any prior console can uninstall itself before we change system console settings and System.in.

Parameters
encoding:String

name of a supported encoding or null for Charset.defaultCharset()

Method Detail

fromSuspendback to summary
private boolean fromSuspend(IOException ioe)

Determine if the IOException was likely caused by a SIGSTP (ctrl-z). Seems only applicable to BSD platforms.

getReaderback to summary
public ConsoleReader getReader()
Returns:ConsoleReader

the JLine console reader associated with this interpreter

getStartupHookback to summary
public PyObject getStartupHook()
Returns:PyObject

the startup hook (called prior to each readline)

installback to summary
public void install()

Overrides org.python.core.PlainConsole.install.

Implements org.python.core.Console.install.

Doc from org.python.core.Console.install.

Complete initialization and (optionally) install a stream object with line-editing as the replacement for System.in.

This implementation overrides that by setting System.in to a FilterInputStream object that wraps JLine, and System.out with a layer that buffers incomplete lines for use as the console prompt.

Annotations
@Override
isEOFback to summary
private boolean isEOF(String line)

Determine if line denotes an EOF.

readerReadLineback to summary
private String readerReadLine(String prompt) throws IOException, EOFException

Wrapper on reader.readLine(prompt) that deals with retries (on Unix) when the user enters ctrl-Z to background Jython, then brings it back to the foreground. The inherited implementation says this is necessary and effective on BSD Unix.

Parameters
prompt:String

to display

Returns:String

line of text read in

Exceptions
IOException:
if an error occurs (other than an end of suspension)
EOFException:
if an EOF is detected

setStartupHookback to summary
public void setStartupHook(PyObject hook)

Sets the startup hook (called prior to each readline)

org.python.util back to summary

private Class JLineConsole.HistoryCloser

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
pack-priv FileHistory

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

historyback to summary
pack-priv FileHistory history

Constructor Detail

HistoryCloserback to summary
public HistoryCloser(FileHistory history)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
org.python.util back to summary

private Class JLineConsole.Stream

extends ConsoleInputStream
Class Inheritance

Class to wrap the line-oriented interface to JLine with an InputStream that can replace System.in.

Field Summary

Inherited from org.python.util.ConsoleInputStream:
EMPTY_BUFencodingeoleolPolicyLINE_SEPARATOR

Constructor Summary

AccessConstructor and Description
pack-priv
Stream()

Create a System.in replacement with JLine that adds system-specific line endings

Method Summary

Modifier and TypeMethod and Description
protected CharSequence
getLine()

Implements abstract org.python.util.ConsoleInputStream.getLine.

Get one line of input from the console.

Inherited from org.python.util.ConsoleInputStream:
availablemarkmarkSupportedreadreadresetskip

Constructor Detail

Streamback to summary
pack-priv Stream()

Create a System.in replacement with JLine that adds system-specific line endings

Method Detail

getLineback to summary
protected CharSequence getLine() throws IOException, EOFException

Implements abstract org.python.util.ConsoleInputStream.getLine.

Doc from org.python.util.ConsoleInputStream.getLine.

Get one line of input from the console. Override this method with the actions specific to the library in use.

Returns:CharSequence

Line entered by user

Annotations
@Override
Exceptions
IOException:
in case of an error
EOFException:
if the library recognises an end-of-file condition