Add statusbar (Close #72)
This commit is contained in:
parent
ff62b55133
commit
5d17121510
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
||||
github.com/cjbassi/drawille-go v0.0.0-20180329221028-ad535d0f92cd
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815
|
||||
github.com/gizak/termui v0.0.0-20190101005313-46c77dca8480
|
||||
github.com/gizak/termui v0.0.0-20190101100649-ffdef4cb72e9
|
||||
github.com/go-ole/go-ole v1.2.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/shirou/gopsutil v2.18.11+incompatible
|
||||
|
4
go.sum
4
go.sum
@ -10,6 +10,10 @@ github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815 h1:HMAfwOa33y82Ia
|
||||
github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:l7JNRynTRuqe45tpIyItHNqZWTxywYjp87MWTOnU5cg=
|
||||
github.com/gizak/termui v0.0.0-20190101005313-46c77dca8480 h1:+NHS7QUnQqEwIuhrHaFT6R78LMGbja4fYTu6wny7Q4s=
|
||||
github.com/gizak/termui v0.0.0-20190101005313-46c77dca8480/go.mod h1:S3xz8JHXNDPSNFsvXCdG7bHlEGrwvUG3a0joR/xYZ5M=
|
||||
github.com/gizak/termui v0.0.0-20190101093801-cb2e49106b0d h1:+4uQfMi8fK2KnydfTqUW9wuRLfNVkzz+LuH7EHPUwxA=
|
||||
github.com/gizak/termui v0.0.0-20190101093801-cb2e49106b0d/go.mod h1:S3xz8JHXNDPSNFsvXCdG7bHlEGrwvUG3a0joR/xYZ5M=
|
||||
github.com/gizak/termui v0.0.0-20190101100649-ffdef4cb72e9 h1:h5eo3CW6c9WMG+rN8cVxf25v8bSWFjuaDJdvtEWc61E=
|
||||
github.com/gizak/termui v0.0.0-20190101100649-ffdef4cb72e9/go.mod h1:S3xz8JHXNDPSNFsvXCdG7bHlEGrwvUG3a0joR/xYZ5M=
|
||||
github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
|
||||
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
|
||||
github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o=
|
||||
|
27
main.go
27
main.go
@ -38,6 +38,7 @@ var (
|
||||
configDir = appdir.New("gotop").UserConfig()
|
||||
logPath = filepath.Join(configDir, "errors.log")
|
||||
stderrLogger = log.New(os.Stderr, "", 0)
|
||||
statusbar = false
|
||||
termWidth int
|
||||
termHeight int
|
||||
|
||||
@ -64,6 +65,7 @@ Options:
|
||||
-p, --percpu Show each CPU in the CPU widget.
|
||||
-a, --averagecpu Show average CPU in the CPU widget.
|
||||
-f, --fahrenheit Show temperatures in fahrenheit.
|
||||
-b, --bar Show a statusbar with the time.
|
||||
|
||||
Colorschemes:
|
||||
default
|
||||
@ -90,6 +92,8 @@ Colorschemes:
|
||||
widgetCount = 3
|
||||
}
|
||||
|
||||
statusbar, _ = args["--bar"].(bool)
|
||||
|
||||
rateStr, _ := args["--rate"].(string)
|
||||
rate, err := strconv.ParseFloat(rateStr, 64)
|
||||
if err != nil {
|
||||
@ -143,28 +147,41 @@ func setupGrid() {
|
||||
grid = ui.NewGrid()
|
||||
grid.SetRect(0, 0, termWidth, termHeight)
|
||||
|
||||
var barRow interface{}
|
||||
if minimal {
|
||||
rowHeight := 1.0 / 2
|
||||
if statusbar {
|
||||
rowHeight = 50.0 / 101
|
||||
barRow = ui.NewRow(1.0/101, w.NewStatusBar())
|
||||
}
|
||||
grid.Set(
|
||||
ui.NewRow(1.0/2, cpu),
|
||||
ui.NewRow(1.0/2,
|
||||
ui.NewRow(rowHeight, cpu),
|
||||
ui.NewRow(rowHeight,
|
||||
ui.NewCol(1.0/2, mem),
|
||||
ui.NewCol(1.0/2, proc),
|
||||
),
|
||||
barRow,
|
||||
)
|
||||
} else {
|
||||
rowHeight := 1.0 / 3
|
||||
if statusbar {
|
||||
rowHeight = 50.0 / 151
|
||||
barRow = ui.NewRow(1.0/151, w.NewStatusBar())
|
||||
}
|
||||
grid.Set(
|
||||
ui.NewRow(1.0/3, cpu),
|
||||
ui.NewRow(1.0/3,
|
||||
ui.NewRow(rowHeight, cpu),
|
||||
ui.NewRow(rowHeight,
|
||||
ui.NewCol(1.0/3,
|
||||
ui.NewRow(1.0/2, disk),
|
||||
ui.NewRow(1.0/2, temp),
|
||||
),
|
||||
ui.NewCol(2.0/3, mem),
|
||||
),
|
||||
ui.NewRow(1.0/3,
|
||||
ui.NewRow(rowHeight,
|
||||
ui.NewCol(1.0/2, net),
|
||||
ui.NewCol(1.0/2, proc),
|
||||
),
|
||||
barRow,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
50
src/widgets/statusbar.go
Normal file
50
src/widgets/statusbar.go
Normal file
@ -0,0 +1,50 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"image"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
type StatusBar struct {
|
||||
ui.Block
|
||||
}
|
||||
|
||||
func NewStatusBar() *StatusBar {
|
||||
self := &StatusBar{*ui.NewBlock()}
|
||||
self.Border = false
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *StatusBar) Draw(buf *ui.Buffer) {
|
||||
self.Block.Draw(buf)
|
||||
|
||||
hostname, _ := os.Hostname()
|
||||
buf.SetString(
|
||||
hostname,
|
||||
image.Pt(self.Inner.Min.X, self.Inner.Min.Y+(self.Inner.Dy()/2)),
|
||||
ui.AttrPair{ui.Attribute(7), -1},
|
||||
)
|
||||
|
||||
t := time.Now()
|
||||
_time := t.Format("15:04:05")
|
||||
buf.SetString(
|
||||
_time,
|
||||
image.Pt(
|
||||
self.Inner.Min.X+(self.Inner.Dx()/2)-len(_time)/2,
|
||||
self.Inner.Min.Y+(self.Inner.Dy()/2),
|
||||
),
|
||||
ui.AttrPair{7, -1},
|
||||
)
|
||||
|
||||
buf.SetString(
|
||||
"gotop",
|
||||
image.Pt(
|
||||
self.Inner.Max.X-6,
|
||||
self.Inner.Min.Y+(self.Inner.Dy()/2),
|
||||
),
|
||||
ui.AttrPair{7, -1},
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user