|
|
@@ -1,3 +1,4 @@
|
|
|
+// TODO(doc): document TUI lifecycle
|
|
|
package tui
|
|
|
|
|
|
import (
|
|
|
@@ -54,21 +55,15 @@ func (m Model) content() string {
|
|
|
Width(m.width).
|
|
|
Align(lipgloss.Center)
|
|
|
|
|
|
- var footerStyle = lipgloss.NewStyle().
|
|
|
- Width(m.width).
|
|
|
- Align(lipgloss.Center).
|
|
|
- Italic(true).
|
|
|
- Faint(true)
|
|
|
-
|
|
|
output := "\n"
|
|
|
for _, address := range m.Addresses {
|
|
|
if len(address.results) == 0 {
|
|
|
- output = output + fmt.Sprintf("\n%s\tloading...\n\n", headerStyle.Render(address.Address))
|
|
|
- } else {
|
|
|
- output = output + fmt.Sprintf("\n%s\n\n", blockStyle.Render(headerStyle.Render(address.Address)))
|
|
|
+ output = output + fmt.Sprintf("\n%s\tloading...", headerStyle.Render(address.Address))
|
|
|
+ } else if m.viewport.Width != 0 && m.viewport.Height != 0 {
|
|
|
+ output = output + fmt.Sprintf("\n%s", blockStyle.Render(headerStyle.Render(address.Address)))
|
|
|
|
|
|
// Linechart
|
|
|
- slc := streamlinechart.New(m.width, 7)
|
|
|
+ slc := streamlinechart.New(m.width, 10)
|
|
|
for _, v := range address.results {
|
|
|
slc.Push(v)
|
|
|
}
|
|
|
@@ -77,8 +72,6 @@ func (m Model) content() string {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- output = output + footerStyle.Render("\n--------\npingo v0\n")
|
|
|
-
|
|
|
return output
|
|
|
}
|
|
|
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
@@ -93,9 +86,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
address.max_results = m.width
|
|
|
m.Addresses[i] = address
|
|
|
}
|
|
|
- m.viewport.Height = msg.Height
|
|
|
+ m.viewport.Height = msg.Height - 4
|
|
|
m.viewport.Width = msg.Width
|
|
|
- // m.viewport.YPosition = 0
|
|
|
+ m.viewport.YPosition = 1
|
|
|
|
|
|
case tea.KeyMsg:
|
|
|
if k := msg.String(); k == "j" { // scroll down
|
|
|
@@ -120,7 +113,21 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
}
|
|
|
|
|
|
func (m Model) View() string {
|
|
|
- return fmt.Sprintf("\n%s\n", m.viewport.View())
|
|
|
+ var headerStyle = lipgloss.NewStyle().
|
|
|
+ Width(m.width).
|
|
|
+ Align(lipgloss.Center).
|
|
|
+ Italic(true).
|
|
|
+ Faint(true)
|
|
|
+
|
|
|
+ var footerStyle = lipgloss.NewStyle().
|
|
|
+ Width(m.width).
|
|
|
+ Align(lipgloss.Center).
|
|
|
+ Italic(true).
|
|
|
+ Faint(true)
|
|
|
+
|
|
|
+ header := headerStyle.Render("pingo v0")
|
|
|
+ footer := footerStyle.Render("\nj/k: down/up\t|\tq/ctrl-c/esc: quit\n")
|
|
|
+ return fmt.Sprintf("\n%s\n%s\n%s", header, m.viewport.View(), footer)
|
|
|
}
|
|
|
|
|
|
// A wrapper for the underlying [tui.Address.Poll] function. For each address in
|