protected TerminalSize waitForTerminalSizeReport(int timeoutMs) {
        long startTime = System.currentTimeMillis();
        synchronized(readMutex) {
            while(System.currentTimeMillis() - startTime < timeoutMs) {
                Key key = inputDecoder.getNextCharacter();
                if(key == null) {
                    try {
                        Thread.sleep(1);
                    }
                    catch(InterruptedException e) {}
                    continue;
                }
                
                if(key.getKind() != Key.Kind.CursorLocation) {
                    keyQueue.add(key);
                }
                else {
                    TerminalPosition reportedTerminalPosition = inputDecoder.getLastReportedTerminalPosition();
                    if(reportedTerminalPosition != null)
                        onResized(reportedTerminalPosition.getColumn(), reportedTerminalPosition.getRow());
                    else
                        throw new LanternaException(new IOException("Unexpected: inputDecoder.getLastReportedTerminalPosition() "
                                + "returned null after position was reported"));
                    return new TerminalSize(reportedTerminalPosition.getColumn(), reportedTerminalPosition.getRow());
                }                    
            }
        }
        throw new LanternaException(
                new IOException(
                    "Timeout while waiting for terminal size report! "
                    + "Maybe your terminal doesn't support cursor position report, please "
                    + "consider using a custom size querier"));
    }