Compare commits
6 Commits
ce0d7b45a1
...
706284d590
| Author | SHA1 | Date | |
|---|---|---|---|
| 706284d590 | |||
| 75564a504e | |||
| edd3e5fdb2 | |||
| d5796bd6c1 | |||
| 90e855ef99 | |||
| 2185421c01 |
@@ -407,6 +407,7 @@ Message classes:
|
||||
| Warning | `⚠️ Warning:` (orange/yellow) | column 0 | Recoverable problem |
|
||||
| Error | `🛑 ERROR:` (red) | column 0 | Operation aborted |
|
||||
| Progress | ` 》` (white) | column 2 | Heartbeat or per-item status during a long-running operation |
|
||||
| Detail | ` 》` (white) | column 2 | Continuation/sub-line of a preceding Complete (visually identical to Progress) |
|
||||
|
||||
Conventions:
|
||||
|
||||
@@ -421,12 +422,13 @@ Conventions:
|
||||
"Uploaded" for Complete. Never write the words "begin" or "complete"
|
||||
in the body — the marker color already conveys that.
|
||||
* All elapsed and remaining-time fields are explicitly scoped to their
|
||||
subject: write "blob upload elapsed 30s, blob upload estimated remaining
|
||||
time (14s), finish at 2026-06-17T03:15:00Z", never just "elapsed 30s,
|
||||
ETA 14s".
|
||||
subject: write "blob upload elapsed: 30s, blob upload ETA: 03:15:00
|
||||
(est remain 14s)", never just "elapsed 30s, ETA 14s".
|
||||
* "ETA" means an absolute clock time (when the operation will finish),
|
||||
not a remaining-duration. Use `ui.Time()` for the former and
|
||||
`ui.Duration()` for the latter, and label both.
|
||||
* `ui.Time` formats same-day times as `HH:MM:SS` and other-day times as
|
||||
`YYYY-MM-DD HH:MM:SS`. No timezone — local time is implied.
|
||||
|
||||
Value colorizers in `internal/ui` colorize specific value types
|
||||
consistently. Compose messages from these helpers rather than embedding
|
||||
|
||||
@@ -51,6 +51,7 @@ func setupGlobals(lc fx.Lifecycle, g *globals.Globals, v *vaultik.Vaultik, opts
|
||||
g.ShortCommit(), g.CommitDate,
|
||||
g.StartTime.Format(time.RFC3339))
|
||||
v.UI.Banner("%s", globals.Homepage)
|
||||
v.UI.Banner("")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -777,16 +777,16 @@ func (s *Scanner) printScanProgressLine(filesScanned int64, changedCount int, es
|
||||
eta = time.Duration(float64(remaining)/rate) * time.Second
|
||||
}
|
||||
if eta > 0 {
|
||||
s.ui.Progress("Snapshot source files enumeration: %s files (~%s), %s changed or new, %.0f files/sec, enumeration elapsed %s, enumeration estimated remaining time (%s), finish at %s.",
|
||||
s.ui.Progress("Snapshot source files enumeration: %s files (~%s), %s changed or new, %.0f files/sec, enumeration elapsed: %s, enumeration ETA: %s (est remain %s).",
|
||||
s.ui.Count(int(filesScanned)),
|
||||
s.ui.Percent(pct),
|
||||
s.ui.Count(changedCount),
|
||||
rate,
|
||||
s.ui.Duration(elapsed),
|
||||
s.ui.Duration(eta),
|
||||
s.ui.Time(time.Now().Add(eta)))
|
||||
s.ui.Time(time.Now().Add(eta)),
|
||||
s.ui.Duration(eta))
|
||||
} else {
|
||||
s.ui.Progress("Snapshot source files enumeration: %s files (~%s), %s changed or new, %.0f files/sec, enumeration elapsed %s.",
|
||||
s.ui.Progress("Snapshot source files enumeration: %s files (~%s), %s changed or new, %.0f files/sec, enumeration elapsed: %s.",
|
||||
s.ui.Count(int(filesScanned)),
|
||||
s.ui.Percent(pct),
|
||||
s.ui.Count(changedCount),
|
||||
@@ -794,7 +794,7 @@ func (s *Scanner) printScanProgressLine(filesScanned int64, changedCount int, es
|
||||
s.ui.Duration(elapsed))
|
||||
}
|
||||
} else {
|
||||
s.ui.Progress("Snapshot source files enumeration: %s files seen, %s changed or new, %.0f files/sec, enumeration elapsed %s.",
|
||||
s.ui.Progress("Snapshot source files enumeration: %s files seen, %s changed or new, %.0f files/sec, enumeration elapsed: %s.",
|
||||
s.ui.Count(int(filesScanned)),
|
||||
s.ui.Count(changedCount),
|
||||
rate,
|
||||
@@ -1067,7 +1067,7 @@ func (s *Scanner) printProcessingProgress(filesProcessed, totalFiles int, bytesP
|
||||
}
|
||||
|
||||
if eta > 0 {
|
||||
s.ui.Progress("Snapshot file processing: %s/%s files (%s), %s/%s, %s, %.0f files/sec, processing elapsed %s, processing estimated remaining time (%s), finish at %s.",
|
||||
s.ui.Progress("Snapshot file processing: %s/%s files (%s), %s/%s, %s, %.0f files/sec, processing elapsed: %s, processing ETA: %s (est remain %s).",
|
||||
s.ui.Count(filesProcessed),
|
||||
s.ui.Count(totalFiles),
|
||||
s.ui.Percent(pct),
|
||||
@@ -1076,10 +1076,10 @@ func (s *Scanner) printProcessingProgress(filesProcessed, totalFiles int, bytesP
|
||||
s.ui.Speed(byteRate),
|
||||
fileRate,
|
||||
s.ui.Duration(elapsed),
|
||||
s.ui.Duration(eta),
|
||||
s.ui.Time(time.Now().Add(eta)))
|
||||
s.ui.Time(time.Now().Add(eta)),
|
||||
s.ui.Duration(eta))
|
||||
} else {
|
||||
s.ui.Progress("Snapshot file processing: %s/%s files (%s), %s/%s, %s, %.0f files/sec, processing elapsed %s.",
|
||||
s.ui.Progress("Snapshot file processing: %s/%s files (%s), %s/%s, %s, %.0f files/sec, processing elapsed: %s.",
|
||||
s.ui.Count(filesProcessed),
|
||||
s.ui.Count(totalFiles),
|
||||
s.ui.Percent(pct),
|
||||
@@ -1251,15 +1251,15 @@ func (s *Scanner) makeUploadProgressCallback(ctx context.Context, finishedBlob *
|
||||
if avgSpeed > 0 {
|
||||
eta = time.Duration(float64(finishedBlob.Compressed-uploaded)/avgSpeed) * time.Second
|
||||
}
|
||||
s.ui.Progress("Blob upload %s: %s / %s (%s) at %s, blob upload elapsed %s, blob upload estimated remaining time (%s), finish at %s.",
|
||||
s.ui.Progress("Blob upload %s: %s / %s (%s) at %s, blob upload elapsed: %s, blob upload ETA: %s (est remain %s).",
|
||||
s.ui.Hex(finishedBlob.Hash),
|
||||
s.ui.Size(uploaded),
|
||||
s.ui.Size(finishedBlob.Compressed),
|
||||
s.ui.Percent(pct),
|
||||
s.ui.Speed(avgSpeed),
|
||||
s.ui.Duration(totalElapsed),
|
||||
s.ui.Duration(eta),
|
||||
s.ui.Time(now.Add(eta)))
|
||||
s.ui.Time(now.Add(eta)),
|
||||
s.ui.Duration(eta))
|
||||
lastStdoutTime = now
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,14 @@ const (
|
||||
const Marker = "》"
|
||||
|
||||
// Writer formats and emits user-facing messages with optional ANSI color.
|
||||
// It also counts warnings and errors emitted so the caller can summarize at
|
||||
// the end of an operation ("Finished successfully." vs "Finished with
|
||||
// warnings.").
|
||||
type Writer struct {
|
||||
out io.Writer
|
||||
color bool
|
||||
out io.Writer
|
||||
color bool
|
||||
warnings int
|
||||
errors int
|
||||
}
|
||||
|
||||
// New returns a Writer that emits to out. Color is enabled when out is a
|
||||
@@ -115,6 +120,7 @@ func (w *Writer) Notice(format string, args ...any) {
|
||||
|
||||
// Warning prints "⚠️ Warning: " in orange/yellow followed by the message.
|
||||
func (w *Writer) Warning(format string, args ...any) {
|
||||
w.warnings++
|
||||
prefix := "⚠️ " + w.paint(ansiYellow+ansiBold, "Warning: ")
|
||||
_, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...))
|
||||
}
|
||||
@@ -123,19 +129,38 @@ func (w *Writer) Warning(format string, args ...any) {
|
||||
// same writer as everything else; callers that want stderr should
|
||||
// construct a separate Writer for it.
|
||||
func (w *Writer) Error(format string, args ...any) {
|
||||
w.errors++
|
||||
prefix := "🛑 " + w.paint(ansiRed+ansiBold, "ERROR: ")
|
||||
_, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
// Detail prints an indented continuation line under a preceding Complete
|
||||
// (or other top-level message). Marker " 》" (white) at column 2.
|
||||
// Distinct from Progress (semantically a "heartbeat") in usage but
|
||||
// visually identical.
|
||||
func (w *Writer) Detail(format string, args ...any) {
|
||||
w.emit(ansiWhite, " "+Marker, "", format, args)
|
||||
}
|
||||
|
||||
// WarningCount returns the number of Warning() calls this writer has emitted.
|
||||
func (w *Writer) WarningCount() int { return w.warnings }
|
||||
|
||||
// ErrorCount returns the number of Error() calls this writer has emitted.
|
||||
func (w *Writer) ErrorCount() int { return w.errors }
|
||||
|
||||
// Progress prints an indented heartbeat / per-item update, marker in white.
|
||||
func (w *Writer) Progress(format string, args ...any) {
|
||||
w.emit(ansiWhite, " "+Marker, "", format, args)
|
||||
}
|
||||
|
||||
// Banner prints a line with no marker, left-aligned. Used for the
|
||||
// application startup banner only.
|
||||
// Banner prints a line with no marker, left-aligned. Bold when color
|
||||
// is enabled. Used for the application startup banner only.
|
||||
func (w *Writer) Banner(format string, args ...any) {
|
||||
_, _ = fmt.Fprintln(w.out, fmt.Sprintf(format, args...))
|
||||
body := fmt.Sprintf(format, args...)
|
||||
if w.color {
|
||||
body = ansiBold + body + ansiReset
|
||||
}
|
||||
_, _ = fmt.Fprintln(w.out, body)
|
||||
}
|
||||
|
||||
// emit writes "<prefix> <body>\n" with the prefix painted in prefixColor
|
||||
@@ -188,9 +213,17 @@ func (w *Writer) Duration(d time.Duration) string {
|
||||
return w.paint(ansiYellow, d.Round(time.Second).String())
|
||||
}
|
||||
|
||||
// Time colorizes an absolute time (RFC3339, second precision).
|
||||
// Time colorizes an absolute clock time. If t falls on today's local
|
||||
// calendar date the output is "HH:MM:SS"; otherwise it is
|
||||
// "YYYY-MM-DD HH:MM:SS". No timezone is included — values are
|
||||
// displayed in the process's local zone.
|
||||
func (w *Writer) Time(t time.Time) string {
|
||||
return w.paint(ansiYellow, t.Format(time.RFC3339))
|
||||
t = t.Local()
|
||||
now := time.Now()
|
||||
if t.Year() == now.Year() && t.YearDay() == now.YearDay() {
|
||||
return w.paint(ansiYellow, t.Format("15:04:05"))
|
||||
}
|
||||
return w.paint(ansiYellow, t.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
|
||||
// Count colorizes an integer count with thousands separators.
|
||||
|
||||
@@ -25,7 +25,8 @@ func TestMessageMethodsPlain(t *testing.T) {
|
||||
{"Warning", func(w *Writer) { w.Warning("oops") }, "⚠️ Warning: oops\n"},
|
||||
{"Error", func(w *Writer) { w.Error("boom") }, "🛑 ERROR: boom\n"},
|
||||
{"Progress", func(w *Writer) { w.Progress("p") }, " 》 p\n"},
|
||||
{"Banner", func(w *Writer) { w.Banner("hello") }, "hello\n"},
|
||||
{"Detail", func(w *Writer) { w.Detail("d") }, " 》 d\n"},
|
||||
{"Banner", func(w *Writer) { w.Banner("hello") }, "hello\n"}, // plain mode, no bold
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -39,6 +40,23 @@ func TestMessageMethodsPlain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWarningErrorCounters(t *testing.T) {
|
||||
w, _ := newTestWriter(false)
|
||||
if w.WarningCount() != 0 || w.ErrorCount() != 0 {
|
||||
t.Fatalf("expected fresh writer to have zero counts")
|
||||
}
|
||||
w.Info("normal")
|
||||
w.Warning("first warn")
|
||||
w.Warning("second warn")
|
||||
w.Error("only error")
|
||||
if got, want := w.WarningCount(), 2; got != want {
|
||||
t.Errorf("WarningCount: got %d, want %d", got, want)
|
||||
}
|
||||
if got, want := w.ErrorCount(), 1; got != want {
|
||||
t.Errorf("ErrorCount: got %d, want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestColorOutputContainsANSI(t *testing.T) {
|
||||
w, buf := newTestWriter(true)
|
||||
w.Error("boom")
|
||||
@@ -51,6 +69,15 @@ func TestColorOutputContainsANSI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBannerBoldWhenColor(t *testing.T) {
|
||||
w, buf := newTestWriter(true)
|
||||
w.Banner("hello")
|
||||
out := buf.String()
|
||||
if !strings.Contains(out, "\033[1m") {
|
||||
t.Errorf("expected bold ANSI escape in colored Banner output, got %q", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValueFormattersPlain(t *testing.T) {
|
||||
w, _ := newTestWriter(false)
|
||||
|
||||
@@ -72,6 +99,16 @@ func TestValueFormattersPlain(t *testing.T) {
|
||||
if got := w.Percent(12.34); got != "12.3%" {
|
||||
t.Errorf("Percent: got %q", got)
|
||||
}
|
||||
|
||||
// Time format: today → HH:MM:SS, other day → YYYY-MM-DD HH:MM:SS.
|
||||
today := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 14, 30, 45, 0, time.Local)
|
||||
if got := w.Time(today); got != "14:30:45" {
|
||||
t.Errorf("Time today: got %q, want 14:30:45", got)
|
||||
}
|
||||
other := time.Date(2030, 1, 2, 3, 4, 5, 0, time.Local)
|
||||
if got := w.Time(other); got != "2030-01-02 03:04:05" {
|
||||
t.Errorf("Time other day: got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValueFormattersColored(t *testing.T) {
|
||||
|
||||
@@ -92,6 +92,12 @@ func (v *Vaultik) CreateSnapshot(opts *SnapshotCreateOptions) error {
|
||||
}
|
||||
}
|
||||
|
||||
if v.UI.WarningCount() > 0 {
|
||||
v.UI.Complete("Finished (with %d warnings).", v.UI.WarningCount())
|
||||
} else {
|
||||
v.UI.Complete("Finished successfully.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -336,35 +342,35 @@ func (v *Vaultik) printSnapshotSummary(snapshotID string, startTime time.Time, s
|
||||
}
|
||||
|
||||
v.UI.Complete("Created snapshot %s.", v.UI.Snapshot(snapshotID))
|
||||
filesMsg := fmt.Sprintf("Files: %s examined, %s to process, %s unchanged",
|
||||
filesMsg := fmt.Sprintf("Files: %s examined, %s processed, %s unchanged",
|
||||
v.UI.Count(stats.totalFiles),
|
||||
v.UI.Count(totalFilesChanged),
|
||||
v.UI.Count(stats.totalFilesSkipped))
|
||||
if stats.totalFilesDeleted > 0 {
|
||||
filesMsg += fmt.Sprintf(", %s deleted", v.UI.Count(stats.totalFilesDeleted))
|
||||
}
|
||||
v.UI.Info("%s.", filesMsg)
|
||||
v.UI.Detail("%s.", filesMsg)
|
||||
|
||||
dataMsg := fmt.Sprintf("Data: %s total (%s to process)",
|
||||
dataMsg := fmt.Sprintf("Data: %s total (%s processed)",
|
||||
v.UI.Size(totalBytesAll),
|
||||
v.UI.Size(stats.totalBytes))
|
||||
if stats.totalBytesDeleted > 0 {
|
||||
dataMsg += fmt.Sprintf(", %s deleted", v.UI.Size(stats.totalBytesDeleted))
|
||||
}
|
||||
v.UI.Info("%s.", dataMsg)
|
||||
v.UI.Detail("%s.", dataMsg)
|
||||
|
||||
if stats.totalBlobsUploaded > 0 {
|
||||
v.UI.Info("Storage: %s compressed from %s (%.2fx ratio).",
|
||||
v.UI.Detail("Storage: %s compressed from %s (%.2fx ratio).",
|
||||
v.UI.Size(totalBlobSizeCompressed),
|
||||
v.UI.Size(totalBlobSizeUncompressed),
|
||||
compressionRatio)
|
||||
v.UI.Info("Upload: %d blobs, %s in %s (%s).",
|
||||
v.UI.Detail("Upload: %d blobs, %s in %s (%s).",
|
||||
stats.totalBlobsUploaded,
|
||||
v.UI.Size(stats.totalBytesUploaded),
|
||||
v.UI.Duration(stats.uploadDuration),
|
||||
formatUploadSpeed(stats.totalBytesUploaded, stats.uploadDuration))
|
||||
}
|
||||
v.UI.Info("Snapshot create duration: %s.", v.UI.Duration(snapshotDuration))
|
||||
v.UI.Detail("Snapshot create duration: %s.", v.UI.Duration(snapshotDuration))
|
||||
}
|
||||
|
||||
// getSnapshotBlobSizes returns total compressed and uncompressed blob sizes for a snapshot
|
||||
@@ -1277,6 +1283,9 @@ func (v *Vaultik) PruneDatabase() (*PruneResult, error) {
|
||||
|
||||
result := &PruneResult{}
|
||||
|
||||
// Snapshot counts before deletion of incompletes.
|
||||
snapshotCountBefore, _ := v.getTableCount("snapshots")
|
||||
|
||||
// First, delete any incomplete snapshots
|
||||
incompleteSnapshots, err := v.Repositories.Snapshots.GetIncompleteSnapshots(v.ctx)
|
||||
if err != nil {
|
||||
@@ -1329,8 +1338,12 @@ func (v *Vaultik) PruneDatabase() (*PruneResult, error) {
|
||||
"orphaned_blobs", result.BlobsDeleted,
|
||||
)
|
||||
|
||||
v.UI.Complete("Pruned local index database: %d incomplete snapshots, %d orphaned files, %d orphaned chunks, %d orphaned blobs removed.",
|
||||
result.SnapshotsDeleted, result.FilesDeleted, result.ChunksDeleted, result.BlobsDeleted)
|
||||
snapshotCountAfter := snapshotCountBefore - result.SnapshotsDeleted
|
||||
v.UI.Complete("Pruned local index database.")
|
||||
v.UI.Detail("Incomplete snapshots: %d removed (%d remain).", result.SnapshotsDeleted, snapshotCountAfter)
|
||||
v.UI.Detail("Orphaned files: %d removed (%d remain).", result.FilesDeleted, fileCountAfter)
|
||||
v.UI.Detail("Orphaned chunks: %d removed (%d remain).", result.ChunksDeleted, chunkCountAfter)
|
||||
v.UI.Detail("Orphaned blobs: %d removed (%d remain).", result.BlobsDeleted, blobCountAfter)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user