java.lang.Object
it.polimi.ingsw.view.cli.console.RawConsoleInput
public class RawConsoleInput
extends java.lang.Object
Console input utilities
-
Constructor Summary
Constructors Constructor Description RawConsoleInput(int maxBufferSize)
-
Method Summary
Modifier and Type Method Description void
addKeyEventListener(KeyEventListener listener)
Adds a new key event listener
If the listener already was in the listeners list, nothing happensprotected int
currentBufferSize()
Provides the current size of the input string stored in the bufferint
currentInputSize()
Provides the number of printable characters in the buffervoid
disableConsoleInput()
Disables the console inputvoid
enableConsoleInput()
Enables the console inputvoid
flushBuffer()
java.lang.String
getCurrentBuffer()
int
getMaxBufferSize()
maxBufferSize getterboolean
hasNext()
Returns true if this scanner has another token in its input.boolean
isConsoleInputEnabled()
Determines if the console input is enabledprotected void
listenForRawInput()
Constantly listens for keystrokesprotected void
listenForStandardInput()
java.lang.String
nextLine()
Returns the last line read and empties the buffervoid
removeKeyEventListener(KeyEventListener listener)
Removes a key event listener
If the listener was not in the listeners list, nothing happens
-
Constructor Details
-
RawConsoleInput
public RawConsoleInput(int maxBufferSize)
-
-
Method Details
-
listenForRawInput
protected void listenForRawInput()Constantly listens for keystrokes -
listenForStandardInput
protected void listenForStandardInput() -
getMaxBufferSize
public int getMaxBufferSize()maxBufferSize getter- Returns:
- the input buffer maximum size
-
getCurrentBuffer
public java.lang.String getCurrentBuffer() -
flushBuffer
public void flushBuffer() -
nextLine
public java.lang.String nextLine()Returns the last line read and empties the buffer- Returns:
- the next line
-
hasNext
public boolean hasNext()Returns true if this scanner has another token in its input.- Returns:
- true if and only if this scanner has another token
-
currentInputSize
public int currentInputSize()Provides the number of printable characters in the buffer- Returns:
- the number of characters in the buffer
-
addKeyEventListener
Adds a new key event listener
If the listener already was in the listeners list, nothing happens- Parameters:
listener
- the listener to add
-
removeKeyEventListener
Removes a key event listener
If the listener was not in the listeners list, nothing happens- Parameters:
listener
- the listener to remove
-
currentBufferSize
protected int currentBufferSize()Provides the current size of the input string stored in the buffer- Returns:
- the input length
-
isConsoleInputEnabled
public boolean isConsoleInputEnabled()Determines if the console input is enabledling or disabling the console input does not affect the listenForRawInput() method in any way;
- Input enabled: the console works as usual, registering all keystrokes and adding new characters in the buffer
- Input disabled: no echo is provided, "locking" the cursor in place; the console just ignores the keystrokes, not filling the buffer.
- Returns:
- true if the input is enabled, false otherwise
-
enableConsoleInput
public void enableConsoleInput()Enables the console input- See Also:
isConsoleInputEnabled()
-
disableConsoleInput
public void disableConsoleInput()Disables the console input- See Also:
isConsoleInputEnabled()
-