public void open(CliShell shell, QueryResult queryResult) throws ExecutorException {
    terminal = shell.getTerminal();
    executor = shell.getExecutor();
    exeContext = shell.getExeContext();

    TerminalStatus prevStatus = setupTerminal();
    try {
      keyReader = new BindingReader(terminal.reader());
      inputThread = new InputThread();
      inputThread.start();
      while (keepRunning) {
        try {
          display();
          if (keepRunning)
            Thread.sleep(refreshInterval);
        } catch (InterruptedException e) {
        }
      }

      try {
        inputThread.join(1 * 1000);
      } catch (InterruptedException e) {
      }
    } finally {
      restoreTerminal(prevStatus);
      if (inputThread.isAlive()) {
        terminal.writer().println("Warning: input thread hang. Have to kill!");
        terminal.writer().flush();
        inputThread.interrupt();
      }
    }

  }
A scrolling (logging) view of the query result of a streaming SELECT statement.
samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/QueryResultLogView.java