From 41aa62a815c3f1c2941ed5d86f89abe2c1c84c5c Mon Sep 17 00:00:00 2001 From: Douglas Vinicius Date: Sat, 17 May 2025 09:54:16 -0300 Subject: [PATCH 1/7] feat: make gradient colours configurable (#133) --- main.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 3980fe2..8fd927d 100644 --- a/main.go +++ b/main.go @@ -120,8 +120,17 @@ var ( altscreenStyle = lipgloss.NewStyle().MarginLeft(padding) boldStyle = lipgloss.NewStyle().Bold(true) italicStyle = lipgloss.NewStyle().Italic(true) + gradientFlag string ) +var gradientPresets = map[string][2]string{ + "default": {"#5A56E0", "#EE6FF8"}, + "sunset": {"#FFB28C", "#FFC371"}, + "aqua": {"#13547A", "#80D0C7"}, + "forest": {"#5A3F37", "#2C7744"}, + "fire": {"#F7971E", "#FFD200"}, +} + const ( padding = 2 maxWidth = 80 @@ -147,10 +156,26 @@ var rootCmd = &cobra.Command{ if duration < time.Minute { interval = 100 * time.Millisecond } + + // choose the gradient based on the flag + // if the flag is empty or "default", use the default gradient + var progressBar progress.Model + if gradientFlag == "" || gradientFlag == "default" { + progressBar = progress.New(progress.WithDefaultGradient()) + } else if preset, ok := gradientPresets[gradientFlag]; ok { + progressBar = progress.New(progress.WithGradient(preset[0], preset[1])) + } else if strings.Contains(gradientFlag, ",") { + parts := strings.SplitN(gradientFlag, ",", 2) + progressBar = progress.New(progress.WithGradient(parts[0], parts[1])) + } else { + // fallback to default gradient if invalid input + progressBar = progress.New(progress.WithDefaultGradient()) + } + m, err := tea.NewProgram(model{ duration: duration, timer: timer.New(duration, timer.WithInterval(interval)), - progress: progress.New(progress.WithDefaultGradient()), + progress: progressBar, name: name, altscreen: altscreen, startTimeFormat: startTimeFormat, @@ -192,6 +217,7 @@ func init() { rootCmd.Flags().StringVarP(&name, "name", "n", "", "timer name") rootCmd.Flags().BoolVarP(&altscreen, "fullscreen", "f", false, "fullscreen") rootCmd.Flags().StringVarP(&startTimeFormat, "format", "", "", "Specify start time format, possible values: 24h, kitchen") + rootCmd.Flags().StringVarP(&gradientFlag, "gradient", "g", "default", "Gradient preset (default, sunset, aqua, forest, fire) or two hex colors separated by comma (ex: --gradient=#00FF00,#0000FF)") rootCmd.AddCommand(manCmd) } From cac574785f295ebc4ce37f0650f1067eb09f2eff Mon Sep 17 00:00:00 2001 From: Douglas Vinicius <48333749+linkzera@users.noreply.github.com> Date: Tue, 20 May 2025 08:42:57 -0300 Subject: [PATCH 2/7] Update main.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 8fd927d..e56aa77 100644 --- a/main.go +++ b/main.go @@ -166,7 +166,7 @@ var rootCmd = &cobra.Command{ progressBar = progress.New(progress.WithGradient(preset[0], preset[1])) } else if strings.Contains(gradientFlag, ",") { parts := strings.SplitN(gradientFlag, ",", 2) - progressBar = progress.New(progress.WithGradient(parts[0], parts[1])) + progressBar = progress.New(progress.WithGradient(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]))) } else { // fallback to default gradient if invalid input progressBar = progress.New(progress.WithDefaultGradient()) From e6ff3f4ff0db1ab5b08cd61fd0fb06e2439100a8 Mon Sep 17 00:00:00 2001 From: Douglas Vinicius <48333749+linkzera@users.noreply.github.com> Date: Tue, 20 May 2025 08:43:12 -0300 Subject: [PATCH 3/7] Update main.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index e56aa77..385ea21 100644 --- a/main.go +++ b/main.go @@ -169,6 +169,7 @@ var rootCmd = &cobra.Command{ progressBar = progress.New(progress.WithGradient(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]))) } else { // fallback to default gradient if invalid input + fmt.Printf("Warning: Invalid gradient '%s'. Falling back to default gradient.\n", gradientFlag) progressBar = progress.New(progress.WithDefaultGradient()) } From d226ec97cede7534943e436399352672e15a502e Mon Sep 17 00:00:00 2001 From: Douglas Vinicius <48333749+linkzera@users.noreply.github.com> Date: Wed, 21 May 2025 11:25:50 -0300 Subject: [PATCH 4/7] Update main.go Co-authored-by: Carlos Alexandro Becker --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 385ea21..f9cf10d 100644 --- a/main.go +++ b/main.go @@ -120,7 +120,7 @@ var ( altscreenStyle = lipgloss.NewStyle().MarginLeft(padding) boldStyle = lipgloss.NewStyle().Bold(true) italicStyle = lipgloss.NewStyle().Italic(true) - gradientFlag string + gradient string ) var gradientPresets = map[string][2]string{ From d32a06fac4932257a790b8d462845004700ad281 Mon Sep 17 00:00:00 2001 From: Douglas Vinicius <48333749+linkzera@users.noreply.github.com> Date: Wed, 21 May 2025 11:30:19 -0300 Subject: [PATCH 5/7] Update main.go --- main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index f9cf10d..4f09670 100644 --- a/main.go +++ b/main.go @@ -160,16 +160,16 @@ var rootCmd = &cobra.Command{ // choose the gradient based on the flag // if the flag is empty or "default", use the default gradient var progressBar progress.Model - if gradientFlag == "" || gradientFlag == "default" { + if gradient == "" || gradient == "default" { progressBar = progress.New(progress.WithDefaultGradient()) - } else if preset, ok := gradientPresets[gradientFlag]; ok { + } else if preset, ok := gradientPresets[gradient]; ok { progressBar = progress.New(progress.WithGradient(preset[0], preset[1])) - } else if strings.Contains(gradientFlag, ",") { - parts := strings.SplitN(gradientFlag, ",", 2) + } else if strings.Contains(gradient, ",") { + parts := strings.SplitN(gradient, ",", 2) progressBar = progress.New(progress.WithGradient(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]))) } else { // fallback to default gradient if invalid input - fmt.Printf("Warning: Invalid gradient '%s'. Falling back to default gradient.\n", gradientFlag) + fmt.Printf("Warning: Invalid gradient '%s'. Falling back to default gradient.\n", gradient) progressBar = progress.New(progress.WithDefaultGradient()) } @@ -218,7 +218,7 @@ func init() { rootCmd.Flags().StringVarP(&name, "name", "n", "", "timer name") rootCmd.Flags().BoolVarP(&altscreen, "fullscreen", "f", false, "fullscreen") rootCmd.Flags().StringVarP(&startTimeFormat, "format", "", "", "Specify start time format, possible values: 24h, kitchen") - rootCmd.Flags().StringVarP(&gradientFlag, "gradient", "g", "default", "Gradient preset (default, sunset, aqua, forest, fire) or two hex colors separated by comma (ex: --gradient=#00FF00,#0000FF)") + rootCmd.Flags().StringVarP(&gradient, "gradient", "g", "default", "Gradient preset (default, sunset, aqua, forest, fire) or two hex colors separated by comma (ex: --gradient=#00FF00,#0000FF)") rootCmd.AddCommand(manCmd) } From b57443ab49abd3289d5cd898b601087f2cb00b31 Mon Sep 17 00:00:00 2001 From: Douglas Vinicius <48333749+linkzera@users.noreply.github.com> Date: Wed, 21 May 2025 11:33:32 -0300 Subject: [PATCH 6/7] Update main.go --- main.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 4f09670..468d57c 100644 --- a/main.go +++ b/main.go @@ -159,18 +159,15 @@ var rootCmd = &cobra.Command{ // choose the gradient based on the flag // if the flag is empty or "default", use the default gradient + var progressBar progress.Model - if gradient == "" || gradient == "default" { - progressBar = progress.New(progress.WithDefaultGradient()) - } else if preset, ok := gradientPresets[gradient]; ok { - progressBar = progress.New(progress.WithGradient(preset[0], preset[1])) + if preset, ok := gradientPresets[gradient]; ok { + progressBar = progress.New(progress.WithGradient(preset[0], preset[1])) } else if strings.Contains(gradient, ",") { - parts := strings.SplitN(gradient, ",", 2) - progressBar = progress.New(progress.WithGradient(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]))) + parts := strings.SplitN(gradient, ",", 2) + progressBar = progress.New(progress.WithGradient(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]))) } else { - // fallback to default gradient if invalid input - fmt.Printf("Warning: Invalid gradient '%s'. Falling back to default gradient.\n", gradient) - progressBar = progress.New(progress.WithDefaultGradient()) + return fmt.Errorf("invalid gradient %q", gradient) } m, err := tea.NewProgram(model{ From b3b4d28ce505ec9bf732e109984108d665894412 Mon Sep 17 00:00:00 2001 From: Douglas Vinicius <48333749+linkzera@users.noreply.github.com> Date: Thu, 22 May 2025 13:18:36 -0300 Subject: [PATCH 7/7] Update main.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 468d57c..606515b 100644 --- a/main.go +++ b/main.go @@ -161,7 +161,8 @@ var rootCmd = &cobra.Command{ // if the flag is empty or "default", use the default gradient var progressBar progress.Model - if preset, ok := gradientPresets[gradient]; ok { + normalizedGradient := strings.ToLower(gradient) + if preset, ok := gradientPresets[normalizedGradient]; ok { progressBar = progress.New(progress.WithGradient(preset[0], preset[1])) } else if strings.Contains(gradient, ",") { parts := strings.SplitN(gradient, ",", 2)