Pārlūkot izejas kodu

Allows user to set chart height, enables fullscreen charts

arianagiroux 3 nedēļas atpakaļ
vecāks
revīzija
e34f85fae8
3 mainītis faili ar 15 papildinājumiem un 8 dzēšanām
  1. 0 1
      Readme.md
  2. 12 4
      internal/tui/tui.go
  3. 3 3
      main.go

+ 0 - 1
Readme.md

@@ -8,7 +8,6 @@ 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

+ 12 - 4
internal/tui/tui.go

@@ -17,13 +17,15 @@ type Model struct {
 	Addresses   []Address // as defined in internal/tui/types.go
 	viewport    viewport.Model
 	UpdateSpeed time.Duration
+	ChartHeight int
 }
 
-func InitialModel(addresses []string, speed time.Duration) Model {
+func InitialModel(addresses []string, speed time.Duration, chartHeight int) Model {
 	var model Model
 	model.viewport = viewport.New(0, 0)
 	model.viewport.MouseWheelEnabled = true
 	model.UpdateSpeed = speed
+	model.ChartHeight = chartHeight
 
 	for _, address := range addresses {
 		var addr Address
@@ -63,7 +65,13 @@ func (m Model) content() string {
 			output = output + fmt.Sprintf("\n%s", blockStyle.Render(headerStyle.Render(address.Address)))
 
 			// Linechart
-			slc := streamlinechart.New(m.width, 10)
+			var slc streamlinechart.Model
+			if m.ChartHeight == 0 {
+				slc = streamlinechart.New(m.width, m.viewport.Height-9)
+			} else {
+				slc = streamlinechart.New(m.width, m.ChartHeight)
+			}
+
 			for _, v := range address.results {
 				slc.Push(v)
 			}
@@ -92,9 +100,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 
 	case tea.KeyMsg:
 		if k := msg.String(); k == "j" { // scroll down
-			m.viewport.HalfViewDown()
+			m.viewport.LineDown(8)
 		} else if k == "k" { // scroll up
-			m.viewport.HalfViewUp()
+			m.viewport.LineUp(8)
 		} else {
 			return m, tea.Quit
 		}

+ 3 - 3
main.go

@@ -1,7 +1,5 @@
 // A simple TUI application that charts latency times to specified hosts.
 //
-// TODO(main): set chart height by user flag
-//
 // TODO(main): determine chart heights dynamically by number of addresses
 //
 // TODO(performance): implement ping message channel buffering
@@ -25,6 +23,8 @@ import (
 
 func main() {
 	speed := flag.Int("s", 80, "the speed with which the UI runs")
+	chartHeight := flag.Int("h", 0,
+		"the height of the latency chart. set to 0 to render charts full screen.")
 	flag.Parse()
 	hosts := flag.Args()
 
@@ -33,7 +33,7 @@ func main() {
 		return
 	}
 	var model = tui.InitialModel(
-		hosts, time.Duration(*speed),
+		hosts, time.Duration(*speed), *chartHeight,
 	)
 
 	p := tea.NewProgram(model,