{
String output;
try
{
StringBuilder sb = new StringBuilder();
Key inputKey;
do
{
CommandOperation input = commandInvocation.getInput();
inputKey = input.getInputKey();
if (inputKey == Key.CTRL_C || inputKey == Key.CTRL_D)
{
return null;
}
else if (inputKey == Key.BACKSPACE && sb.length() > 0)
{
sb.setLength(sb.length() - 1);
if (echo)
{
// move cursor left
out.print(Buffer.printAnsi("1D"));
out.flush();
// overwrite it with space
out.print(" ");
// move cursor back again
out.print(Buffer.printAnsi("1D"));
out.flush();
}
}
else if (inputKey.isPrintable())
{
if (echo)
out.print(inputKey.getAsChar());
sb.append(inputKey.getAsChar());
}
}
while (inputKey != Key.ENTER && inputKey != Key.ENTER_2);
output = (sb.length() == 0) ? null : sb.toString();
}