chore: update build and tui assets

This commit is contained in:
2025-10-24 15:43:27 +00:00
parent 9b3c3f2b1b
commit 4e281cff01
31 changed files with 2456 additions and 571 deletions

View File

@ -15,9 +15,10 @@ import (
// TUIProgressReporter is a progress reporter that integrates with the TUI
type TUIProgressReporter struct {
mu sync.RWMutex
operations map[string]*progress.OperationStatus
callbacks []func([]progress.OperationStatus)
mu sync.RWMutex
operations map[string]*progress.OperationStatus
callbacks []func([]progress.OperationStatus)
defaultOperationID string
}
// NewTUIProgressReporter creates a new TUI-compatible progress reporter
@ -41,17 +42,123 @@ func (t *TUIProgressReporter) notifyCallbacks() {
for _, op := range t.operations {
operations = append(operations, *op)
}
for _, callback := range t.callbacks {
go callback(operations)
}
}
func (t *TUIProgressReporter) ensureDefaultOperationLocked(message string) *progress.OperationStatus {
if t.defaultOperationID == "" {
t.defaultOperationID = fmt.Sprintf("tui-progress-%d", time.Now().UnixNano())
}
op, exists := t.operations[t.defaultOperationID]
if !exists {
op = &progress.OperationStatus{
ID: t.defaultOperationID,
Name: "Backup Progress",
Type: "indicator",
Status: "running",
StartTime: time.Now(),
Message: message,
Progress: 0,
Details: make(map[string]string),
Steps: make([]progress.StepStatus, 0),
}
t.operations[t.defaultOperationID] = op
}
if message != "" {
op.Message = message
}
return op
}
func (t *TUIProgressReporter) Start(message string) {
t.mu.Lock()
defer t.mu.Unlock()
op := t.ensureDefaultOperationLocked(message)
now := time.Now()
op.Status = "running"
op.StartTime = now
op.EndTime = nil
op.Progress = 0
op.Message = message
t.notifyCallbacks()
}
func (t *TUIProgressReporter) Update(message string) {
t.mu.Lock()
defer t.mu.Unlock()
op := t.ensureDefaultOperationLocked(message)
if op.Progress < 95 {
op.Progress += 5
}
op.Message = message
t.notifyCallbacks()
}
func (t *TUIProgressReporter) Complete(message string) {
t.mu.Lock()
defer t.mu.Unlock()
if t.defaultOperationID == "" {
return
}
if op, exists := t.operations[t.defaultOperationID]; exists {
now := time.Now()
op.Status = "completed"
op.Message = message
op.Progress = 100
op.EndTime = &now
op.Duration = now.Sub(op.StartTime)
t.notifyCallbacks()
}
}
func (t *TUIProgressReporter) Fail(message string) {
t.mu.Lock()
defer t.mu.Unlock()
if t.defaultOperationID == "" {
return
}
if op, exists := t.operations[t.defaultOperationID]; exists {
now := time.Now()
op.Status = "failed"
op.Message = message
op.EndTime = &now
op.Duration = now.Sub(op.StartTime)
t.notifyCallbacks()
}
}
func (t *TUIProgressReporter) Stop() {
t.mu.Lock()
defer t.mu.Unlock()
if t.defaultOperationID == "" {
return
}
if op, exists := t.operations[t.defaultOperationID]; exists {
if op.Status == "running" {
now := time.Now()
op.Status = "stopped"
op.EndTime = &now
op.Duration = now.Sub(op.StartTime)
}
t.notifyCallbacks()
}
}
// StartOperation starts tracking a new operation
func (t *TUIProgressReporter) StartOperation(id, name, opType string) *TUIOperationTracker {
t.mu.Lock()
defer t.mu.Unlock()
operation := &progress.OperationStatus{
ID: id,
Name: name,
@ -63,10 +170,10 @@ func (t *TUIProgressReporter) StartOperation(id, name, opType string) *TUIOperat
Details: make(map[string]string),
Steps: make([]progress.StepStatus, 0),
}
t.operations[id] = operation
t.notifyCallbacks()
return &TUIOperationTracker{
reporter: t,
operationID: id,
@ -83,7 +190,7 @@ type TUIOperationTracker struct {
func (t *TUIOperationTracker) UpdateProgress(progress int, message string) {
t.reporter.mu.Lock()
defer t.reporter.mu.Unlock()
if op, exists := t.reporter.operations[t.operationID]; exists {
op.Progress = progress
op.Message = message
@ -95,7 +202,7 @@ func (t *TUIOperationTracker) UpdateProgress(progress int, message string) {
func (t *TUIOperationTracker) Complete(message string) {
t.reporter.mu.Lock()
defer t.reporter.mu.Unlock()
if op, exists := t.reporter.operations[t.operationID]; exists {
now := time.Now()
op.Status = "completed"
@ -111,7 +218,7 @@ func (t *TUIOperationTracker) Complete(message string) {
func (t *TUIOperationTracker) Fail(message string) {
t.reporter.mu.Lock()
defer t.reporter.mu.Unlock()
if op, exists := t.reporter.operations[t.operationID]; exists {
now := time.Now()
op.Status = "failed"
@ -126,7 +233,7 @@ func (t *TUIOperationTracker) Fail(message string) {
func (t *TUIProgressReporter) GetOperations() []progress.OperationStatus {
t.mu.RLock()
defer t.mu.RUnlock()
operations := make([]progress.OperationStatus, 0, len(t.operations))
for _, op := range t.operations {
operations = append(operations, *op)
@ -137,11 +244,11 @@ func (t *TUIProgressReporter) GetOperations() []progress.OperationStatus {
// SilentLogger implements logger.Logger but doesn't output anything
type SilentLogger struct{}
func (s *SilentLogger) Info(msg string, args ...any) {}
func (s *SilentLogger) Warn(msg string, args ...any) {}
func (s *SilentLogger) Error(msg string, args ...any) {}
func (s *SilentLogger) Debug(msg string, args ...any) {}
func (s *SilentLogger) Time(msg string, args ...any) {}
func (s *SilentLogger) Info(msg string, args ...any) {}
func (s *SilentLogger) Warn(msg string, args ...any) {}
func (s *SilentLogger) Error(msg string, args ...any) {}
func (s *SilentLogger) Debug(msg string, args ...any) {}
func (s *SilentLogger) Time(msg string, args ...any) {}
func (s *SilentLogger) StartOperation(name string) logger.OperationLogger {
return &SilentOperation{}
}
@ -149,9 +256,9 @@ func (s *SilentLogger) StartOperation(name string) logger.OperationLogger {
// SilentOperation implements logger.OperationLogger but doesn't output anything
type SilentOperation struct{}
func (s *SilentOperation) Update(message string, args ...any) {}
func (s *SilentOperation) Update(message string, args ...any) {}
func (s *SilentOperation) Complete(message string, args ...any) {}
func (s *SilentOperation) Fail(message string, args ...any) {}
func (s *SilentOperation) Fail(message string, args ...any) {}
// SilentProgressIndicator implements progress.Indicator but doesn't output anything
type SilentProgressIndicator struct{}
@ -163,9 +270,9 @@ func (s *SilentProgressIndicator) Fail(message string) {}
func (s *SilentProgressIndicator) Stop() {}
// RunBackupInTUI runs a backup operation with TUI-compatible progress reporting
func RunBackupInTUI(ctx context.Context, cfg *config.Config, log logger.Logger,
func RunBackupInTUI(ctx context.Context, cfg *config.Config, log logger.Logger,
backupType string, databaseName string, reporter *TUIProgressReporter) error {
// Create database connection
db, err := database.New(cfg, &SilentLogger{}) // Use silent logger
if err != nil {
@ -181,11 +288,11 @@ func RunBackupInTUI(ctx context.Context, cfg *config.Config, log logger.Logger,
// Create backup engine with silent progress indicator and logger
silentProgress := &SilentProgressIndicator{}
engine := backup.NewSilent(cfg, &SilentLogger{}, db, silentProgress)
// Start operation tracking
operationID := fmt.Sprintf("%s_%d", backupType, time.Now().Unix())
tracker := reporter.StartOperation(operationID, databaseName, backupType)
// Run the appropriate backup type
switch backupType {
case "single":
@ -200,7 +307,7 @@ func RunBackupInTUI(ctx context.Context, cfg *config.Config, log logger.Logger,
default:
err = fmt.Errorf("unknown backup type: %s", backupType)
}
// Update final status
if err != nil {
tracker.Fail(fmt.Sprintf("Backup failed: %v", err))
@ -209,4 +316,4 @@ func RunBackupInTUI(ctx context.Context, cfg *config.Config, log logger.Logger,
tracker.Complete(fmt.Sprintf("%s backup completed successfully", backupType))
return nil
}
}
}