Improve debug output options
This commit is contained in:
		
							
								
								
									
										12
									
								
								gomuks.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								gomuks.go
									
									
									
									
									
								
							@@ -43,7 +43,7 @@ type Gomuks struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// NewGomuks creates a new Gomuks instance with everything initialized,
 | 
					// NewGomuks creates a new Gomuks instance with everything initialized,
 | 
				
			||||||
// but does not start it.
 | 
					// but does not start it.
 | 
				
			||||||
func NewGomuks(enableDebug bool) *Gomuks {
 | 
					func NewGomuks(enableDebug, forceExternalDebug bool) *Gomuks {
 | 
				
			||||||
	configDir := filepath.Join(os.Getenv("HOME"), ".config/gomuks")
 | 
						configDir := filepath.Join(os.Getenv("HOME"), ".config/gomuks")
 | 
				
			||||||
	gmx := &Gomuks{
 | 
						gmx := &Gomuks{
 | 
				
			||||||
		app:  tview.NewApplication(),
 | 
							app:  tview.NewApplication(),
 | 
				
			||||||
@@ -70,7 +70,11 @@ func NewGomuks(enableDebug bool) *Gomuks {
 | 
				
			|||||||
	main := gmx.ui.InitViews()
 | 
						main := gmx.ui.InitViews()
 | 
				
			||||||
	if enableDebug {
 | 
						if enableDebug {
 | 
				
			||||||
		debug.EnableExternal()
 | 
							debug.EnableExternal()
 | 
				
			||||||
		main = gmx.debug.Wrap(main)
 | 
							if forceExternalDebug {
 | 
				
			||||||
 | 
								debug.RedirectAllExt = true
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								main = gmx.debug.Wrap(main, debug.Right)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		gmx.debugMode = true
 | 
							gmx.debugMode = true
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	gmx.app.SetRoot(main, true)
 | 
						gmx.app.SetRoot(main, true)
 | 
				
			||||||
@@ -166,8 +170,8 @@ func (gmx *Gomuks) UI() ifc.GomuksUI {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	enableDebug := len(os.Getenv("DEBUG")) > 0
 | 
						debugVar := os.Getenv("DEBUG")
 | 
				
			||||||
	NewGomuks(enableDebug).Start()
 | 
						NewGomuks(len(debugVar) > 0, debugVar == "ext").Start()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// We use os.Exit() everywhere, so exiting by returning from Start() shouldn't happen.
 | 
						// We use os.Exit() everywhere, so exiting by returning from Start() shouldn't happen.
 | 
				
			||||||
	time.Sleep(5 * time.Second)
 | 
						time.Sleep(5 * time.Second)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,10 +35,12 @@ type Printer interface {
 | 
				
			|||||||
type Pane struct {
 | 
					type Pane struct {
 | 
				
			||||||
	*tview.TextView
 | 
						*tview.TextView
 | 
				
			||||||
	Height int
 | 
						Height int
 | 
				
			||||||
 | 
						Width  int
 | 
				
			||||||
	num    int
 | 
						num    int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var Default Printer
 | 
					var Default Printer
 | 
				
			||||||
 | 
					var RedirectAllExt bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewPane() *Pane {
 | 
					func NewPane() *Pane {
 | 
				
			||||||
	pane := tview.NewTextView()
 | 
						pane := tview.NewTextView()
 | 
				
			||||||
@@ -52,6 +54,7 @@ func NewPane() *Pane {
 | 
				
			|||||||
	return &Pane{
 | 
						return &Pane{
 | 
				
			||||||
		TextView: pane,
 | 
							TextView: pane,
 | 
				
			||||||
		Height:   35,
 | 
							Height:   35,
 | 
				
			||||||
 | 
							Width:    80,
 | 
				
			||||||
		num:      0,
 | 
							num:      0,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -69,20 +72,49 @@ func (db *Pane) WriteString(text string) {
 | 
				
			|||||||
	fmt.Fprintf(db, "[%d] %s", db.num, text)
 | 
						fmt.Fprintf(db, "[%d] %s", db.num, text)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (db *Pane) Wrap(main tview.Primitive) tview.Primitive {
 | 
					type PaneSide int
 | 
				
			||||||
	return tview.NewGrid().SetRows(0, db.Height).SetColumns(0).
 | 
					
 | 
				
			||||||
		AddItem(main, 0, 0, 1, 1, 1, 1, true).
 | 
					const (
 | 
				
			||||||
		AddItem(db, 1, 0, 1, 1, 1, 1, false)
 | 
						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{}) {
 | 
					func Printf(text string, args ...interface{}) {
 | 
				
			||||||
	if Default != nil {
 | 
						if RedirectAllExt {
 | 
				
			||||||
 | 
							ExtPrintf(text, args...)
 | 
				
			||||||
 | 
						} else if Default != nil {
 | 
				
			||||||
		Default.Printf(text, args...)
 | 
							Default.Printf(text, args...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Print(text ...interface{}) {
 | 
					func Print(text ...interface{}) {
 | 
				
			||||||
	if Default != nil {
 | 
						if RedirectAllExt {
 | 
				
			||||||
 | 
							ExtPrint(text...)
 | 
				
			||||||
 | 
						} else if Default != nil {
 | 
				
			||||||
		Default.Print(text...)
 | 
							Default.Print(text...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user