diff method
Compute a list of CellUpdates needed to turn this buffer into other.
Implementation
List<CellUpdate> diff(Buffer other) {
final result = <CellUpdate>[];
final len =
content.length < other.content.length ? content.length : other.content.length;
var i = 0;
while (i < len) {
final current = other.content[i];
final previous = content[i];
switch (current.diffOption) {
case CellDiffOption.skip:
i++;
continue;
case CellDiffOption.forcedWidth:
final width = charWidthOf(current.symbol);
if (current != previous) {
final pos = posOf(i);
result.add(CellUpdate(pos.x, pos.y, current));
}
i += width;
continue;
case CellDiffOption.none:
case CellDiffOption.alwaysUpdate:
final cellWidth = charWidthOf(current.symbol);
final needsUpdate = current.diffOption == CellDiffOption.alwaysUpdate || current != previous;
if (needsUpdate) {
final pos = posOf(i);
result.add(CellUpdate(pos.x, pos.y, current));
}
i += cellWidth > 1 ? cellWidth : 1;
}
}
return result;
}