From dd89fa621d6824edf96c61e47099f1c6ad0bfd09 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 1 Apr 2018 10:05:29 +0300 Subject: Improve debug output options --- ui/debug/debug.go | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'ui/debug/debug.go') diff --git a/ui/debug/debug.go b/ui/debug/debug.go index a87d64c..3f47980 100644 --- a/ui/debug/debug.go +++ b/ui/debug/debug.go @@ -35,10 +35,12 @@ type Printer interface { type Pane struct { *tview.TextView Height int + Width int num int } var Default Printer +var RedirectAllExt bool func NewPane() *Pane { pane := tview.NewTextView() @@ -52,6 +54,7 @@ func NewPane() *Pane { return &Pane{ TextView: pane, Height: 35, + Width: 80, num: 0, } } @@ -69,20 +72,49 @@ func (db *Pane) WriteString(text string) { fmt.Fprintf(db, "[%d] %s", db.num, text) } -func (db *Pane) Wrap(main tview.Primitive) tview.Primitive { - return tview.NewGrid().SetRows(0, db.Height).SetColumns(0). - AddItem(main, 0, 0, 1, 1, 1, 1, true). - AddItem(db, 1, 0, 1, 1, 1, 1, false) +type PaneSide int + +const ( + Top PaneSide = iota + Bottom + Left + Right +) + +func (db *Pane) Wrap(main tview.Primitive, side PaneSide) tview.Primitive { + rows, columns := []int{0}, []int{0} + mainRow, mainColumn, paneRow, paneColumn := 0, 0, 0, 0 + switch side { + case Top: + rows = []int{db.Height, 0} + mainRow = 1 + case Bottom: + rows = []int{0, db.Height} + paneRow = 1 + case Left: + columns = []int{db.Width, 0} + mainColumn = 1 + case Right: + columns = []int{0, db.Width} + paneColumn = 1 + } + return tview.NewGrid().SetRows(rows...).SetColumns(columns...). + AddItem(main, mainRow, mainColumn, 1, 1, 1, 1, true). + AddItem(db, paneRow, paneColumn, 1, 1, 1, 1, false) } func Printf(text string, args ...interface{}) { - if Default != nil { + if RedirectAllExt { + ExtPrintf(text, args...) + } else if Default != nil { Default.Printf(text, args...) } } func Print(text ...interface{}) { - if Default != nil { + if RedirectAllExt { + ExtPrint(text...) + } else if Default != nil { Default.Print(text...) } } -- cgit v1.2.3