diff --git a/go-peer/main.go b/go-peer/main.go index 5ec66ab5..4f512387 100644 --- a/go-peer/main.go +++ b/go-peer/main.go @@ -115,7 +115,13 @@ func main() { flag.Parse() - log.SetLogLevel("app", "debug") + // Only enable debug logging in headless mode, otherwise it interferes with the TUI + if *headless { + log.SetLogLevel("app", "debug") + } else { + // Suppress all logging to avoid TUI interference + log.SetLogLevel("app", "fatal") + } ctx := context.Background() @@ -262,9 +268,16 @@ func main() { rm := h.Network().ResourceManager() rm.ViewSystem( func(rs network.ResourceScope) error { - fmt.Printf("Stats: %+v\n", rs.Stat()) - if r, ok := rs.(interface{ Limit() rcmgr.Limit }); ok { - fmt.Printf("Limits: %+v\n", r.Limit()) + if *headless { + fmt.Printf("Stats: %+v\n", rs.Stat()) + if r, ok := rs.(interface{ Limit() rcmgr.Limit }); ok { + fmt.Printf("Limits: %+v\n", r.Limit()) + } + } else { + LogMsgf("Stats: %+v", rs.Stat()) + if r, ok := rs.(interface{ Limit() rcmgr.Limit }); ok { + LogMsgf("Limits: %+v", r.Limit()) + } } return nil }, diff --git a/go-peer/ui.go b/go-peer/ui.go index 13d4d040..d2eb47ce 100644 --- a/go-peer/ui.go +++ b/go-peer/ui.go @@ -29,17 +29,20 @@ type ChatUI struct { // It won't actually do anything until you call Run(). func NewChatUI(cr *ChatRoom) *ChatUI { app := tview.NewApplication() + app.EnableMouse(true) // Enable mouse support // make a text view to contain our chat messages msgBox := tview.NewTextView() msgBox.SetDynamicColors(true) msgBox.SetBorder(true) msgBox.SetTitle(fmt.Sprintf("Room: %s", cr.roomName)) + msgBox.SetScrollable(true) // text views are io.Writers, but they don't automatically refresh. // this sets a change handler to force the app to redraw when we get // new messages to display. msgBox.SetChangedFunc(func() { + msgBox.ScrollToEnd() app.Draw() }) @@ -48,11 +51,13 @@ func NewChatUI(cr *ChatRoom) *ChatUI { sysBox.SetDynamicColors(true) sysBox.SetBorder(true) sysBox.SetTitle("System") + sysBox.SetScrollable(true) // text views are io.Writers, but they don't automatically refresh. // this sets a change handler to force the app to redraw when we get // new messages to display. sysBox.SetChangedFunc(func() { + sysBox.ScrollToEnd() app.Draw() }) @@ -156,11 +161,9 @@ func (ui *ChatUI) displayChatMessage(cm *ChatMessage) { fmt.Fprintf(ui.msgW, "%s %s\n", prompt, cm.Message) } -// displayChatMessage writes a ChatMessage from the room to the message window, -// with the sender's nick highlighted in green. +// displaySysMessage writes a system message to the system message window. func (ui *ChatUI) displaySysMessage(cm *ChatMessage) { fmt.Fprintf(ui.sysW, "%s\n", cm.Message) - logger.Info(cm.Message) } // displaySelfMessage writes a message from ourself to the message window,