Skip to content

Commit

Permalink
Configure refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Feb 28, 2024
1 parent 8a309dc commit 67d24cc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
7 changes: 0 additions & 7 deletions config/ui.go

This file was deleted.

3 changes: 1 addition & 2 deletions ui/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ui

import (
"github.com/bahner/go-ma-actor/config"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
Expand Down Expand Up @@ -31,7 +30,7 @@ func (ui *ChatUI) setupApp() {
// the peers list takes 20 columns, and the messages take the remaining space
ui.chatPanel = tview.NewFlex().
AddItem(msgBox, 0, 1, false).
AddItem(peersList, config.GetUIPeerslistWidth(), 1, false)
AddItem(peersList, getUIPeerslistWidth(), 1, false)

// The ordering here is a little kludgy, but acceptable for now.
// the input fiield setup became rather verbose, so it was moved to its own file.
Expand Down
2 changes: 2 additions & 0 deletions ui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func (ui *ChatUI) handleCommands(input string) {
ui.handleMeCommands(args)
case "/refresh":
ui.refreshPeers()
ui.msgBox.Clear()
ui.app.Draw()
default:
ui.displaySystemMessage("Unknown command: " + args[0])
}
Expand Down
14 changes: 14 additions & 0 deletions ui/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ui

import (
"time"

"github.com/spf13/viper"
)

func getUIPeerslistWidth() int {
return viper.GetInt("ui.peerslist-width")
}
func getUIPeersRefreshInterval() time.Duration {
return viper.GetDuration("ui.refresh")
}
2 changes: 1 addition & 1 deletion ui/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (ui *ChatUI) displaySystemMessage(msg string) {
// refreshes the list of peers in the UI.

func (ui *ChatUI) handleEvents() {
peerRefreshTicker := time.NewTicker(time.Second)
peerRefreshTicker := time.NewTicker(getUIPeersRefreshInterval())
defer peerRefreshTicker.Stop()

for {
Expand Down
11 changes: 8 additions & 3 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"time"

"github.com/bahner/go-ma-actor/config"
"github.com/bahner/go-ma-actor/entity"
Expand All @@ -25,14 +26,18 @@ const (

defaultLimbo = "closet"

defaultPeerslistWidth = 10
defaultPeerslistWidth = 10
defaultPeerslistRefresh = time.Second * 3
)

func init() {

// UI
pflag.Int("peerslist-width", defaultPeerslistWidth, "Sets the width of the peerslist pane in the UI")
viper.BindPFlag("ui.peerslist-width", pflag.Lookup("peerslist-width"))
pflag.Int("ui-peerslist-width", defaultPeerslistWidth, "Sets the width of the peerslist pane in the UI")
viper.BindPFlag("ui.peerslist-width", pflag.Lookup("ui-peerslist-width"))

pflag.Duration("ui-refresh", defaultPeerslistRefresh, "Sets the update frequency of the peerslist pane in the UI")
viper.BindPFlag("ui.refresh", pflag.Lookup("ui-refresh"))

}

Expand Down

0 comments on commit 67d24cc

Please sign in to comment.