public ConsoleReader initializeConsoleReader(InputStream inputStream) throws IOException {
    if (inputStream != null) {
      // ### NOTE: fix for sf.net bug 879425.
      // Working around an issue in jline-2.1.2, see https://github.com/jline/jline/issues/10
      // by appending a newline to the end of inputstream
      InputStream inputStreamAppendedNewline = new SequenceInputStream(inputStream,
          new ByteArrayInputStream((new String("\n")).getBytes()));
      consoleReader = new ConsoleReader(inputStreamAppendedNewline, getErrorStream());
      consoleReader.setCopyPasteDetection(true); // jline will detect if <tab> is regular character
    } else {
      consoleReader = new ConsoleReader(getInputStream(), getErrorStream());
    }

    //disable the expandEvents for the purpose of backward compatibility
    consoleReader.setExpandEvents(false);

    try {
      // now set the output for the history
      if (this.history != null) {
        consoleReader.setHistory(this.history);
      } else {
        consoleReader.setHistoryEnabled(false);
      }
    } catch (Exception e) {
      handleException(e);
    }

    if (inputStream instanceof FileInputStream || inputStream instanceof FSDataInputStream) {
      // from script.. no need to load history and no need of completer, either
      return consoleReader;
    }

    consoleReader.addCompleter(new BeeLineCompleter(this));
    return consoleReader;
  }
Start accepting input from stdin, and dispatch it
to the appropriate {@link CommandHandler} until the
global variable <code>exit</code> is true.
beeline/src/java/org/apache/hive/beeline/BeeLine.java