xmtop/widgets/help.go

91 lines
1.7 KiB
Go
Raw Normal View History

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 = `
Quit: q or <C-c>
2018-02-19 15:25:02 +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 with SIGTERM (15)
- d3: kill selected process or group of processes with SIGQUIT (3)
- d9: kill selected process or group of processes with SIGKILL (9)
Process sorting:
- c: CPU
- m: Mem
- p: PID
2018-02-19 15:25:02 +08:00
Process filtering:
- /: start editing filter
- (while editing):
- <Enter>: accept filter
- <C-c> and <Escape>: clear filter
CPU and Mem graph scaling:
- h: scale in
- l: scale out
Network:
- b: toggle between mbps and scaled bytes per second
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) {
textWidth := 53
for _, line := range strings.Split(KEYBINDS, "\n") {
if textWidth < len(line) {
textWidth = len(line) + 2
}
}
textHeight := strings.Count(KEYBINDS, "\n") + 1
2019-01-01 08:55:50 +08:00
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(
ui.NewCell(rune, ui.Theme.Default),
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
}