void readInputLoop()

in common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java [499:536]


    void readInputLoop() {
        try {
            while (!closing) {
                if (readInput.readLock().tryLock(10, TimeUnit.MILLISECONDS)) {
                    if (projectReadingInput != null) {
                        char[] buf = new char[256];
                        int idx = 0;
                        while (idx < buf.length) {
                            int c = terminal.reader().read(idx > 0 ? 1 : 10);
                            if (c < 0) {
                                break;
                            }
                            buf[idx++] = (char) c;
                        }
                        if (idx > 0) {
                            String data = String.valueOf(buf, 0, idx);
                            daemonReceive.accept(Message.inputResponse(data));
                        }
                    } else {
                        int c = terminal.reader().read(10);
                        if (c == -1) {
                            break;
                        }
                        if (c == KEY_PLUS || c == KEY_MINUS || c == KEY_CTRL_L || c == KEY_CTRL_M || c == KEY_CTRL_B) {
                            daemonReceive.accept(Message.keyboardInput((char) c));
                        }
                    }
                    readInput.readLock().unlock();
                }
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (InterruptedIOException e) {
            Thread.currentThread().interrupt();
        } catch (IOException e) {
            this.exception = e;
        }
    }