pingo.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // A simple TUI application that charts latency times to specified hosts.
  2. //
  3. // TODO(main): determine chart heights dynamically by number of addresses
  4. //
  5. // TODO(performance): implement ping message channel buffering
  6. //
  7. // i.e, change the address title to red so long as there is a single -1 in
  8. // the display buffer, and a toast notification (???) if a display buffer is
  9. // entirely composed of -1
  10. package main
  11. import (
  12. "flag"
  13. "fmt"
  14. "os"
  15. "pingo"
  16. "time"
  17. tea "github.com/charmbracelet/bubbletea"
  18. )
  19. func main() {
  20. speed := flag.Int("s", 80, "the speed with which the UI runs")
  21. chartHeight := flag.Int("h", 0,
  22. "the height of the latency chart. set to 0 to render charts full screen.")
  23. flag.Parse()
  24. hosts := flag.Args()
  25. if len(hosts) == 0 {
  26. fmt.Println("Must specify hosts!")
  27. return
  28. }
  29. var model = pingo.InitialModel(
  30. hosts, time.Duration(*speed), *chartHeight,
  31. )
  32. p := tea.NewProgram(model,
  33. tea.WithAltScreen(), // use the full size of the terminal in its "alternate screen buffer"
  34. // tea.WithMouseCellMotion(), // turn on mouse support so we can track the mouse wheel
  35. )
  36. if _, err := p.Run(); err != nil {
  37. fmt.Printf("Alas, there's been an error: %v", err)
  38. os.Exit(1)
  39. }
  40. }