Package org.jline.terminal.impl
Class LineDisciplineTerminal
- java.lang.Object
-
- org.jline.terminal.impl.AbstractTerminal
-
- org.jline.terminal.impl.LineDisciplineTerminal
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
,Terminal
- Direct Known Subclasses:
ExternalTerminal
public class LineDisciplineTerminal extends AbstractTerminal
Abstract terminal with support for line discipline. TheTerminal
interface represents the slave side of a PTY, but implementations derived from this class will handle both the slave and master side of things. In order to correctly handle line discipline, the terminal needs to read the input in advance in order to raise the signals as fast as possible. For example, when the user hits Ctrl+C, we can't wait until the application consumes all the read events. The same applies to echoing, when enabled, as the echoing has to happen as soon as the user hit the keyboard, and not only when the application running in the terminal processes the input.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
LineDisciplineTerminal.FilteringOutputStream
-
Nested classes/interfaces inherited from interface org.jline.terminal.Terminal
Terminal.MouseTracking, Terminal.Signal, Terminal.SignalHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected Attributes
attributes
Console dataprivate static java.lang.String
DEFAULT_TERMINAL_ATTRIBUTES
protected java.io.OutputStream
masterOutput
private static int
PIPE_SIZE
protected Size
size
protected NonBlockingPumpInputStream
slaveInput
protected java.io.OutputStream
slaveInputPipe
protected java.io.OutputStream
slaveOutput
protected NonBlockingReader
slaveReader
protected java.io.PrintWriter
slaveWriter
-
Fields inherited from class org.jline.terminal.impl.AbstractTerminal
bools, encoding, handlers, ints, name, onClose, palette, status, strings, type
-
Fields inherited from interface org.jline.terminal.Terminal
TYPE_DUMB, TYPE_DUMB_COLOR
-
-
Constructor Summary
Constructors Constructor Description LineDisciplineTerminal(java.lang.String name, java.lang.String type, java.io.OutputStream masterOutput, java.nio.charset.Charset encoding)
LineDisciplineTerminal(java.lang.String name, java.lang.String type, java.io.OutputStream masterOutput, java.nio.charset.Charset encoding, Terminal.SignalHandler signalHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doClose()
protected boolean
doProcessInputByte(int c)
Attributes
getAttributes()
Returns the terminal attributes.Size
getSize()
Retrieve the size of the visible windowjava.io.InputStream
input()
Retrieve the input stream for this terminal.java.io.OutputStream
output()
Retrieve the output stream for this terminal.void
processInputByte(int c)
Master input processing.void
processInputBytes(byte[] input)
void
processInputBytes(byte[] input, int offset, int length)
protected void
processIOException(java.io.IOException ioException)
protected void
processOutputByte(int c)
Master output processing.void
raise(Terminal.Signal signal)
NonBlockingReader
reader()
Retrieve theReader
for this terminal.void
setAttributes(Attributes attr)
Set the terminal attributes.void
setSize(Size sz)
java.io.PrintWriter
writer()
Retrieve theWriter
for this terminal.-
Methods inherited from class org.jline.terminal.impl.AbstractTerminal
canPauseResume, checkInterrupted, close, echo, echo, echoSignal, encoding, enterRawMode, flush, getBooleanCapability, getCursorPosition, getKind, getName, getNumericCapability, getPalette, getStatus, getStatus, getStringCapability, getType, handle, hasFocusSupport, hasMouseSupport, parseInfoCmp, pause, pause, paused, puts, readMouseEvent, readMouseEvent, resume, setOnClose, trackFocus, trackMouse
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jline.terminal.Terminal
getBufferSize, getHeight, getWidth
-
-
-
-
Field Detail
-
DEFAULT_TERMINAL_ATTRIBUTES
private static final java.lang.String DEFAULT_TERMINAL_ATTRIBUTES
- See Also:
- Constant Field Values
-
PIPE_SIZE
private static final int PIPE_SIZE
- See Also:
- Constant Field Values
-
masterOutput
protected final java.io.OutputStream masterOutput
-
slaveInputPipe
protected final java.io.OutputStream slaveInputPipe
-
slaveInput
protected final NonBlockingPumpInputStream slaveInput
-
slaveReader
protected final NonBlockingReader slaveReader
-
slaveWriter
protected final java.io.PrintWriter slaveWriter
-
slaveOutput
protected final java.io.OutputStream slaveOutput
-
attributes
protected final Attributes attributes
Console data
-
size
protected final Size size
-
-
Constructor Detail
-
LineDisciplineTerminal
public LineDisciplineTerminal(java.lang.String name, java.lang.String type, java.io.OutputStream masterOutput, java.nio.charset.Charset encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
LineDisciplineTerminal
public LineDisciplineTerminal(java.lang.String name, java.lang.String type, java.io.OutputStream masterOutput, java.nio.charset.Charset encoding, Terminal.SignalHandler signalHandler) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
reader
public NonBlockingReader reader()
Description copied from interface:Terminal
Retrieve theReader
for this terminal. This is the standard way to read input from this terminal. The reader is non blocking.- Returns:
- The non blocking reader
-
writer
public java.io.PrintWriter writer()
Description copied from interface:Terminal
Retrieve theWriter
for this terminal. This is the standard way to write to this terminal.- Returns:
- The writer
-
input
public java.io.InputStream input()
Description copied from interface:Terminal
Retrieve the input stream for this terminal. In some rare cases, there may be a need to access the terminal input stream directly. In the usual cases, use theTerminal.reader()
instead.- Returns:
- The input stream
- See Also:
Terminal.reader()
-
output
public java.io.OutputStream output()
Description copied from interface:Terminal
Retrieve the output stream for this terminal. In some rare cases, there may be a need to access the terminal output stream directly. In the usual cases, use theTerminal.writer()
instead.- Returns:
- The output stream
- See Also:
Terminal.writer()
-
getAttributes
public Attributes getAttributes()
Description copied from interface:Terminal
Returns the terminal attributes. The returned object can be safely modified further used in a call toTerminal.setAttributes(Attributes)
.- Returns:
- the terminal attributes.
-
setAttributes
public void setAttributes(Attributes attr)
Description copied from interface:Terminal
Set the terminal attributes. The terminal will perform a copy of the given attributes.- Parameters:
attr
- the new attributes
-
getSize
public Size getSize()
Description copied from interface:Terminal
Retrieve the size of the visible window- Returns:
- the visible terminal size
- See Also:
Terminal.getBufferSize()
-
setSize
public void setSize(Size sz)
-
raise
public void raise(Terminal.Signal signal)
- Specified by:
raise
in interfaceTerminal
- Overrides:
raise
in classAbstractTerminal
-
processInputByte
public void processInputByte(int c) throws java.io.IOException
Master input processing. All data coming to the terminal should be provided using this method.- Parameters:
c
- the input byte- Throws:
java.io.IOException
- if anything wrong happens
-
processInputBytes
public void processInputBytes(byte[] input) throws java.io.IOException
- Throws:
java.io.IOException
-
processInputBytes
public void processInputBytes(byte[] input, int offset, int length) throws java.io.IOException
- Throws:
java.io.IOException
-
doProcessInputByte
protected boolean doProcessInputByte(int c) throws java.io.IOException
- Throws:
java.io.IOException
-
processOutputByte
protected void processOutputByte(int c) throws java.io.IOException
Master output processing. All data going to the master should be provided by this method.- Parameters:
c
- the output byte- Throws:
java.io.IOException
- if anything wrong happens
-
processIOException
protected void processIOException(java.io.IOException ioException)
-
doClose
protected void doClose() throws java.io.IOException
- Overrides:
doClose
in classAbstractTerminal
- Throws:
java.io.IOException
-
-