diff --git a/components/debug.go b/components/debug.go index 22f44f9..0fff57a 100644 --- a/components/debug.go +++ b/components/debug.go @@ -2,6 +2,8 @@ package components import "github.com/erroneousboat/termui" +// Debug can be used to relay debugging information in the Debug component, +// see event.go on how to use it type Debug struct { Par *termui.Par List *termui.List @@ -46,5 +48,11 @@ func (d *Debug) SetY(y int) { // Println will add the text to the Debug component func (d *Debug) Println(text string) { d.List.Items = append(d.List.Items, text) + + // When at the end remove first item + if len(d.List.Items) > d.List.InnerBounds().Max.Y-1 { + d.List.Items = d.List.Items[1:] + } + termui.Render(d) } diff --git a/handlers/event.go b/handlers/event.go index 15b3770..76c0a21 100644 --- a/handlers/event.go +++ b/handlers/event.go @@ -56,6 +56,11 @@ func eventHandler(ctx *context.AppContext) { ev := <-ctx.EventQueue handleTermboxEvents(ctx, ev) handleMoreTermboxEvents(ctx, ev) + + // Place your debugging statements here + if ctx.Debug { + ctx.View.Debug.Println("hello world") + } } }() }