gradient selection
This commit is contained in:
parent
393556a265
commit
df18d0fb89
|
@ -87,8 +87,8 @@ func (s *SparkLine) consumeSample(sample *data.Sample) {
|
||||||
func (s *SparkLine) Draw(buffer *ui.Buffer) {
|
func (s *SparkLine) Draw(buffer *ui.Buffer) {
|
||||||
|
|
||||||
textStyle := ui.NewStyle(s.palette.BaseColor)
|
textStyle := ui.NewStyle(s.palette.BaseColor)
|
||||||
lineStyle := ui.NewStyle(s.color)
|
|
||||||
|
|
||||||
|
height := s.Dy() - 2
|
||||||
minValue := util.FormatValue(s.minValue, s.scale)
|
minValue := util.FormatValue(s.minValue, s.scale)
|
||||||
maxValue := util.FormatValue(s.maxValue, s.scale)
|
maxValue := util.FormatValue(s.maxValue, s.scale)
|
||||||
curValue := util.FormatValue(s.values[len(s.values)-1], s.scale)
|
curValue := util.FormatValue(s.values[len(s.values)-1], s.scale)
|
||||||
|
@ -105,14 +105,14 @@ func (s *SparkLine) Draw(buffer *ui.Buffer) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
top := int((s.values[i] / s.maxValue) * float64(s.Dy()-2))
|
top := int((s.values[i] / s.maxValue) * float64(height))
|
||||||
|
|
||||||
if top == 0 {
|
if top == 0 {
|
||||||
top = 1
|
top = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
for j := 1; j <= top; j++ {
|
for j := 1; j <= top; j++ {
|
||||||
buffer.SetCell(ui.NewCell(console.SymbolSquare, lineStyle), image.Pt(s.Inner.Max.X-n-indent, s.Inner.Max.Y-j))
|
buffer.SetCell(ui.NewCell(console.SymbolVerticalBar, ui.NewStyle(s.palette.GetGradientColor(j-1, height))), image.Pt(s.Inner.Max.X-n-indent, s.Inner.Max.Y-j))
|
||||||
if i == len(s.values)-1 && j == top {
|
if i == len(s.values)-1 && j == top {
|
||||||
buffer.SetString(curValue, textStyle, image.Pt(s.Inner.Max.X-n-indent+2, s.Inner.Max.Y-j))
|
buffer.SetString(curValue, textStyle, image.Pt(s.Inner.Max.X-n-indent+2, s.Inner.Max.Y-j))
|
||||||
buffer.SetString(minValue, textStyle, image.Pt(s.Inner.Max.X-n-indent+2, s.Max.Y-2))
|
buffer.SetString(minValue, textStyle, image.Pt(s.Inner.Max.X-n-indent+2, s.Max.Y-2))
|
||||||
|
|
|
@ -85,10 +85,10 @@ asciiboxes:
|
||||||
font: 3d
|
font: 3d
|
||||||
sparklines:
|
sparklines:
|
||||||
- title: CPU usage
|
- title: CPU usage
|
||||||
position: [[27, 17], [25, 5]]
|
position: [[27, 22], [25, 7]]
|
||||||
scale: 0
|
scale: 0
|
||||||
value: ps -A -o %cpu | awk '{s+=$1} END {print s}'
|
value: ps -A -o %cpu | awk '{s+=$1} END {print s}'
|
||||||
- title: Memory pages free
|
- title: Memory pages free
|
||||||
position: [[27, 22], [25, 7]]
|
position: [[27, 17], [25, 5]]
|
||||||
scale: 0
|
scale: 0
|
||||||
value: memory_pressure | grep 'Pages free' | awk '{print $3}'
|
value: memory_pressure | grep 'Pages free' | awk '{print $3}'
|
||||||
|
|
|
@ -48,7 +48,7 @@ func GetPalette(theme Theme) Palette {
|
||||||
case ThemeDark:
|
case ThemeDark:
|
||||||
return Palette{
|
return Palette{
|
||||||
ContentColors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink, ColorWhite, ColorGrey, ColorGreen, ColorOrange, ColorCian, ColorPurple},
|
ContentColors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink, ColorWhite, ColorGrey, ColorGreen, ColorOrange, ColorCian, ColorPurple},
|
||||||
GradientColors: []ui.Color{39, 44, 47, 82, 148, 185, 208, 203, 198, 196},
|
GradientColors: []ui.Color{39, 44, 47, 82, 148, 185, 209, 203, 198, 196, 125},
|
||||||
BaseColor: ColorWhite,
|
BaseColor: ColorWhite,
|
||||||
MediumColor: ColorDarkGrey,
|
MediumColor: ColorDarkGrey,
|
||||||
ReverseColor: ColorBlack,
|
ReverseColor: ColorBlack,
|
||||||
|
@ -56,7 +56,7 @@ func GetPalette(theme Theme) Palette {
|
||||||
case ThemeLight:
|
case ThemeLight:
|
||||||
return Palette{
|
return Palette{
|
||||||
ContentColors: []ui.Color{ColorBlack, ColorDarkRed, ColorBlueViolet, ColorGrey, ColorGreen},
|
ContentColors: []ui.Color{ColorBlack, ColorDarkRed, ColorBlueViolet, ColorGrey, ColorGreen},
|
||||||
GradientColors: []ui.Color{250, 248, 246, 244, 242, 240, 238, 236, 234, 232},
|
GradientColors: []ui.Color{250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 16},
|
||||||
BaseColor: ColorBlack,
|
BaseColor: ColorBlack,
|
||||||
MediumColor: ColorLightGrey,
|
MediumColor: ColorLightGrey,
|
||||||
ReverseColor: ColorWhite,
|
ReverseColor: ColorWhite,
|
||||||
|
@ -65,3 +65,9 @@ func GetPalette(theme Theme) Palette {
|
||||||
panic(fmt.Sprintf("Following theme is not supported: %v", theme))
|
panic(fmt.Sprintf("Following theme is not supported: %v", theme))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// selects gradient color for cur item (out of max items)
|
||||||
|
func (palette *Palette) GetGradientColor(cur int, max int) ui.Color {
|
||||||
|
ratio := float64(len(palette.GradientColors)) / float64(max)
|
||||||
|
return palette.GradientColors[int(ratio*float64(cur))]
|
||||||
|
}
|
||||||
|
|
|
@ -4,5 +4,4 @@ const (
|
||||||
SymbolSelection rune = '▲'
|
SymbolSelection rune = '▲'
|
||||||
SymbolVerticalBar rune = '▎'
|
SymbolVerticalBar rune = '▎'
|
||||||
SymbolHorizontalBar rune = '═'
|
SymbolHorizontalBar rune = '═'
|
||||||
SymbolSquare rune = '■'
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue