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 }
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 }
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 }
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 }
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 }
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 }) }
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 }) }
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 }
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 }
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 }
func delView(g *gocui.Gui, s string) error { if err := g.DeleteView(s); err != nil { return err } return nil }
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 }
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) }
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 }
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) }
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 }) } } }
func setView(g *gocui.Gui, s string) error { if err := g.SetCurrentView(s); err != nil { return err } return nil }
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 }
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 }
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 }
// 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() } }
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 }
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 }
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() } }
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() } }
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() } }
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 }
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 }
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 }
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 }