xmtop/widgets/help.go

54 lines
1.0 KiB
Go
Raw Normal View History

2018-02-19 15:25:02 +08:00
package widgets
import (
"strings"
2018-03-30 06:48:43 +08:00
ui "github.com/cjbassi/termui"
2018-02-19 15:25:02 +08:00
)
const KEYBINDS = `
Quit: q or <C-c>
2018-02-19 15:25:02 +08:00
2018-03-10 08:29:05 +08:00
Process Navigation
- <up>/<down> and j/k: up and down
- <C-d> and <C-u>: up and down half a page
- <C-f> and <C-b>: up and down a full page
- gg and G: jump to top and bottom
2018-02-19 15:25:02 +08:00
Process Sorting
- c: CPU
- m: Mem
- p: PID
2018-02-19 15:25:02 +08:00
<tab>: toggle process grouping
dd: kill the selected process or process group
2018-03-10 08:29:05 +08:00
h and l: zoom in and out of CPU and Mem graphs
2018-02-19 15:25:02 +08:00
`
type HelpMenu struct {
2018-02-24 13:15:38 +08:00
*ui.Block
2018-02-19 15:25:02 +08:00
}
func NewHelpMenu() *HelpMenu {
2018-02-24 13:15:38 +08:00
block := ui.NewBlock()
2018-04-13 10:48:50 +08:00
block.X = 48 // width - 1
block.Y = 17 // height - 1
2018-02-19 15:25:02 +08:00
return &HelpMenu{block}
}
2018-03-28 05:27:23 +08:00
func (self *HelpMenu) Buffer() *ui.Buffer {
buf := self.Block.Buffer()
2018-02-19 15:25:02 +08:00
2018-04-13 10:48:50 +08:00
self.Block.XOffset = (ui.Body.Width - self.Block.X) / 2 // X coordinate
self.Block.YOffset = (ui.Body.Height - self.Block.Y) / 2 // Y coordinate
2018-02-19 15:25:02 +08:00
for y, line := range strings.Split(KEYBINDS, "\n") {
for x, char := range line {
2018-03-28 05:27:23 +08:00
buf.SetCell(x+1, y, ui.NewCell(char, ui.Color(7), self.Bg))
2018-02-19 15:25:02 +08:00
}
}
return buf
}