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
|
|
|
|
2019-06-01 10:58:29 +08:00
|
|
|
Process navigation:
|
2018-11-30 10:17:13 +08:00
|
|
|
- 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
|
2019-10-04 08:59:22 +08:00
|
|
|
- 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)
|
2018-11-30 10:17:13 +08:00
|
|
|
|
2019-06-01 10:58:29 +08:00
|
|
|
Process sorting:
|
2018-03-05 12:00:55 +08:00
|
|
|
- c: CPU
|
|
|
|
- m: Mem
|
|
|
|
- p: PID
|
2018-02-19 15:25:02 +08:00
|
|
|
|
2019-06-01 10:58:29 +08:00
|
|
|
Process filtering:
|
|
|
|
- /: start editing filter
|
|
|
|
- (while editing):
|
|
|
|
- <Enter>: accept filter
|
2019-06-04 05:13:31 +08:00
|
|
|
- <C-c> and <Escape>: clear filter
|
2019-06-01 10:58:29 +08:00
|
|
|
|
2018-11-30 10:17:13 +08:00
|
|
|
CPU and Mem graph scaling:
|
|
|
|
- h: scale in
|
|
|
|
- l: scale out
|
2020-04-17 02:28:18 +08:00
|
|
|
|
|
|
|
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
|
2020-04-16 23:18:00 +08:00
|
|
|
for _, line := range strings.Split(KEYBINDS, "\n") {
|
|
|
|
if textWidth < len(line) {
|
|
|
|
textWidth = len(line) + 2
|
|
|
|
}
|
|
|
|
}
|
2019-06-01 10:58:29 +08:00
|
|
|
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(
|
2020-04-16 23:18:00 +08:00
|
|
|
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
|
|
|
|
}
|