Jelajahi Sumber

Made cmd/pingo.go update chart heights aprpopriately

arianagiroux 1 Minggu lalu
induk
melakukan
ad5c0746d1
1 mengubah file dengan 5 tambahan dan 4 penghapusan
  1. 5 4
      cmd/pingo.go

+ 5 - 4
cmd/pingo.go

@@ -49,10 +49,10 @@ func (m md) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	switch msg := msg.(type) {
 	case tea.WindowSizeMsg:
 		m.p.Width = msg.Width
-		m.p.Height = msg.Height
+		m.p.Height = msg.Height - m.getVerticalMargin() - 1
 		if m.viewport.Width() == 0 && m.viewport.Height() == 0 {
 			m.viewport = viewport.New(
-				viewport.WithHeight(msg.Height),
+				viewport.WithHeight(msg.Height-m.getVerticalMargin()),
 				viewport.WithWidth(msg.Width),
 			)
 		}
@@ -73,7 +73,8 @@ func (m md) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	m.viewport, cmd = m.viewport.Update(msg)
 	cmds = append(cmds, cmd)
 
-	m.p, cmd = m.p.Update(msg)
+	model, cmd := m.p.Update(msg)
+	m.p = model.(pingo.Model)
 	cmds = append(cmds, cmd)
 
 	return m, tea.Batch(cmds...)
@@ -109,7 +110,7 @@ func main() {
 		return
 	}
 
-	p := tea.NewProgram(md{p: pingo.InitialModel([]string{"google.ca", "asdf"}, 20, 10, *chartHeight)})
+	p := tea.NewProgram(md{p: pingo.InitialModel(hosts, 20, 10, *chartHeight)})
 
 	if _, err := p.Run(); err != nil {
 		fmt.Printf("Alas, there's been an error: %v", err)