From 2e96ecb050eac5ec7087644ce91ed1649af5995e Mon Sep 17 00:00:00 2001 From: Bart Willems Date: Thu, 23 Jan 2020 23:17:14 +0100 Subject: [PATCH] =?UTF-8?q?added=20the=20degrees=20symbol(=C2=B0)=20to=20t?= =?UTF-8?q?he=20temperatures,=20made=20the=20TempWidget.Draw=20function=20?= =?UTF-8?q?more=20flexible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bart Willems --- src/widgets/temp.go | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/widgets/temp.go b/src/widgets/temp.go index 08a210b3..df000f69 100644 --- a/src/widgets/temp.go +++ b/src/widgets/temp.go @@ -11,11 +11,11 @@ import ( "github.com/cjbassi/gotop/src/utils" ) -type TempScale int +type TempScale rune const ( - Celcius TempScale = 0 - Fahrenheit = 1 + Celcius TempScale = 'C' + Fahrenheit = 'F' ) type TempWidget struct { @@ -83,19 +83,12 @@ func (self *TempWidget) Draw(buf *ui.Buffer) { image.Pt(self.Inner.Min.X, self.Inner.Min.Y+y), ) - switch self.TempScale { - case Fahrenheit: - buf.SetString( - fmt.Sprintf("%3dF", self.Data[key]), - ui.NewStyle(fg), - image.Pt(self.Inner.Max.X-4, self.Inner.Min.Y+y), - ) - case Celcius: - buf.SetString( - fmt.Sprintf("%3dC", self.Data[key]), - ui.NewStyle(fg), - image.Pt(self.Inner.Max.X-4, self.Inner.Min.Y+y), - ) - } + temperature := fmt.Sprintf("%3d°%c", self.Data[key], self.TempScale) + + buf.SetString( + temperature, + ui.NewStyle(fg), + image.Pt(self.Inner.Max.X-(len(temperature)-1), self.Inner.Min.Y+y), + ) } }