package cli import ( "bufio" "fmt" "io" "strings" "github.com/humdrum-tiv/dots-cli/internal/day" ) // FormatChanges renders the pre-write diff table shown before confirmation. func FormatChanges(changes []day.Change, typeNames map[string]string, blockSize int) string { name := func(id *string) string { if id == nil { return "(cleared)" } if n, ok := typeNames[*id]; ok { return n } return *id } var b strings.Builder for _, c := range changes { from := "(empty)" if c.FromID != nil { from = name(c.FromID) } fmt.Fprintf(&b, " %-6s %s → %s\n", day.SlotLabel(c.Index, blockSize), from, name(c.ToID)) } return b.String() } // Confirm enforces the no-silent-overwrite rule: --yes bypasses, a real TTY // prompts y/N (default N), and non-TTY without --yes refuses outright. func Confirm(prompt string, yes bool, in io.Reader, out io.Writer, isTTY bool) (bool, error) { if yes { return true, nil } if !isTTY { return false, fmt.Errorf("would change existing blocks — re-run with --yes (non-interactive)") } fmt.Fprintf(out, "%s [y/N] ", prompt) line, _ := bufio.NewReader(in).ReadString('\n') return strings.TrimSpace(strings.ToLower(line)) == "y", nil }