Skip to content

refactor: eliminate duplicate code in pomodoro timer animation #10

@LudoLoops

Description

@LudoLoops

Issue

In pomodoro/pomodoro.go:70-150, the animationTicker case (lines 73-111) and secondTicker case (lines 112-148) are 99% identical.

Problem

  • Massive code duplication (~80 lines of identical logic)
  • Changes to animation logic require updates in 2 places
  • Hard to maintain

Solution

Extract common logic:

func renderFrame(elapsed, total time.Duration, lastPrinted int) (string, int) {
    // Common rendering logic
    return bar, seconds
}

// In select:
case <-animationTicker.C:
    elapsedTime := time.Since(startTime)
    bar, seconds := renderFrame(elapsedTime, totalDuration, lastPrintedSeconds)
    if seconds != lastPrintedSeconds {
        fmt.Printf("\r%s", bar)
        lastPrintedSeconds = seconds
    }

Benefits

  • Eliminates ~80 lines of code
  • Easier to modify animation logic
  • Single source of truth

Impact

🟢 Low - Code quality improvement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions