Class InputDecoder

java.lang.Object
com.googlecode.lanterna.input.InputDecoder

public class InputDecoder extends Object
Used to read the input stream character by character and generate Key objects to be put in the input queue.
  • Field Details

    • source

      private final Reader source
    • bytePatterns

      private final List<CharacterPattern> bytePatterns
    • currentMatching

      private final List<Character> currentMatching
    • seenEOF

      private boolean seenEOF
    • timeoutUnits

      private int timeoutUnits
  • Constructor Details

    • InputDecoder

      public InputDecoder(Reader source)
      Creates a new input decoder using a specified Reader as the source to read characters from
      Parameters:
      source - Reader to read characters from, will be wrapped by a BufferedReader
  • Method Details

    • 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 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, otherwise false
    • 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 IOException
      Reads and decodes the next key stroke from the input stream
      Parameters:
      blockingIO - If set to true, the call will not return until it has read at least one KeyStroke
      Returns:
      Key stroke read from the input stream, or null if none
      Throws:
      IOException - If there was an I/O error when reading from the input stream
    • getBestMatch

      private CharacterPattern.Matching getBestMatch(List<Character> characterSequence)