sampler-fork/console/palette.go

104 lines
2.5 KiB
Go
Raw Normal View History

package console
2019-01-31 23:40:05 +00:00
import (
"fmt"
2019-07-28 20:59:51 +00:00
"runtime"
ui "github.com/gizak/termui/v3"
2019-01-31 23:40:05 +00:00
)
type Theme string
const (
ThemeDark Theme = "dark"
2019-01-31 23:40:05 +00:00
ThemeLight Theme = "light"
)
const (
ColorOlive ui.Color = 178
2019-01-31 23:40:05 +00:00
ColorDeepSkyBlue ui.Color = 39
ColorDeepPink ui.Color = 198
ColorCian ui.Color = 43
ColorOrange ui.Color = 166
ColorPurple ui.Color = 129
ColorGreen ui.Color = 64
ColorDarkRed ui.Color = 88
ColorBlueViolet ui.Color = 57
ColorDarkGrey ui.Color = 238
ColorLightGrey ui.Color = 254
ColorGrey ui.Color = 242
2021-05-31 18:45:29 +00:00
ColorWhite ui.Color = 244
ColorBlack ui.Color = 0
ColorClear ui.Color = -1
2019-02-25 00:08:36 +00:00
)
const (
2019-07-28 20:59:51 +00:00
menuColorNix ui.Color = 255
menuColorReverseNix ui.Color = 235
menuColorWindows ui.Color = 255
menuColorReverseWindows ui.Color = 0
2019-01-31 23:40:05 +00:00
)
type Palette struct {
2019-03-28 23:56:46 +00:00
ContentColors []ui.Color
2019-04-01 04:35:55 +00:00
GradientColors [][]ui.Color
2019-03-28 23:56:46 +00:00
BaseColor ui.Color
MediumColor ui.Color
ReverseColor ui.Color
2019-01-31 23:40:05 +00:00
}
// GetPalette returns a color palette based on specified theme
2019-01-31 23:40:05 +00:00
func GetPalette(theme Theme) Palette {
switch theme {
case ThemeDark:
return Palette{
2019-03-28 23:56:46 +00:00
ContentColors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink, ColorWhite, ColorGrey, ColorGreen, ColorOrange, ColorCian, ColorPurple},
2019-04-01 04:35:55 +00:00
GradientColors: [][]ui.Color{{39, 33, 62, 93, 164, 161}, {95, 138, 180, 179, 178, 178}},
2019-03-28 23:56:46 +00:00
BaseColor: ColorWhite,
MediumColor: ColorDarkGrey,
ReverseColor: ColorBlack,
}
2019-01-31 23:40:05 +00:00
case ThemeLight:
return Palette{
2019-03-28 23:56:46 +00:00
ContentColors: []ui.Color{ColorBlack, ColorDarkRed, ColorBlueViolet, ColorGrey, ColorGreen},
2019-04-01 04:35:55 +00:00
GradientColors: [][]ui.Color{{250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 16}},
2019-03-28 23:56:46 +00:00
BaseColor: ColorBlack,
MediumColor: ColorLightGrey,
ReverseColor: ColorWhite,
}
2019-01-31 23:40:05 +00:00
default:
2019-07-30 02:39:17 +00:00
panic(fmt.Sprintf("Specified theme is not supported: %v", theme))
2019-01-31 23:40:05 +00:00
}
}
2019-04-01 03:02:58 +00:00
// GetMenuColor returns a color based on the
// operating system target
2019-07-28 20:59:51 +00:00
func GetMenuColor() ui.Color {
switch runtime.GOOS {
case "windows":
return menuColorWindows
default:
return menuColorNix
}
}
// GetMenuColorReverse returns a color based on the
// operating system target
2019-07-28 20:59:51 +00:00
func GetMenuColorReverse() ui.Color {
switch runtime.GOOS {
case "windows":
return menuColorReverseWindows
default:
return menuColorReverseNix
}
}
2019-04-01 04:35:55 +00:00
func GetGradientColor(gradient []ui.Color, cur int, max int) ui.Color {
ratio := float64(len(gradient)) / float64(max)
index := int(ratio * float64(cur))
if index > len(gradient)-1 {
index = len(gradient) - 1
}
return gradient[index]
2019-04-01 03:02:58 +00:00
}