From 79e4cdb3d4b5d4e6d4abe5aa924ab4d0b1c1ee01 Mon Sep 17 00:00:00 2001 From: shaobeichen Date: Thu, 17 Oct 2024 12:06:56 +0800 Subject: [PATCH] feat: update template --- main.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 1ac7911..4b66315 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "math" + "os" "strconv" "strings" "time" @@ -19,7 +20,6 @@ const ( progressEmptyChar = "░" progressColor1 = "#B14FFF" progressColor2 = "#00FFA3" - progressMaxValue = 1 ) // General stuff for styling the view @@ -30,6 +30,8 @@ var ( // Gradient colors we'll use for the progress bar ramp = makeRampStyles(progressColor1, progressColor2, progressBarWidth) + + progressMaxValue float64 = 1 ) type model struct { @@ -40,6 +42,20 @@ type model struct { } func main() { + // Check if a command line argument is provided + if len(os.Args) != 2 { + fmt.Println("Usage: go run . ") + return + } + + // Convert the argument to a float64 + var err error + progressMaxValue, err = strconv.ParseFloat(os.Args[1], 64) + if err != nil { + fmt.Println("Invalid progressMaxValue. It should be a number.") + return + } + initialModel := model{false, 0, 0, false} p := tea.NewProgram(initialModel) if _, err := p.Run(); err != nil { @@ -85,7 +101,7 @@ func updateChosen(msg tea.Msg, m model) (tea.Model, tea.Cmd) { case frameMsg: if !m.Loaded { m.Frames++ - m.Progress = ease.Linear(float64(m.Frames) / float64(100)) + m.Progress = ease.Linear(float64(m.Frames) / 100) // Adjusted the calculation for the new progressMaxValue if m.Progress >= progressMaxValue { m.Progress = progressMaxValue m.Loaded = true