mirror of
https://github.com/rjNemo/pomodoro
synced 2026-06-05 23:46:40 +00:00
Move TUI logic to a new tui.go file, separating concerns and improving maintainability. Integrate terminal-notifier to display a notification when the timer completes on Darwin systems. Update README to include terminal-notifier as a requirement.
45 lines
896 B
Go
45 lines
896 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/charmbracelet/bubbles/progress"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
type (
|
|
model struct {
|
|
name string
|
|
totalTime time.Duration
|
|
elapsedTime time.Duration
|
|
progress progress.Model
|
|
}
|
|
|
|
TickMsg time.Time
|
|
)
|
|
|
|
func main() {
|
|
if err := run(); err != nil {
|
|
log.Fatalf("error running the Pomodoro timer %v", err)
|
|
}
|
|
}
|
|
|
|
func run() error {
|
|
name := flag.String("name", "Pomodoro", "Name of the timer")
|
|
durationString := flag.String("duration", "25m", "Duration of the timer")
|
|
flag.Parse()
|
|
|
|
duration, err := time.ParseDuration(*durationString)
|
|
if err != nil {
|
|
return fmt.Errorf("could not parse duration %s: %w", *durationString, err)
|
|
}
|
|
|
|
p := tea.NewProgram(initialModel(*name, duration))
|
|
if _, err := p.Run(); err != nil {
|
|
return fmt.Errorf("could not start the timer app %w", err)
|
|
}
|
|
return nil
|
|
}
|