diff --git a/src/commands/common.zig b/src/commands/common.zig index b06cf5c..2abb4f2 100644 --- a/src/commands/common.zig +++ b/src/commands/common.zig @@ -129,47 +129,38 @@ pub const LoadProgress = struct { pub const AggregateProgress = struct { color: bool, last_phase: ?zfin.DataService.AggregateProgressCallback.Phase = null, + last_completed: usize = 0, fn onProgress(ctx: *anyopaque, completed: usize, total: usize, phase: zfin.DataService.AggregateProgressCallback.Phase) void { const self: *AggregateProgress = @ptrCast(@alignCast(ctx)); - // Track phase transitions for newlines const phase_changed = self.last_phase == null or self.last_phase.? != phase; self.last_phase = phase; var buf: [256]u8 = undefined; var writer = std.fs.File.stderr().writer(&buf); - const out = &writer.interface; + const w = &writer.interface; switch (phase) { - .cache_check => { - // Brief phase, no output needed - }, + .cache_check => {}, .server_sync => { - // Single updating line with carriage return - if (self.color) fmt.ansiSetFg(out, CLR_MUTED[0], CLR_MUTED[1], CLR_MUTED[2]) catch {}; - out.print("\r Syncing from server... [{d}/{d}]", .{ completed, total }) catch {}; - if (self.color) fmt.ansiReset(out) catch {}; - out.flush() catch {}; + if (completed != self.last_completed) { + if (self.color) fmt.ansiSetFg(w, CLR_MUTED[0], CLR_MUTED[1], CLR_MUTED[2]) catch {}; + w.print(" Syncing from server... [{d}/{d}]\n", .{ completed, total }) catch {}; + if (self.color) fmt.ansiReset(w) catch {}; + w.flush() catch {}; + self.last_completed = completed; + } }, .provider_fetch => { if (phase_changed) { - // Clear the server sync line and print newline - out.print("\r\x1b[K", .{}) catch {}; // clear line - if (self.color) fmt.ansiSetFg(out, CLR_MUTED[0], CLR_MUTED[1], CLR_MUTED[2]) catch {}; - out.print(" Synced {d} from server, fetching remaining from providers...\n", .{completed}) catch {}; - if (self.color) fmt.ansiReset(out) catch {}; - out.flush() catch {}; - } - }, - .complete => { - // Final newline if we were on server_sync line - if (self.last_phase != null and - (self.last_phase.? == .server_sync or self.last_phase.? == .cache_check)) - { - out.print("\r\x1b[K", .{}) catch {}; // clear line + if (self.color) fmt.ansiSetFg(w, CLR_MUTED[0], CLR_MUTED[1], CLR_MUTED[2]) catch {}; + w.print(" Synced {d} from server, fetching remaining from providers...\n", .{completed}) catch {}; + if (self.color) fmt.ansiReset(w) catch {}; + w.flush() catch {}; } }, + .complete => {}, } }