gotop/widgets/help.go

53 lines
1.1 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-03-04 09:05:52 +08:00
block.X = 48 // width - 1
2018-03-10 08:29:05 +08:00
block.Y = 17 // height - 1
2018-02-23 16:42:39 +08:00
block.XOffset = (ui.Body.Width - block.X) / 2 // X coordinate
block.YOffset = (ui.Body.Height - block.Y) / 2 // Y coordinate
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
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
}