mirror of
https://github.com/hibiken/asynq.git
synced 2025-09-19 05:17:30 +08:00
(cli) Add footer to dash
This commit is contained in:
@@ -41,10 +41,20 @@ func init() {
|
|||||||
dashCmd.Flags().BoolVar(&flagUseRealData, "realdata", false, "Use real data in redis")
|
dashCmd.Flags().BoolVar(&flagUseRealData, "realdata", false, "Use real data in redis")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// viewType is an enum for dashboard views.
|
||||||
|
type viewType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
viewTypeQueues viewType = iota
|
||||||
|
viewTypeHelp
|
||||||
|
)
|
||||||
|
|
||||||
type dashState struct {
|
type dashState struct {
|
||||||
queues []*asynq.QueueInfo
|
queues []*asynq.QueueInfo
|
||||||
err error
|
err error
|
||||||
rowIdx int // highlighted row
|
rowIdx int // highlighted row
|
||||||
|
view viewType // current view type
|
||||||
|
prevView viewType // to support "go back"
|
||||||
}
|
}
|
||||||
|
|
||||||
func dash(cmd *cobra.Command, args []string) {
|
func dash(cmd *cobra.Command, args []string) {
|
||||||
@@ -66,6 +76,7 @@ func dash(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
queues, err := getQueueInfo(inspector)
|
queues, err := getQueueInfo(inspector)
|
||||||
state := dashState{
|
state := dashState{
|
||||||
|
view: viewTypeQueues,
|
||||||
queues: queues,
|
queues: queues,
|
||||||
err: err,
|
err: err,
|
||||||
}
|
}
|
||||||
@@ -96,7 +107,14 @@ func dash(cmd *cobra.Command, args []string) {
|
|||||||
case *tcell.EventResize:
|
case *tcell.EventResize:
|
||||||
s.Sync()
|
s.Sync()
|
||||||
case *tcell.EventKey:
|
case *tcell.EventKey:
|
||||||
if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC || ev.Rune() == 'q' {
|
if ev.Key() == tcell.KeyEscape {
|
||||||
|
if state.view == viewTypeHelp {
|
||||||
|
state.view = state.prevView // exit help
|
||||||
|
drawDash(s, baseStyle, &state)
|
||||||
|
} else {
|
||||||
|
quit()
|
||||||
|
}
|
||||||
|
} else if ev.Key() == tcell.KeyCtrlC || ev.Rune() == 'q' {
|
||||||
quit()
|
quit()
|
||||||
} else if ev.Key() == tcell.KeyCtrlL {
|
} else if ev.Key() == tcell.KeyCtrlL {
|
||||||
s.Sync()
|
s.Sync()
|
||||||
@@ -114,6 +132,10 @@ func dash(cmd *cobra.Command, args []string) {
|
|||||||
state.rowIdx--
|
state.rowIdx--
|
||||||
}
|
}
|
||||||
drawDash(s, baseStyle, &state)
|
drawDash(s, baseStyle, &state)
|
||||||
|
} else if ev.Rune() == '?' {
|
||||||
|
state.prevView = state.view
|
||||||
|
state.view = viewTypeHelp
|
||||||
|
drawDash(s, baseStyle, &state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,13 +176,22 @@ func drawDash(s tcell.Screen, style tcell.Style, state *dashState) {
|
|||||||
s.Clear()
|
s.Clear()
|
||||||
// Simulate data update on every render
|
// Simulate data update on every render
|
||||||
d := NewScreenDrawer(s)
|
d := NewScreenDrawer(s)
|
||||||
d.Println("=== Queues ===", style.Bold(true))
|
switch state.view {
|
||||||
d.NL() // empty line
|
case viewTypeQueues:
|
||||||
drawQueueSizeGraphs(d, style, state)
|
d.Println("=== Queues ===", style.Bold(true))
|
||||||
d.NL() // empty line
|
d.NL() // empty line
|
||||||
drawQueueTable(d, style, state)
|
drawQueueSizeGraphs(d, style, state)
|
||||||
d.GoToBottom()
|
d.NL() // empty line
|
||||||
drawFooter(d, style, state)
|
drawQueueTable(d, style, state)
|
||||||
|
d.GoToBottom()
|
||||||
|
drawFooter(d, style, state)
|
||||||
|
case viewTypeHelp:
|
||||||
|
d.Println("=== HELP ===", style.Bold(true))
|
||||||
|
d.NL() // empty line
|
||||||
|
// TODO: Draw HELP body
|
||||||
|
d.GoToBottom()
|
||||||
|
drawFooter(d, style, state)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawQueueSizeGraphs(d *ScreenDrawer, style tcell.Style, state *dashState) {
|
func drawQueueSizeGraphs(d *ScreenDrawer, style tcell.Style, state *dashState) {
|
||||||
@@ -236,7 +267,12 @@ func drawFooter(d *ScreenDrawer, baseStyle tcell.Style, state *dashState) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
style := baseStyle.Background(tcell.ColorDarkSlateGray)
|
style := baseStyle.Background(tcell.ColorDarkSlateGray)
|
||||||
d.Print("F1=HELP", style)
|
switch state.view {
|
||||||
|
case viewTypeHelp:
|
||||||
|
d.Print("Esc=GoBack", style)
|
||||||
|
default:
|
||||||
|
d.Print("F1=Queues F2=Servers F3=Schedulers F4=Redis ?=Help", style)
|
||||||
|
}
|
||||||
d.FillLine(' ', style)
|
d.FillLine(' ', style)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,8 +364,7 @@ func ByteCount(b int64) string {
|
|||||||
exp++
|
exp++
|
||||||
|
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%.1f% cB",
|
return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "kMGTPE"[exp])
|
||||||
float64(b)/float64(div), "kMGTPE"[exp])
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,6 +451,7 @@ func drawQueueTable(d *ScreenDrawer, style tcell.Style, state *dashState) {
|
|||||||
|
|
||||||
if flagDebug {
|
if flagDebug {
|
||||||
d.Println(fmt.Sprintf("DEBUG: rowIdx = %d", state.rowIdx), style)
|
d.Println(fmt.Sprintf("DEBUG: rowIdx = %d", state.rowIdx), style)
|
||||||
|
d.Println(fmt.Sprintf("DEBUG: view = %v", state.view), style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user