From 9cd65525b3c5c46fd28ef920a42c29015c1536cf Mon Sep 17 00:00:00 2001 From: Alex Mylonas Date: Sun, 5 Oct 2025 20:33:33 +0300 Subject: [PATCH 1/2] fix: scrollable windows + logging --- go-peer/main.go | 13 +++++++++++++ go-peer/ui.go | 9 ++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/go-peer/main.go b/go-peer/main.go index 5ec66ab5..1e7fa431 100644 --- a/go-peer/main.go +++ b/go-peer/main.go @@ -115,7 +115,13 @@ func main() { flag.Parse() +// 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 { +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, From ea5c0bc620198244954a8813ab49e65d0106e807 Mon Sep 17 00:00:00 2001 From: Alex Mylonas Date: Sun, 5 Oct 2025 20:37:41 +0300 Subject: [PATCH 2/2] go fmt --- go-peer/main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/go-peer/main.go b/go-peer/main.go index 1e7fa431..4f512387 100644 --- a/go-peer/main.go +++ b/go-peer/main.go @@ -115,12 +115,12 @@ func main() { flag.Parse() -// Only enable debug logging in headless mode, otherwise it interferes with the TUI + // Only enable debug logging in headless mode, otherwise it interferes with the TUI if *headless { - log.SetLogLevel("app", "debug") -} else { + log.SetLogLevel("app", "debug") + } else { // Suppress all logging to avoid TUI interference - log.SetLogLevel("app", "fatal") + log.SetLogLevel("app", "fatal") } ctx := context.Background() @@ -268,11 +268,11 @@ func main() { rm := h.Network().ResourceManager() rm.ViewSystem( func(rs network.ResourceScope) error { -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()) -} + 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 {