From 7fec49ff040dfd4256554bfb91108b3244aa3e61 Mon Sep 17 00:00:00 2001 From: talksik Date: Mon, 27 Oct 2025 16:17:23 -0700 Subject: [PATCH] support refreshing data --- go-cli/cmd/main.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/go-cli/cmd/main.go b/go-cli/cmd/main.go index 37ed397..f095769 100644 --- a/go-cli/cmd/main.go +++ b/go-cli/cmd/main.go @@ -102,7 +102,6 @@ type model struct { viewport viewport.Model detailViewport viewport.Model ready bool - showKeypad bool terminalWidth int terminalHeight int focusOnDetail bool // true = detail panel has focus, false = list has focus @@ -110,9 +109,8 @@ type model struct { func initialModel(humans []*HumanData) model { return model{ - humans: humans, - cursor: 0, - showKeypad: false, + humans: humans, + cursor: 0, } } @@ -181,6 +179,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } + case "r": + m.humans = getHumansData() + m.cursor = 0 + m.viewport.SetContent(m.renderList()) + m.detailViewport.SetContent(m.renderDetails()) + m.detailViewport.GotoTop() + case "down", "j": if m.cursor < len(m.humans)-1 { m.cursor++ @@ -282,7 +287,7 @@ func (m model) View() string { statusBar := statusStyle.Render(fmt.Sprintf(" %d/%d", m.cursor+1, len(m.humans))) // Help text - help := helpStyle.Render("↑/k up • ↓/j down • ctrl+u/d scroll detail • q quit") + help := helpStyle.Render("↑/k up • ↓/j down • ctrl+u/d scroll detail • r refresh • q quit") // Create two-column layout leftPanel := m.viewport.View() @@ -308,6 +313,15 @@ func unaryInterceptor(ctx context.Context, method string, req, reply interface{} func main() { logrus.Infof("hello world") + humansData := getHumansData() + p := tea.NewProgram(initialModel(humansData)) + if _, err := p.Run(); err != nil { + fmt.Printf("Alas, there's been an error: %v", err) + os.Exit(1) + } +} + +func getHumansData() []*HumanData { heliosAddr := "helios.flowy.live:443" creds := credentials.NewTLS(&tls.Config{ InsecureSkipVerify: true, @@ -332,12 +346,6 @@ func main() { os.Exit(1) } - keypadsResponse.GetHumanKeypads()[0].GetHumanId() - keypadsResponse.GetHumanKeypads()[0].GetYamlConfig() - - logrus.Info("connected to helios") - logrus.Infof("fetched %d humans", len(humansResponse.GetHumans())) - humansData := []*HumanData{} for _, human := range humansResponse.GetHumans() { keypadConfiguration := "" @@ -354,9 +362,5 @@ func main() { }) } - p := tea.NewProgram(initialModel(humansData)) - if _, err := p.Run(); err != nil { - fmt.Printf("Alas, there's been an error: %v", err) - os.Exit(1) - } + return humansData }