2017-01-14 06:07:43 +00:00
|
|
|
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
2015-03-20 20:21:50 +00:00
|
|
|
// Use of this source code is governed by a MIT license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build ignore
|
|
|
|
|
2015-03-13 17:20:17 +00:00
|
|
|
package main
|
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
2019-03-07 10:50:20 +00:00
|
|
|
ui "github.com/gizak/termui/v3"
|
|
|
|
"github.com/gizak/termui/v3/widgets"
|
2019-01-24 04:12:10 +00:00
|
|
|
)
|
2015-03-13 17:20:17 +00:00
|
|
|
|
|
|
|
func main() {
|
2019-01-24 04:12:10 +00:00
|
|
|
if err := ui.Init(); err != nil {
|
|
|
|
log.Fatalf("failed to initialize termui: %v", err)
|
2018-09-07 01:22:04 +00:00
|
|
|
}
|
2018-09-06 21:48:09 +00:00
|
|
|
defer ui.Close()
|
2015-03-13 17:20:17 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
g0 := widgets.NewGauge()
|
|
|
|
g0.Title = "Slim Gauge"
|
|
|
|
g0.SetRect(20, 20, 30, 30)
|
|
|
|
g0.Percent = 75
|
2018-09-06 21:48:09 +00:00
|
|
|
g0.BarColor = ui.ColorRed
|
2019-01-24 04:12:10 +00:00
|
|
|
g0.BorderStyle.Fg = ui.ColorWhite
|
|
|
|
g0.TitleStyle.Fg = ui.ColorCyan
|
2015-03-13 17:20:17 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
g2 := widgets.NewGauge()
|
|
|
|
g2.Title = "Slim Gauge"
|
|
|
|
g2.SetRect(0, 3, 50, 6)
|
2015-03-13 17:20:17 +00:00
|
|
|
g2.Percent = 60
|
2018-09-06 21:48:09 +00:00
|
|
|
g2.BarColor = ui.ColorYellow
|
2019-01-24 04:12:10 +00:00
|
|
|
g2.LabelStyle = ui.NewStyle(ui.ColorBlue)
|
|
|
|
g2.BorderStyle.Fg = ui.ColorWhite
|
2015-03-13 17:20:17 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
g1 := widgets.NewGauge()
|
|
|
|
g1.Title = "Big Gauge"
|
|
|
|
g1.SetRect(0, 6, 50, 11)
|
2015-03-13 17:20:17 +00:00
|
|
|
g1.Percent = 30
|
2018-09-06 21:48:09 +00:00
|
|
|
g1.BarColor = ui.ColorGreen
|
2019-01-24 04:12:10 +00:00
|
|
|
g1.LabelStyle = ui.NewStyle(ui.ColorYellow)
|
|
|
|
g1.TitleStyle.Fg = ui.ColorMagenta
|
|
|
|
g1.BorderStyle.Fg = ui.ColorWhite
|
2015-03-13 17:20:17 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
g3 := widgets.NewGauge()
|
|
|
|
g3.Title = "Gauge with custom label"
|
|
|
|
g3.SetRect(0, 11, 50, 14)
|
2015-04-21 14:43:09 +00:00
|
|
|
g3.Percent = 50
|
2019-01-24 04:12:10 +00:00
|
|
|
g3.Label = fmt.Sprintf("%v%% (100MBs free)", g3.Percent)
|
2015-04-21 14:43:09 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
g4 := widgets.NewGauge()
|
|
|
|
g4.Title = "Gauge"
|
|
|
|
g4.SetRect(0, 14, 50, 17)
|
2015-04-22 20:04:30 +00:00
|
|
|
g4.Percent = 50
|
|
|
|
g4.Label = "Gauge with custom highlighted label"
|
2018-09-06 21:48:09 +00:00
|
|
|
g4.BarColor = ui.ColorGreen
|
2019-01-24 04:12:10 +00:00
|
|
|
g4.LabelStyle = ui.NewStyle(ui.ColorYellow)
|
2015-04-22 20:04:30 +00:00
|
|
|
|
2018-09-06 21:48:09 +00:00
|
|
|
ui.Render(g0, g1, g2, g3, g4)
|
2015-03-13 17:20:17 +00:00
|
|
|
|
2018-11-29 23:32:42 +00:00
|
|
|
uiEvents := ui.PollEvents()
|
2018-11-29 02:19:34 +00:00
|
|
|
for {
|
2018-11-29 23:32:42 +00:00
|
|
|
e := <-uiEvents
|
2018-11-29 02:19:34 +00:00
|
|
|
switch e.ID {
|
|
|
|
case "q", "<C-c>":
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2015-03-13 17:20:17 +00:00
|
|
|
}
|