styleTransitionSgr function
Returns the cheaper SGR transition from from to to.
This compares the delta sequence from styleDiff with a full reset plus styleToSgr reapply and returns whichever emits fewer bytes.
Implementation
String styleTransitionSgr(UvStyle? from, UvStyle? to) {
final delta = styleDiff(from, to);
if (to == null || to.isZero) {
return delta.isEmpty ? UvAnsi.resetStyle : delta;
}
if (from == null || from.isZero) {
return styleToSgr(to);
}
final resetThenApply = '${UvAnsi.resetStyle}${styleToSgr(to)}';
if (delta.isEmpty) return '';
return delta.length <= resetThenApply.length ? delta : resetThenApply;
}