2018-02-19 15:25:02 +08:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
2019-01-01 08:55:50 +08:00
|
|
|
"image"
|
2018-02-19 15:25:02 +08:00
|
|
|
"strings"
|
|
|
|
|
2019-03-08 15:15:41 +08:00
|
|
|
ui "github.com/gizak/termui/v3"
|
2018-02-19 15:25:02 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const KEYBINDS = `
|
2018-03-05 12:00:55 +08:00
|
|
|
Quit: q or <C-c>
|
2018-02-19 15:25:02 +08:00
|
|
|
|
2018-11-30 10:17:13 +08:00
|
|
|
Process navigation
|
|
|
|
- k and <Up>: up
|
|
|
|
- j and <Down>: down
|
|
|
|
- <C-u>: half page up
|
|
|
|
- <C-d>: half page down
|
|
|
|
- <C-b>: full page up
|
|
|
|
- <C-f>: full page down
|
|
|
|
- gg and <Home>: jump to top
|
|
|
|
- G and <End>: jump to bottom
|
|
|
|
|
|
|
|
Process actions:
|
|
|
|
- <Tab>: toggle process grouping
|
|
|
|
- dd: kill selected process or group of processes
|
|
|
|
|
|
|
|
Process sorting
|
2018-03-05 12:00:55 +08:00
|
|
|
- c: CPU
|
|
|
|
- m: Mem
|
|
|
|
- p: PID
|
2018-02-19 15:25:02 +08:00
|
|
|
|
2018-11-30 10:17:13 +08:00
|
|
|
CPU and Mem graph scaling:
|
|
|
|
- h: scale in
|
|
|
|
- l: scale out
|
2018-02-19 15:25:02 +08:00
|
|
|
`
|
|
|
|
|
|
|
|
type HelpMenu struct {
|
2019-01-01 08:55:50 +08:00
|
|
|
ui.Block
|
2018-02-19 15:25:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewHelpMenu() *HelpMenu {
|
2019-01-01 08:55:50 +08:00
|
|
|
return &HelpMenu{
|
|
|
|
Block: *ui.NewBlock(),
|
|
|
|
}
|
2018-02-19 15:25:02 +08:00
|
|
|
}
|
|
|
|
|
2019-01-01 08:55:50 +08:00
|
|
|
func (self *HelpMenu) Resize(termWidth, termHeight int) {
|
2019-07-16 07:06:37 +08:00
|
|
|
var textWidth = 0
|
|
|
|
for _, line := range strings.Split(KEYBINDS, "\n") {
|
|
|
|
textWidth = maxInt(len(line), textWidth)
|
|
|
|
}
|
|
|
|
textWidth += 2
|
2019-01-01 08:55:50 +08:00
|
|
|
textHeight := 22
|
|
|
|
x := (termWidth - textWidth) / 2
|
|
|
|
y := (termHeight - textHeight) / 2
|
|
|
|
|
|
|
|
self.Block.SetRect(x, y, textWidth+x, textHeight+y)
|
|
|
|
}
|
2018-02-19 15:25:02 +08:00
|
|
|
|
2019-01-01 08:55:50 +08:00
|
|
|
func (self *HelpMenu) Draw(buf *ui.Buffer) {
|
|
|
|
self.Block.Draw(buf)
|
2018-04-13 10:48:50 +08:00
|
|
|
|
2018-02-19 15:25:02 +08:00
|
|
|
for y, line := range strings.Split(KEYBINDS, "\n") {
|
2019-03-01 08:29:52 +08:00
|
|
|
for x, rune := range line {
|
2019-01-01 08:55:50 +08:00
|
|
|
buf.SetCell(
|
2019-03-01 08:29:52 +08:00
|
|
|
ui.NewCell(rune, ui.NewStyle(7)),
|
2019-01-01 08:55:50 +08:00
|
|
|
image.Pt(self.Inner.Min.X+x, self.Inner.Min.Y+y-1),
|
|
|
|
)
|
2018-02-19 15:25:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-16 07:06:37 +08:00
|
|
|
|
|
|
|
func maxInt(a int, b int) int {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|