@Override
        public Entry<Integer, String> next() {
            if (index > last) {
                throw new NoSuchElementException();
            }
            int p = index++;
            return new AbstractMap.SimpleImmutableEntry<>(p, history.get(p));
        }
Handles running the Kafka metadata shell in interactive mode, where we accept input in real time.
shell/src/main/java/org/apache/kafka/shell/InteractiveShell.java