From d81e5713d41316b3f4b628a34d1dd771250e9e78 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 18 Nov 2020 15:59:10 -0500 Subject: [PATCH] Cache termenv color profile lookup --- progress/progress.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/progress/progress.go b/progress/progress.go index 3f54fb5..b67b9b6 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -9,6 +9,8 @@ import ( "github.com/muesli/termenv" ) +var color func(string) termenv.Color = termenv.ColorProfile().Color + type Model struct { // Left side color of progress bar. By default, it's #00dbde StartColor colorful.Color @@ -73,7 +75,7 @@ func (m Model) bar(percent float64, textWidth int) string { var fullCells string for i := 0; i < len(ramp); i++ { - fullCells += termenv.String(string(m.Full)).Foreground(termenv.ColorProfile().Color(ramp[i])).String() + fullCells += termenv.String(string(m.Full)).Foreground(color(ramp[i])).String() } fullCells += strings.Repeat(string(m.Empty), w-len(ramp))