formatSyncReport function
Builds the final report for a completed sync o — a one-line summary of file
counts and raw vs on-wire bytes, e.g.
Synced push: 12 transferred, 3 copied · 4.1 MB (1.2 MB on wire). When
verbose, appends one line per path (+ transferred, = copied, -
removed). Mirrors the wording of :drive/omnyshell drive so the CLI and
in-session paths read the same.
Implementation
String formatSyncReport(SyncOutcome o, {bool verbose = false}) {
if (o.isConflict) return 'Conflict: ${o.conflict!.message}';
if (o.direction == null) return 'Already up to date.';
final counts = <String>[];
if (o.transferredPaths.isNotEmpty) {
counts.add('${o.transferredPaths.length} transferred');
}
if (o.copiedPaths.isNotEmpty) counts.add('${o.copiedPaths.length} copied');
if (o.removedPaths.isNotEmpty) counts.add('${o.removedPaths.length} removed');
// Git syncs expose no per-path metrics; fall back to the applied count.
final summary = counts.isEmpty ? '${o.applied} change(s)' : counts.join(', ');
final buf = StringBuffer('Synced ${o.direction!.wireValue}: $summary');
if (o.bytesTransferred > 0) {
final raw = ProgressBar._fmt(o.bytesTransferred);
buf.write(
o.bytesOnWire > 0 && o.bytesOnWire != o.bytesTransferred
? ' · $raw (${ProgressBar._fmt(o.bytesOnWire)} on wire)'
: ' · $raw',
);
}
if (o.publishedBranch != null) buf.write(' (published ${o.publishedBranch})');
buf.write('.');
if (verbose) {
for (final p in o.transferredPaths) {
buf.write('\n + $p');
}
for (final p in o.copiedPaths) {
buf.write('\n = $p');
}
for (final p in o.removedPaths) {
buf.write('\n - $p');
}
}
return buf.toString();
}