print out server sync only once progress is made
This commit is contained in:
parent
742c237515
commit
648a173fb1
1 changed files with 15 additions and 24 deletions
|
|
@ -129,47 +129,38 @@ pub const LoadProgress = struct {
|
||||||
pub const AggregateProgress = struct {
|
pub const AggregateProgress = struct {
|
||||||
color: bool,
|
color: bool,
|
||||||
last_phase: ?zfin.DataService.AggregateProgressCallback.Phase = null,
|
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 {
|
fn onProgress(ctx: *anyopaque, completed: usize, total: usize, phase: zfin.DataService.AggregateProgressCallback.Phase) void {
|
||||||
const self: *AggregateProgress = @ptrCast(@alignCast(ctx));
|
const self: *AggregateProgress = @ptrCast(@alignCast(ctx));
|
||||||
|
|
||||||
// Track phase transitions for newlines
|
|
||||||
const phase_changed = self.last_phase == null or self.last_phase.? != phase;
|
const phase_changed = self.last_phase == null or self.last_phase.? != phase;
|
||||||
self.last_phase = phase;
|
self.last_phase = phase;
|
||||||
|
|
||||||
var buf: [256]u8 = undefined;
|
var buf: [256]u8 = undefined;
|
||||||
var writer = std.fs.File.stderr().writer(&buf);
|
var writer = std.fs.File.stderr().writer(&buf);
|
||||||
const out = &writer.interface;
|
const w = &writer.interface;
|
||||||
|
|
||||||
switch (phase) {
|
switch (phase) {
|
||||||
.cache_check => {
|
.cache_check => {},
|
||||||
// Brief phase, no output needed
|
|
||||||
},
|
|
||||||
.server_sync => {
|
.server_sync => {
|
||||||
// Single updating line with carriage return
|
if (completed != self.last_completed) {
|
||||||
if (self.color) fmt.ansiSetFg(out, CLR_MUTED[0], CLR_MUTED[1], CLR_MUTED[2]) catch {};
|
if (self.color) fmt.ansiSetFg(w, CLR_MUTED[0], CLR_MUTED[1], CLR_MUTED[2]) catch {};
|
||||||
out.print("\r Syncing from server... [{d}/{d}]", .{ completed, total }) catch {};
|
w.print(" Syncing from server... [{d}/{d}]\n", .{ completed, total }) catch {};
|
||||||
if (self.color) fmt.ansiReset(out) catch {};
|
if (self.color) fmt.ansiReset(w) catch {};
|
||||||
out.flush() catch {};
|
w.flush() catch {};
|
||||||
|
self.last_completed = completed;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
.provider_fetch => {
|
.provider_fetch => {
|
||||||
if (phase_changed) {
|
if (phase_changed) {
|
||||||
// Clear the server sync line and print newline
|
if (self.color) fmt.ansiSetFg(w, CLR_MUTED[0], CLR_MUTED[1], CLR_MUTED[2]) catch {};
|
||||||
out.print("\r\x1b[K", .{}) catch {}; // clear line
|
w.print(" Synced {d} from server, fetching remaining from providers...\n", .{completed}) catch {};
|
||||||
if (self.color) fmt.ansiSetFg(out, CLR_MUTED[0], CLR_MUTED[1], CLR_MUTED[2]) catch {};
|
if (self.color) fmt.ansiReset(w) catch {};
|
||||||
out.print(" Synced {d} from server, fetching remaining from providers...\n", .{completed}) catch {};
|
w.flush() 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
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
.complete => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue