Logo Search packages:      
Sourcecode: jline version File versions  Download package

String jline::ConsoleReader::readLine ( final String  prompt,
final Character  mask 
) throws IOException [inline]

Read a line from the in InputStream, and return the line (without any trailing newlines).

Parameters:
prompt the prompt to issue to the console, may be null.
Returns:
a line that is read from the terminal, or null if there was null input (e.g., CTRL-D was pressed).

Definition at line 515 of file ConsoleReader.java.

References backspace(), beep(), jline::CursorBuffer::buffer, jline::ConsoleOperations::CLEAR_SCREEN, clearScreen(), complete(), jline::ConsoleOperations::COMPLETE, jline::ConsoleOperations::DELETE_PREV_CHAR, jline::ConsoleOperations::DELETE_PREV_WORD, jline::ConsoleOperations::EXIT, finishBuffer(), flushConsole(), jline::Terminal::isSupported(), jline::ConsoleOperations::KILL_LINE, jline::ConsoleOperations::KILL_LINE_PREV, killLine(), mask, jline::ConsoleOperations::MOVE_TO_BEG, jline::ConsoleOperations::MOVE_TO_END, moveCursor(), moveHistory(), jline::ConsoleOperations::NEWLINE, jline::ConsoleOperations::NEXT_CHAR, jline::ConsoleOperations::NEXT_HISTORY, jline::ConsoleOperations::NEXT_WORD, paste(), jline::ConsoleOperations::PASTE, jline::ConsoleOperations::PREV_CHAR, jline::ConsoleOperations::PREV_HISTORY, jline::ConsoleOperations::PREV_WORD, printNewline(), putChar(), readBinding(), readLine(), jline::ConsoleOperations::REDISPLAY, resetLine(), setCursorPosition(), terminal, and jline::ConsoleOperations::UNKNOWN.

      {
            this.mask = mask;
            this.prompt = prompt;

            if (prompt != null && prompt.length () > 0)
            {
                  out.write (prompt);
                  out.flush ();
            }

            // if the terminal is unsupported, just use plain-java reading
            if (!terminal.isSupported ())
                  return readLine (in);

            while (true)
            {
                  int[] next = readBinding ();
                  if (next == null)
                        return null;

                  int c = next[0];
                  int code = next[1];

                  if (c == -1)
                        return null;

                  boolean success = true;

                  switch (code)
                  {
                        case EXIT: // ctrl-d
                              if (buf.buffer.length () == 0)
                                    return null;
                        case COMPLETE: // tab
                              success = complete ();
                              break;
                        case MOVE_TO_BEG:
                              success = setCursorPosition (0);
                              break;
                        case KILL_LINE: // CTRL-K
                              success = killLine ();
                              break;
                        case CLEAR_SCREEN: // CTRL-L
                              success = clearScreen ();
                              break;
                        case KILL_LINE_PREV: // CTRL-U
                              success = resetLine ();
                              break;
                        case NEWLINE: // enter
                              printNewline (); // output newline
                              return finishBuffer ();
                        case DELETE_PREV_CHAR: // backspace
                              success = backspace ();
                              break;
                        case MOVE_TO_END:
                              success = moveToEnd ();
                              break;
                        case PREV_CHAR:
                              success = moveCursor (-1) != 0;
                              break;
                        case NEXT_CHAR:
                              success = moveCursor (1) != 0;
                              break;
                        case NEXT_HISTORY:
                              success = moveHistory (true);
                              break;
                        case PREV_HISTORY:
                              success = moveHistory (false);
                              break;
                        case REDISPLAY:
                              break;
                        case PASTE:
                              success = paste ();
                              break;
                        case DELETE_PREV_WORD:
                              success = deletePreviousWord ();
                              break;
                        case PREV_WORD:
                              success = previousWord ();
                              break;
                        case NEXT_WORD:
                              success = nextWord ();
                              break;

                        case UNKNOWN:
                        default:
                              putChar (c, true);
                  }

                  if (!(success))
                        beep ();

                  flushConsole ();
            }
      }


Generated by  Doxygen 1.6.0   Back to index