Skip to content

Commit 0488894

Browse files
committed
added progress bar
1 parent 7a0850d commit 0488894

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/ota-api/dto.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,27 @@ func formatStateData(state, data string, firmware_size *int64, hasReceivedFlashS
180180
if state == "fetch" {
181181
// This is the state 'fetch' of OTA progress. This contains a numer that represents the number of bytes fetched
182182
if hasReceivedFlashState {
183-
return "100%"
183+
return buildSimpleProgressBar(float64(100))
184184
}
185185
actualDownloadedData, err := strconv.Atoi(data)
186186
if err != nil || firmware_size == nil || actualDownloadedData <= 0 || *firmware_size <= 0 { // Sanitize and avoid division by zero
187187
return data
188188
}
189189
percentage := (float64(actualDownloadedData) / float64(*firmware_size)) * 100
190-
return strconv.FormatFloat(percentage, 'f', 2, 64) + "%"
190+
return buildSimpleProgressBar(percentage)
191191
}
192192
return data
193193
}
194194

195+
func buildSimpleProgressBar(progress float64) string {
196+
progressInt := int(progress) / 10
197+
bar := "["
198+
bar = bar + strings.Repeat("=", progressInt)
199+
bar = bar + strings.Repeat(" ", 10-progressInt)
200+
bar = bar + "] " + strconv.FormatFloat(progress, 'f', 2, 64) + "%"
201+
return bar
202+
}
203+
195204
func upperCaseFirst(s string) string {
196205
if len(s) > 0 {
197206
s = strings.ReplaceAll(s, "_", " ")

0 commit comments

Comments
 (0)