Example #1
0
func guiLoadInfo(ipinfo IPInfoResult, gui *gocui.Gui) {
	gui.Execute(func(g *gocui.Gui) error {

		view, err := gui.View("info")
		if err != nil {
			log.Fatal(err)
		}

		loc, err := ipinfo.GetKey("loc")
		if err != nil {
			log.Fatal(err)
		}

		hostname, err := ipinfo.GetKey("hostname")
		city, err := ipinfo.GetKey("city")
		region, err := ipinfo.GetKey("region")
		country, err := ipinfo.GetKey("country")
		postal, err := ipinfo.GetKey("postal")
		org, err := ipinfo.GetKey("org")

		mu.Lock()
		fmt.Fprintln(view, fmt.Sprintf("Hostname: %s", hostname))
		fmt.Fprintln(view, fmt.Sprintf("Org: %s", org))
		fmt.Fprintln(view, fmt.Sprintf("Longitude,Latitude: %s", loc))
		fmt.Fprintln(view, fmt.Sprintf("City: %s", city))
		fmt.Fprintln(view, fmt.Sprintf("Region: %s", region))
		fmt.Fprintln(view, fmt.Sprintf("Country: %s", country))
		fmt.Fprintln(view, fmt.Sprintf("Postal: %s", postal))
		mu.Unlock()

		return nil
	})
}
Example #2
0
func counter(g *gocui.Gui) {
	defer wg.Done()

	for {
		select {
		case <-done:
			return
		case <-time.After(500 * time.Millisecond):
			mu.Lock()
			n := ctr
			ctr++
			mu.Unlock()

			g.Execute(func(g *gocui.Gui) error {
				v, err := g.View("ctr")
				if err != nil {
					return err
				}
				v.Clear()
				fmt.Fprintln(v, n)
				return nil
			})
		}
	}
}
Example #3
0
func guiLoadMap(ipinfo IPInfoResult, gui *gocui.Gui) {
	gui.Execute(func(g *gocui.Gui) error {

		view, err := gui.View("map")
		if err != nil {
			log.Fatal(err)
		}
		maxX, maxY := view.Size()

		var mapCanvas MapCanvas
		mapCanvas.Init(float64(maxX), float64(maxY))
		mapCanvas.LoadCoordinates(CreateWorldMap())

		lon, lat, err := ipinfo.GetLonLat()
		if err != nil {
			log.Fatal(err)
		}

		mapCanvas.PlotText(lon, lat, "X")

		mu.Lock()
		fmt.Fprintf(view, mapCanvas.String())
		mu.Unlock()

		return nil
	})
}
Example #4
0
func startDeferrerRoutine(gui *gocui.Gui, deferrer <-chan func()) {
	go func() {
		for task := range deferrer {
			deferredTask := task
			gui.Execute(func(*gocui.Gui) error {
				deferredTask()

				return nil
			})
		}
	}()
}
Example #5
0
func watchTubes(g *gocui.Gui) {
	for {
		select {
		case <-stop:
			watch = false
			return
		case <-time.After(time.Duration(*refreshRate) * time.Second):
			//Pause reloads while we're in cmd mode, this could cause weird issues
			//with tubes disappearing when a command is run
			if !cmdMode {
				watch = true
				//Refresh tube list
				g.Execute(func(g *gocui.Gui) error {
					return reloadTubes(g)
				})

				_ = reloadMenu(g)
			}
		}
	}
}