diff --git a/debug.go b/debug.go new file mode 100644 index 0000000..5059c9c --- /dev/null +++ b/debug.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "reflect" +) + +func inspect(i interface{}) (s string) { + val := reflect.ValueOf(i) + elem := val.Type().Elem() + + eName := elem.String() + for i := 0; i < elem.NumField(); i++ { + field := elem.Field(i) + fieldVal := reflect.Indirect(val).FieldByName(field.Name) + s += fmt.Sprintf("%s.%s = ", eName, field.Name) + s += fmt.Sprintf("%v (%s)\n", fieldVal, field.Type) + } + return s +} diff --git a/grid.go b/grid.go index 1586681..75eb8bb 100644 --- a/grid.go +++ b/grid.go @@ -122,6 +122,15 @@ func (g *Grid) redrawRows() { ui.Render(cGrid) } +// Log current container and widget state +func (g *Grid) dumpContainer() { + c, _ := g.cSource.Get(g.cursorID) + msg := fmt.Sprintf("logging state for container: %s\n", c.ShortID()) + msg += fmt.Sprintf("id = %s\nname = %s\nstate = %s\n", c.id, c.name, c.state) + msg += inspect(&c.metrics) + log.Infof(msg) +} + func (g *Grid) ExpandView() { ui.Clear() ui.DefaultEvtStream.ResetHandlers() @@ -142,6 +151,7 @@ func (g *Grid) ExpandView() { ui.Loop() container.widgets = curWidgets + container.widgets.Reset() } func logEvent(e ui.Event) { @@ -178,6 +188,9 @@ func Display(g *Grid) bool { config.Toggle("allContainers") g.redrawRows() }) + ui.Handle("/sys/kbd/D", func(ui.Event) { + g.dumpContainer() + }) ui.Handle("/sys/kbd/f", func(ui.Event) { menu = FilterMenu ui.StopLoop()