Selaa lähdekoodia

Added support for dynamic chart height

arianagiroux 1 kuukausi sitten
vanhempi
sitoutus
008d4fd8c6
2 muutettua tiedostoa jossa 20 lisäystä ja 7 poistoa
  1. 9 2
      cmd/pingo.go
  2. 11 5
      tui.go

+ 9 - 2
cmd/pingo.go

@@ -129,7 +129,12 @@ func (m Model) View() tea.View {
 func (m Model) header() string { return titleStyle.Width(m.viewport.Width()).Render("pingo v0") }
 
 func (m Model) footer() string {
-	return footerStyle.Width(m.viewport.Width()).Render("j/k: down/up\t|\tctrl+c: quit")
+	s := ""
+	if m.p.ChartHeight != -1 {
+		s = s + "j/k: down/up\t|\t"
+	}
+	s = s + "ctrl+c: quit"
+	return footerStyle.Width(m.viewport.Width()).Render(s)
 }
 
 // get lipgloss.Height value of header and footer
@@ -139,7 +144,9 @@ func main() {
 	// get timing interval in milliseconds
 	speed := flag.Int("s", 80, "the interval in milliseconds between pings")
 	chartHeight := flag.Int("h", 0,
-		"the height of the latency chart. set to 0 to render charts full screen.")
+		"the height of the latency chart. set to -1 to render chart height dynamically. "+
+			"defaults to full screen for all charts.",
+	)
 	flag.Parse()
 	hosts := flag.Args()
 

+ 11 - 5
tui.go

@@ -184,13 +184,14 @@ func (p Peak) View() tea.View {
 
 			var slc streamlinechart.Model
 
-			if p.ChartHeight == 0 && len(p.Addresses) == 1 { // catch user specified fullscreen
+			if p.ChartHeight == 0 { // && len(p.Addresses) == 1 { // catch user specified fullscreen
 				// render chart at fullscreen
-				slc = streamlinechart.New(p.Width, p.Height-1)
-			} else if p.ChartHeight == 0 && len(p.Addresses) > 1 { // catch user specified fullscreen
+				slc = streamlinechart.New(p.Width, p.Height-3)
+			} else if p.ChartHeight == -1 && len(p.Addresses) > 1 { // catch user specified fullscreen
 				// render chart at fullscreen minus a few lines to hint at scrolling
-				slc = streamlinechart.New(p.Width, p.Height-2)
-			} else {
+				slc = streamlinechart.New(p.Width, p.getDynamicChartHeight()-1)
+				// slc = streamlinechart.New(p.Width, p.Height-2)
+			} else if p.ChartHeight >= 1 {
 				slc = streamlinechart.New(p.Width, p.ChartHeight-1) // DEPRECATE
 			}
 
@@ -222,3 +223,8 @@ func (p Peak) Poll() tea.Cmd {
 	}
 	return tea.Batch(cmds...)
 }
+
+func (p Peak) getDynamicChartHeight() int {
+	nAddresses := len(p.Addresses)
+	return p.Height / nAddresses
+}