Quellcode durchsuchen

Implemented help and header/footer in tui

arianagiroux vor 3 Wochen
Ursprung
Commit
afdb7e6495
2 geänderte Dateien mit 26 neuen und 19 gelöschten Zeilen
  1. 4 4
      Readme.md
  2. 22 15
      internal/tui/tui.go

+ 4 - 4
Readme.md

@@ -8,10 +8,10 @@ additionally, see `bin/` for additional pre-compiled binaries
 
 ## TODO:
 
-- main.go:// TODO(main): set chart height by user flag
-- main.go:// TODO(main): determine chart heights dynamically by number of addresses
-- main.go:// TODO(performance): implement ping message channel buffering
-- main.go:// TODO(tui): notify user when an address is not resolving
+main.go:// TODO(main): set chart height by user flag
+main.go:// TODO(main): determine chart heights dynamically by number of addresses
+main.go:// TODO(performance): implement ping message channel buffering
+main.go:// TODO(tui): notify user when an address is not resolving
 
 > NOTE: generate this list via `git grep '// TODO' -- ':(exclude)Readme.md'`
 

+ 22 - 15
internal/tui/tui.go

@@ -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