Esempio n. 1
1
File: ui.go Progetto: garry415/goax
func layout(g *gocui.Gui) error {
	maxX, maxY := g.Size()
	if v, err := g.SetView("contacts", 1, 1, 60, maxY-1); err != nil {
		if err != gocui.ErrorUnkView {
			return err
		}
		v.Highlight = true
	}
	if v, err := g.SetView("main", 60, 1, maxX-1, maxY-3); err != nil {
		if err != gocui.ErrorUnkView {
			return err
		}
		v.Wrap = true
		v.WrapPrefix = "  "
	}
	if v, err := g.SetView("input", 60, maxY-3, maxX-1, maxY-1); err != nil {
		if err != gocui.ErrorUnkView {
			return err
		}
		v.Editable = true
		if err := g.SetCurrentView("input"); err != nil {
			return err
		}
	}
	return nil
}
Esempio n. 2
0
func (runner *appRunner) layout(g *gocui.Gui) error {
	maxX, maxY := g.Size()

	view, _ := g.SetView("mainControls", -1, -1, maxX/2, maxY)
	_, originY := view.Origin()
	_, cursorY := view.Cursor()

	view.Clear()
	runner.mainControlLines = 0
	runner.highlightedTexter = nil

	if g.CurrentView() == nil {
		g.SetCurrentView("mainControls")
	}
	view.Highlight = g.CurrentView() == view

	runner.rootTexter.TextMain(func(label, line string, texter ViewModelNodeTexter) {
		paddedLabel := fmt.Sprintf("%20s", label)
		fmt.Fprintf(view, "%s %v\n", paddedLabel[len(paddedLabel)-20:len(paddedLabel)], line)
		if (originY + cursorY) == runner.mainControlLines {
			runner.highlightedTexter = texter
		}
		runner.mainControlLines++
	})

	return nil
}
Esempio n. 3
0
func InputView(g *gocui.Gui, x, y, maxX, maxY int) error {

	if v, err := g.SetView("input", x, y, maxX, maxY); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}

		_, err := g.SetCurrentView("input")

		if err != nil {
			return err
		}

		logger.Logger.Println(" CHANGE:", "input", x, y, maxX, maxY)

		v.Editor = Editor

		// v.FgColor = gocui.ColorGreen
		v.BgColor = gocui.ColorDefault

		v.Autoscroll = false
		v.Editable = true
		v.Wrap = false
		v.Frame = false

	}

	return nil
}
Esempio n. 4
0
func layout(g *gocui.Gui) error {

	maxX, maxY := g.Size()
	v, err := g.SetView("mainmenu", 2, 1, maxX-2, maxY-2)

	v.FgColor = gocui.ColorGreen

	if err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
		//		b, err := ioutil.ReadFile("mainmenu")
		//if err != nil {
		//	log.Panicln(err)
		//	panic(err)
		//}
		v.Title = "Main Menu"
		v.Frame = true
		//fmt.Fprintf(v, "%s", b)

		v.Wrap = true
		v.SetCursor(10, 10)
		fmt.Println(v.Cursor())
	}
	return nil

}
Esempio n. 5
0
func MenuView(g *gocui.Gui, maxX, maxY int) error {

	if v, err := g.SetView("menu", -1, maxY-4, maxX, maxY+3); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}

		_, err := g.SetCurrentView("menu")

		if err != nil {
			return err
		}

		// v.FgColor = gocui.ColorGreen
		v.BgColor = gocui.ColorDefault

		v.Autoscroll = false
		v.Editable = false
		v.Wrap = false
		v.Frame = false

		go func() {
			for range time.Tick(time.Millisecond * 200) {
				UpdateMenuView(g)
			}
		}()

		UpdateMenuView(g)
	}

	return nil
}
Esempio n. 6
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
	})
}
Esempio n. 7
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
	})
}
Esempio n. 8
0
func HeaderView(g *gocui.Gui, x, y, maxX, maxY int) error {

	if v, err := g.SetView("header", x, y, maxX, maxY); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}

		// v.FgColor = gocui.ColorGreen
		v.BgColor = gocui.ColorDefault

		v.Autoscroll = false
		v.Editable = false
		v.Wrap = false
		v.Frame = false
		v.Overwrite = true

		fmt.Fprintf(v, "  --")

		go func() {
			for range time.Tick(time.Millisecond * 100) {
				UpdateHeaderView(g)
			}
		}()

	}

	return nil
}
Esempio n. 9
0
func getLine(g *gocui.Gui, v *gocui.View) error {
	var l string
	var err error

	g.ShowCursor = false

	_, cy := v.Cursor()
	if l, err = v.Line(cy); err != nil {
		l = ""
	}

	maxX, maxY := g.Size()
	length := 10 + len(current_name)
	if l != "" {
		current_name = l
		if v, err := g.SetView("msg", maxX/2-length/2, maxY/2-3, maxX/2+length/2, maxY/2+3); err != nil {
			v.BgColor = gocui.ColorGreen
			v.FgColor = gocui.ColorBlack
			if err != gocui.ErrorUnkView {
				return err
			}
			current_proj = projects[current_name]
			current_proj.start()
			fmt.Fprintln(v, "")
			fmt.Fprintln(v, "")
			fmt.Fprintln(v, strings.Repeat(" ", (length-15)/2), "Active Project")
			fmt.Fprintln(v, "")
			fmt.Fprintln(v, strings.Repeat(" ", 5), current_name)
			fmt.Fprintln(v, "")
			setView(g, "msg")
		}
	}
	return nil
}
Esempio n. 10
0
func MoveTubeCursor(g *gocui.Gui, mx, my int) error {
	if cmdMode {
		return nil
	}

	tv, err := g.View("tubes")
	if err != nil {
		return err
	}

	cx, cy := tv.Cursor()
	ny := cy + my

	//Check the cursor isn't trying to move above the first tube or past the last tube
	if ny < 1 || ny > len(cTubes.Conns) {
		return nil
	}

	if err = tv.SetCursor(cx, ny); err != nil {
		return err
	}

	//Set the selected tube to the currently highlighted row
	cTubes.SelectedIdx = ny - 1
	cTubes.Selected = cTubes.Names[cTubes.SelectedIdx]
	debugLog("Set tube to: ", cTubes.Selected)

	return nil
}
Esempio n. 11
0
func delView(g *gocui.Gui, s string) error {
	if err := g.DeleteView(s); err != nil {
		return err
	}
	return nil

}
Esempio n. 12
0
func removeProject(g *gocui.Gui, v *gocui.View) error {
	var l string
	var err error

	g.ShowCursor = false

	_, cy := v.Cursor()
	if l, err = v.Line(cy); err != nil {
		l = ""
	}
	current_name = l

	maxX, maxY := g.Size()
	length := 20
	if l != "" {
		if v, err := g.SetView("del_proj", maxX/2-length/2, maxY/2, maxX/2+length/2, maxY/2+2); err != nil {
			v.BgColor = gocui.ColorRed
			if err != gocui.ErrorUnkView {
				return err
			}
			fmt.Fprintln(v, "Press 'd' to delete")
			setView(g, "del_proj")
		}
	}
	return nil
}
Esempio n. 13
0
func layout(g *ui.Gui) error {

	x, y := g.Size()
	size := len(cli.Nodes)

	if v, err := g.SetView("nodes-cursor", 0, 0, 6, size+1); err != nil {
		if err != ui.ErrUnknownView {
			return err
		}
		v.Highlight = true
		v.Frame = false
	}

	if v, err := g.SetView("nodes", 2, 0, 20, size+1); err != nil {
		if err != ui.ErrUnknownView {
			return err
		}
		v.Frame = false
		printNodes()
	}

	if v, err := g.SetView("node", 16, 0, x, y-1); err != nil {
		if err != ui.ErrUnknownView {
			return err
		}
		v.Frame = false
		v.Editable = true
		printNode(g)
	}
	return g.SetCurrentView(current)
}
Esempio n. 14
0
File: tui.go Progetto: Rompei/vuls
func changeHost(g *gocui.Gui, v *gocui.View) error {

	if err := g.DeleteView("summary"); err != nil {
		return err
	}
	if err := g.DeleteView("detail"); err != nil {
		return err
	}

	_, cy := v.Cursor()
	l, err := v.Line(cy)
	if err != nil {
		return err
	}
	serverName := strings.TrimSpace(l)

	for _, r := range scanHistory.ScanResults {
		if serverName == strings.TrimSpace(r.ServerInfoTui()) {
			currentScanResult = r
			break
		}
	}

	if err := setSummaryLayout(g); err != nil {
		return err
	}
	if err := setDetailLayout(g); err != nil {
		return err
	}
	return nil
}
Esempio n. 15
0
func (c *column) CreateViews(g *gocui.Gui, colv *gocui.View) error {
	if c.isActive {
		colv.FgColor = gocui.ColorCyan | gocui.AttrBold
	} else {
		colv.FgColor = gocui.ColorDefault
	}
	x, y, maxX, maxY, err := g.ViewPosition(colv.Name())
	y = y + 2
	if err != nil {
		return err
	}
	maxIssues := maxY / LinesPerEntry
	c.maxIssues = maxIssues
	for i := 0; i < maxIssues; i++ {
		v, err := g.SetView(fmt.Sprintf("col-%s-%d", c.name, i),
			x, y+(i*LinesPerEntry), maxX, y+((i+1)*LinesPerEntry))
		if err != nil {
			if err != gocui.ErrorUnkView {
				return err
			}
		}
		v.SelBgColor = gocui.ColorRed
		v.Frame = false
		v.Wrap = true
	}
	return c.redraw(g)
}
Esempio n. 16
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
			})
		}
	}
}
Esempio n. 17
0
func setView(g *gocui.Gui, s string) error {
	if err := g.SetCurrentView(s); err != nil {
		return err
	}
	return nil

}
Esempio n. 18
0
func nextView(g *gocui.Gui, v *gocui.View) error {
	if v == nil || v.Name() == "side" {
		_, err := g.SetCurrentView("main")
		return err
	}
	_, err := g.SetCurrentView("side")
	return err
}
Esempio n. 19
0
func toggleButton(g *gocui.Gui, v *gocui.View) error {
	nextview := "butdown"
	if v != nil && v.Name() == "butdown" {
		nextview = "butup"
	}
	_, err := g.SetCurrentView(nextview)
	return err
}
Esempio n. 20
0
func keybindings(g *ui.Gui) error {
	for _, k := range keys {
		if err := g.SetKeybinding(k.name, k.key, k.mod, k.f); err != nil {
			return err
		}
	}
	return nil
}
Esempio n. 21
0
// the UI could be a lot smoother if there was less Clear()
// and Flush() .. Flush() could run on an interval instead of
// inside these update*View functions
func updateStatusView(g *gocui.Gui) {
	status_view, _ := g.View("status")
	for i := range status_output {
		status_view.Clear()
		fmt.Fprintln(status_view, i)
		g.Flush()
	}
}
Esempio n. 22
0
func FocusAndResetAll(g *gocui.Gui, v *gocui.View) error {
	status, _ := g.View(client.StatusChannel)
	input, _ := g.View("input")

	FocusStatusView(g, status)
	FocusInputView(g, input)
	return nil
}
Esempio n. 23
0
func textUp(g *gocui.Gui, v *gocui.View) error {
	if v, err := g.View(vText); err == nil {
		ox, oy := v.Origin()
		oy = oy - 10
		v.SetOrigin(ox, oy)
	}
	return nil
}
Esempio n. 24
0
func updateMainView(g *gocui.Gui) {
	main_view, _ := g.View("main")
	for i := range main_output {
		main_view.Clear()
		fmt.Fprintln(main_view, i)
		g.Flush()
	}
}
Esempio n. 25
0
func updateAveragesView(g *gocui.Gui) {
	averages_view, _ := g.View("averages")
	for i := range averages_output {
		averages_view.Clear()
		fmt.Fprintln(averages_view, i)
		g.Flush()
	}
}
Esempio n. 26
0
func updateSparksView(g *gocui.Gui) {
	sparks_view, _ := g.View("sparks")
	for i := range sparks_output {
		sparks_view.Clear()
		fmt.Fprintln(sparks_view, i)
		g.Flush()
	}
}
Esempio n. 27
0
func (c *commentView) MoveDown(g *gocui.Gui) error {
	v, err := g.View(c.viewName())
	if err != nil {
		return err
	}
	x, y := v.Origin()
	v.SetOrigin(x, y+1)
	return nil
}
Esempio n. 28
0
func delMsg(g *gocui.Gui, v *gocui.View) error {
	if err := g.DeleteView("msg"); err != nil {
		return err
	}
	if _, err := g.SetCurrentView("side"); err != nil {
		return err
	}
	return nil
}
Esempio n. 29
0
func layout(g *gocui.Gui) error {
	if v, err := g.SetView("ctr", 2, 2, 12, 4); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
		fmt.Fprintln(v, "0")
	}
	return nil
}
Esempio n. 30
0
func hideMatched(g *gocui.Gui, v *gocui.View) error {
	if err := g.DeleteView("matched"); err != nil {
		return err
	}
	if err := g.SetCurrentView("background"); err != nil {
		return err
	}
	return nil
}