palette changes for windows support

This commit is contained in:
sqshq 2019-07-28 16:59:51 -04:00
parent 24eb7bf571
commit a506bb92eb
2 changed files with 27 additions and 6 deletions

View File

@ -53,18 +53,18 @@ func NewStatusLine(configFileName string, palette console.Palette, license *meta
func (s *StatusBar) Draw(buffer *ui.Buffer) { func (s *StatusBar) Draw(buffer *ui.Buffer) {
buffer.Fill(ui.NewCell(' ', ui.NewStyle(console.ColorClear, console.MenuColorBackground)), s.GetRect()) buffer.Fill(ui.NewCell(' ', ui.NewStyle(console.ColorClear, console.GetMenuColorReverse())), s.GetRect())
indent := bindingsIndent indent := bindingsIndent
for _, binding := range s.keyBindings { for _, binding := range s.keyBindings {
buffer.SetString(binding, ui.NewStyle(console.MenuColorText, console.MenuColorBackground), image.Pt(s.Max.X-len(binding)-indent, s.Min.Y)) buffer.SetString(binding, ui.NewStyle(console.GetMenuColor(), console.GetMenuColorReverse()), image.Pt(s.Max.X-len(binding)-indent, s.Min.Y))
indent += bindingsIndent + len(binding) indent += bindingsIndent + len(binding)
} }
buffer.SetString(s.text, ui.NewStyle(console.MenuColorText, console.MenuColorBackground), s.Min) buffer.SetString(s.text, ui.NewStyle(console.GetMenuColor(), console.GetMenuColorReverse()), s.Min)
if s.pause { if s.pause {
buffer.SetString(pauseText, ui.NewStyle(console.MenuColorBackground, console.MenuColorText), image.Pt(s.Max.X-s.Dx()/2-len(pauseText)/2, s.Min.Y)) buffer.SetString(pauseText, ui.NewStyle(console.GetMenuColorReverse(), console.GetMenuColor()), image.Pt(s.Max.X-s.Dx()/2-len(pauseText)/2, s.Min.Y))
} }
s.Block.Draw(buffer) s.Block.Draw(buffer)

View File

@ -3,6 +3,7 @@ package console
import ( import (
"fmt" "fmt"
ui "github.com/gizak/termui/v3" ui "github.com/gizak/termui/v3"
"runtime"
) )
type Theme string type Theme string
@ -31,8 +32,10 @@ const (
) )
const ( const (
MenuColorBackground ui.Color = 235 menuColorNix ui.Color = 255
MenuColorText ui.Color = 255 menuColorReverseNix ui.Color = 235
menuColorWindows ui.Color = 255
menuColorReverseWindows ui.Color = 0
) )
type Palette struct { type Palette struct {
@ -66,6 +69,24 @@ func GetPalette(theme Theme) Palette {
} }
} }
func GetMenuColor() ui.Color {
switch runtime.GOOS {
case "windows":
return menuColorWindows
default:
return menuColorNix
}
}
func GetMenuColorReverse() ui.Color {
switch runtime.GOOS {
case "windows":
return menuColorReverseWindows
default:
return menuColorReverseNix
}
}
func GetGradientColor(gradient []ui.Color, cur int, max int) ui.Color { func GetGradientColor(gradient []ui.Color, cur int, max int) ui.Color {
ratio := float64(len(gradient)) / float64(max) ratio := float64(len(gradient)) / float64(max)
index := int(ratio * float64(cur)) index := int(ratio * float64(cur))