- java.lang.Object
-
- com.googlecode.lanterna.input.InputDecoder
-
public class InputDecoder extends java.lang.Object
Used to read the input stream character by character and generateKey
objects to be put in the input queue.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<CharacterPattern>
bytePatterns
private java.util.List<java.lang.Character>
currentMatching
private boolean
seenEOF
private java.io.Reader
source
private int
timeoutUnits
-
Constructor Summary
Constructors Constructor Description InputDecoder(java.io.Reader source)
Creates a new input decoder using a specified Reader as the source to read characters from
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProfile(KeyDecodingProfile profile)
Adds another key decoding profile to this InputDecoder, which means all patterns from the profile will be used when decoding input.private CharacterPattern.Matching
getBestMatch(java.util.List<java.lang.Character> characterSequence)
KeyStroke
getNextCharacter(boolean blockingIO)
Reads and decodes the next key stroke from the input streamjava.util.Collection<CharacterPattern>
getPatterns()
Returns a collection of all patterns registered in this InputDecoder.int
getTimeoutUnits()
queries the current timeoutUnits value.boolean
removePattern(CharacterPattern pattern)
Removes one pattern from the list of patterns in this InputDecodervoid
setTimeoutUnits(int units)
Sets the number of 1/4-second units for how long to try to get further input to complete an escape-sequence for a special Key.
-
-
-
Field Detail
-
source
private final java.io.Reader source
-
bytePatterns
private final java.util.List<CharacterPattern> bytePatterns
-
currentMatching
private final java.util.List<java.lang.Character> currentMatching
-
seenEOF
private boolean seenEOF
-
timeoutUnits
private int timeoutUnits
-
-
Method Detail
-
addProfile
public void addProfile(KeyDecodingProfile profile)
Adds another key decoding profile to this InputDecoder, which means all patterns from the profile will be used when decoding input.- Parameters:
profile
- Profile to add
-
getPatterns
public java.util.Collection<CharacterPattern> getPatterns()
Returns a collection of all patterns registered in this InputDecoder.- Returns:
- Collection of patterns in the InputDecoder
-
removePattern
public boolean removePattern(CharacterPattern pattern)
Removes one pattern from the list of patterns in this InputDecoder- Parameters:
pattern
- Pattern to remove- Returns:
true
if the supplied pattern was found and was removed, otherwisefalse
-
setTimeoutUnits
public void setTimeoutUnits(int units)
Sets the number of 1/4-second units for how long to try to get further input to complete an escape-sequence for a special Key. Negative numbers are mapped to 0 (no wait at all), and unreasonably high values are mapped to a maximum of 240 (1 minute).- Parameters:
units
- New timeout to use, in 250ms units
-
getTimeoutUnits
public int getTimeoutUnits()
queries the current timeoutUnits value. One unit is 1/4 second.- Returns:
- The timeout this InputDecoder will use when waiting for additional input, in units of 1/4 seconds
-
getNextCharacter
public KeyStroke getNextCharacter(boolean blockingIO) throws java.io.IOException
Reads and decodes the next key stroke from the input stream- Parameters:
blockingIO
- If set totrue
, the call will not return until it has read at least oneKeyStroke
- Returns:
- Key stroke read from the input stream, or
null
if none - Throws:
java.io.IOException
- If there was an I/O error when reading from the input stream
-
getBestMatch
private CharacterPattern.Matching getBestMatch(java.util.List<java.lang.Character> characterSequence)
-
-