void (@NotNull StringBuffer buffer, int size) { final int toRemove = buffer.length() - size; if (toRemove > 0) { int indexOfNewline = buffer.indexOf("\n", toRemove); if (indexOfNewline == -1) { buffer.delete(0, toRemove); } else { buffer.delete(0, indexOfNewline + 1); } } }