support refreshing data
This commit is contained in:
+20
-16
@@ -102,7 +102,6 @@ type model struct {
|
|||||||
viewport viewport.Model
|
viewport viewport.Model
|
||||||
detailViewport viewport.Model
|
detailViewport viewport.Model
|
||||||
ready bool
|
ready bool
|
||||||
showKeypad bool
|
|
||||||
terminalWidth int
|
terminalWidth int
|
||||||
terminalHeight int
|
terminalHeight int
|
||||||
focusOnDetail bool // true = detail panel has focus, false = list has focus
|
focusOnDetail bool // true = detail panel has focus, false = list has focus
|
||||||
@@ -110,9 +109,8 @@ type model struct {
|
|||||||
|
|
||||||
func initialModel(humans []*HumanData) model {
|
func initialModel(humans []*HumanData) model {
|
||||||
return model{
|
return model{
|
||||||
humans: humans,
|
humans: humans,
|
||||||
cursor: 0,
|
cursor: 0,
|
||||||
showKeypad: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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":
|
case "down", "j":
|
||||||
if m.cursor < len(m.humans)-1 {
|
if m.cursor < len(m.humans)-1 {
|
||||||
m.cursor++
|
m.cursor++
|
||||||
@@ -282,7 +287,7 @@ func (m model) View() string {
|
|||||||
statusBar := statusStyle.Render(fmt.Sprintf(" %d/%d", m.cursor+1, len(m.humans)))
|
statusBar := statusStyle.Render(fmt.Sprintf(" %d/%d", m.cursor+1, len(m.humans)))
|
||||||
|
|
||||||
// Help text
|
// 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
|
// Create two-column layout
|
||||||
leftPanel := m.viewport.View()
|
leftPanel := m.viewport.View()
|
||||||
@@ -308,6 +313,15 @@ func unaryInterceptor(ctx context.Context, method string, req, reply interface{}
|
|||||||
func main() {
|
func main() {
|
||||||
logrus.Infof("hello world")
|
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"
|
heliosAddr := "helios.flowy.live:443"
|
||||||
creds := credentials.NewTLS(&tls.Config{
|
creds := credentials.NewTLS(&tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
@@ -332,12 +346,6 @@ func main() {
|
|||||||
os.Exit(1)
|
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{}
|
humansData := []*HumanData{}
|
||||||
for _, human := range humansResponse.GetHumans() {
|
for _, human := range humansResponse.GetHumans() {
|
||||||
keypadConfiguration := ""
|
keypadConfiguration := ""
|
||||||
@@ -354,9 +362,5 @@ func main() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
p := tea.NewProgram(initialModel(humansData))
|
return humansData
|
||||||
if _, err := p.Run(); err != nil {
|
|
||||||
fmt.Printf("Alas, there's been an error: %v", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user