func setDetailLayout(g *gocui.Gui) error { maxX, maxY := g.Size() summaryView, err := g.View("summary") if err != nil { return err } _, cy := summaryView.Cursor() _, oy := summaryView.Origin() currentCveInfo = cy + oy if v, err := g.SetView("detail", 40, int(float64(maxY)*0.2), maxX, maxY); err != nil { if err != gocui.ErrUnknownView { return err } // text := report.ToPlainTextDetailsLangEn( // currentScanResult.KnownCves[currentCveInfo], // currentScanResult.Family) text, err := detailLines() if err != nil { return err } fmt.Fprint(v, text) v.Editable = false v.Wrap = true currentDetailLimitY = len(strings.Split(text, "\n")) - 1 } return nil }
func newView(g *gocui.Gui) error { maxX, maxY := g.Size() name := fmt.Sprintf("v%v", idxView) v, err := g.SetView(name, maxX/2-5, maxY/2-5, maxX/2+5, maxY/2+5) if err != nil { if err != gocui.ErrorUnkView { return err } v.Wrap = true fmt.Fprintln(v, strings.Repeat(name+" ", 30)) } if err := g.SetCurrentView(name); err != nil { return err } v.BgColor = gocui.ColorRed if curView >= 0 { cv, err := g.View(views[curView]) if err != nil { return err } cv.BgColor = g.BgColor } views = append(views, name) curView = len(views) - 1 idxView += 1 return nil }
func getLine(g *gocui.Gui, v *gocui.View) error { var l string var err error _, cy := v.Cursor() if l, err = v.Line(cy); err != nil { l = "" } maxX, maxY := g.Size() if v, err := g.SetView("msg", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil { if err != gocui.ErrorUnkView { return err } fmt.Fprintln(v, l) if err := g.SetCurrentView("msg"); err != nil { return err } } if v, err := g.View("main"); err != nil { if err != gocui.ErrorUnkView { return err } f := proj.GetFile(l) if f != nil { v.Clear() fmt.Fprintf(v, "%s", f.GetBody()) } v.Editable = true v.Wrap = true } 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 prevView(g *gocui.Gui, v *gocui.View) error { curView = getCurrentChannelIndex() next := curView - 1 if next < 0 { next = len(Server.Channels) - 1 } logger.Logger.Printf("PREV INDEX %d\n", next) if newView, err := g.View(Server.Channels[next].Name); err != nil { return err } else { newView.Autoscroll = true g.SetViewOnTop(newView.Name()) g.SetViewOnTop("header") } if _, err := g.SetCurrentView(Server.Channels[next].Name); err != nil { return err } // logger.Logger.Printf("Set Current View %d\n", Server.Channels[next].Name) Server.CurrentChannel = Server.Channels[next].Name Server.Channels[next].Unread = false ui.UpdateMenuView(g) FocusInputView(g, v) curView = next return nil }
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 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 nextView(g *gocui.Gui, v *gocui.View) error { if v == nil { return g.SetCurrentView(vPlatforms) } getLine(g, v) switch v.Name() { case vPlatforms: return g.SetCurrentView(vTranscripts) case vTranscripts: return g.SetCurrentView(vDestinations) case vDestinations: if x, err := g.View(vTop); err == nil { x.Clear() fmt.Fprintf(x, "Hit enter to submit selections") } return g.SetCurrentView(vSubmit) case vSubmit: return g.SetCurrentView(vText) case vText: return g.SetCurrentView(vPlatforms) } return g.SetCurrentView(vPlatforms) }
func setContacts(g *gocui.Gui, contacts map[string]*contact) error { if jidBuffs == nil { jidBuffs = make(map[string][]byte) } g.View("contacts").Clear() viewJids = make([]string, 1) viewJids[0] = "Home" for _, c := range contacts { if !c.HasAxo() { continue } viewJids = append(viewJids, c.String()) } sort.Strings(viewJids[1:]) for _, c := range viewJids { fmt.Fprintln(g.View("contacts"), c) } // Cleanup buffers for k, _ := range jidBuffs { if _, ok := contacts[k]; !ok { delete(jidBuffs, k) } } g.Flush() 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 nextView(g *gocui.Gui, disableCurrent bool) error { next := curView + 1 if next > len(views)-1 { next = 0 } nv, err := g.View(views[next]) if err != nil { return err } if err := g.SetCurrentView(views[next]); err != nil { return err } nv.BgColor = gocui.ColorRed if disableCurrent && len(views) > 1 { cv, err := g.View(views[curView]) if err != nil { return err } cv.BgColor = g.BgColor } curView = next 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 updateSparksView(g *gocui.Gui) { sparks_view, _ := g.View("sparks") for i := range sparks_output { sparks_view.Clear() fmt.Fprintln(sparks_view, i) g.Flush() } }
// 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 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 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 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 (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 setContact(g *gocui.Gui, v *gocui.View) error { _, cy := v.Cursor() jid := viewJids[cy] g.View("main").Clear() io.Copy(g.View("main"), bytes.NewReader(jidBuffs[jid])) g.SetCurrentView("input") return nil }
func update(columns []string, state *render.RenderState, g *gocui.Gui) { for _, column := range columns { v, _ := g.View(column) v.Clear() fmt.Fprintln(v, column) for _, row := range *state.Messages { fmt.Fprintln(v, row[column]) } } }
func updateTimeView(g *gocui.Gui) { for { time.Sleep(1 * time.Second) time_view, _ := g.View("time") time_view.Clear() fmt.Fprintln(time_view, "", time.Now().Local()) if err := g.Flush(); err != nil { return } } }
func getSelectedChannelName(g *gocui.Gui) (string, error) { v, err := g.View("channels") if err != nil { return "", err } _, cy := v.Cursor() name, err := v.Line(cy) if err != nil { return "", err } return name, nil }
func updateLogDumpView(g *gocui.Gui) { logdump_view, _ := g.View("logdump_view") flush := time.Tick(update_logdump_frequency * time.Millisecond) for { select { case log_data := <-logdump_output: fmt.Fprintln(logdump_view, log_data) case <-flush: g.Flush() } } }
func (c *commentView) MoveUp(g *gocui.Gui) error { v, err := g.View(c.viewName()) if err != nil { return err } x, y := v.Origin() if y == 0 { return nil } v.SetOrigin(x, y-1) return nil }
func reloadTubes(g *gocui.Gui) error { v, err := g.View("tubes") if err != nil { return err } //Clear the current tube list v.Clear() //Print the new tube list PrintTubeList(v) //Refresh the cursor return RefreshCursor(g) }
func cmd(g *ui.Gui, v *ui.View) error { _, cur := v.Cursor() current = "node" cmdTokens = []rune{} var err error nv, err := g.View("node") if err != nil { return err } cmdMode = true if err := cli.Connect(cur, update); err != nil { return err } return nv.SetCursor(0, 0) }
func send(g *gocui.Gui, v *gocui.View) error { v.SetOrigin(0, 0) message, err := v.Line(0) if err != nil { // We pressed enter and there's no text. Do nothing return nil } v.Clear() message = strings.Replace(message, string(0x00), "", -1) // Remove trailing 0x00 if strings.TrimSpace(message) == "" { return nil } contacts := g.View("contacts") _, cy := contacts.Cursor() contact, err := contacts.Line(cy) if err != nil { return err } if message[0] == '/' { spl := strings.Split(message[1:], " ") if len(spl) == 0 { return nil } switch spl[0] { case "q": fallthrough case "quit": return gocui.ErrorQuit default: display(g, contact, fmt.Sprintf("! Unknown command: %#v", message)) } } else { contacts := g.View("contacts") _, cy := contacts.Cursor() contact, err := contacts.Line(cy) if err != nil { return err } if contact != "Home" { displayTimestamped(g, contact, message) sendMessage(contact, message) } } return nil }
func updateAlertsView(g *gocui.Gui) { alerts_view, _ := g.View("alerts") for { select { case alert_text := <-alerts_output: fmt.Fprintln(alerts_view, alert_text) g.Flush() case alert_state := <-alert_state_chan: if alert_state { alerts_view.BgColor = gocui.ColorRed } else { alerts_view.BgColor = gocui.ColorDefault } g.Flush() } } }
func RefreshCursor(g *gocui.Gui) error { tv, err := g.View("tubes") if err != nil { return err } _, cy := tv.Cursor() if cy > len(cTubes.Conns) { debugLog("Resetting cursor position ", cy, " to ", len(cTubes.Conns)) //Temporary fix for the cursor dropping off the bottom of the list if err = tv.SetCursor(0, len(cTubes.Conns)); err != nil { return err } } return nil }
func printNode(g *ui.Gui) { v, _ := g.View("node") cv, _ := g.View("nodes-cursor") v.Clear() _, cur := cv.Cursor() n := cli.Nodes[cur] f := colors["color2"] i := 1 links = [][]string{} var keys []string for key := range n.Devices { keys = append(keys, key) } sort.Strings(keys) for _, key := range keys { f(v, fmt.Sprintf(" %s", key)) loc := n.Devices[key] var names []string for name := range loc { names = append(names, name) } sort.Strings(names) for _, name := range names { val := loc[name] if val.Value.Value == nil { continue } var l string l, i = getLink(val, i) f(v, fmt.Sprintf(" %s: %s %s", name, getVal(val.Value), l)) if l != "" { v, ok := val.Value.Value.(bool) if ok && v { links = append(links, val.Info.Off) } else { links = append(links, val.Info.On) } } } } }