// in relation to widths array that can contain (should?) 0 value
LineReader renderer(final int[] widths, int height) {
final LineReader[] readers = new LineReader[widths.length];
for (int i = 0;i < readers.length;i++) {
LineRenderer renderer = cols.get(i);
LineReader reader = renderer.reader(widths[i] - leftCellPadding - rightCellPadding, height);
readers[i] = reader;
}
//
return new LineReader() {
/** . */
private boolean done = false;
public boolean hasLine() {
return !done;
}
public void renderLine(RenderAppendable to) {
if (!hasLine()) {
throw new IllegalStateException();
}
//
if (style != null) {
to.enterStyle(style);
}
//
for (int i = 0;i < readers.length;i++) {
LineReader reader = readers[i];
//
if (i > 0) {
if (separator != null) {
to.styleOff();
to.append(separator.vertical);
to.styleOn();
}
}
if (reader != null && reader.hasLine()) {
// Left padding
if (leftCellPadding > 0) {
for (int j = 0;j < leftCellPadding;j++) {
to.append(' ');
}
}
reader.renderLine(to);
// Right padding
if (rightCellPadding > 0) {
for (int j = 0;j < rightCellPadding;j++) {
to.append(' ');
}
}
} else {
readers[i] = null;
for (int j = widths[i];j > 0;j--) {
to.append(' ');
}
}
}
//
if (style != null) {
to.leaveStyle();
}
// Update status
done = true;
for (LineReader reader : readers) {
if (reader != null) {
if (reader.hasLine()) {
done = false;
break;
}
}
}