Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions go-peer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
},
Expand Down
9 changes: 6 additions & 3 deletions go-peer/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand All @@ -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()
})

Expand Down Expand Up @@ -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,
Expand Down