@Override
    protected TerminalSize calculatePreferredSize() {
        int width = preferredSize.getColumns() > 0 ? preferredSize.getColumns() : longestLine + 1;
        int height = preferredSize.getRows() > 0 ? preferredSize.getRows() : lines.size() + 1;
        if(maximumSize != null) {
            if(width > maximumSize.getColumns())
                width = maximumSize.getColumns();
            if(height > maximumSize.getRows())
                height = maximumSize.getRows();
        }
        if(minimumSize != null) {
            if(width < minimumSize.getColumns())
                width = minimumSize.getColumns();
            if(height < minimumSize.getRows())
                height = minimumSize.getRows();
        }
        return new TerminalSize(width, height);
    }