Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

added the degrees symbol(°) to the temperatures, made the TempWidget.Draw function more flexible #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions src/widgets/temp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
)
}
}