func setLayout(g *gocui.Gui) error { maxX, maxY := g.Size() if v, err := g.SetView("tubes", 0, 0, maxX-1, maxY-3); err != nil { if err != gocui.ErrUnknownView { return err } //Initialise the view settings v.Highlight = true v.Wrap = true v.Editable = false v.Autoscroll = false PrintTubeList(v) //Move the cursor to the first tube if err = MoveTubeCursor(g, 0, 1); err != nil { return err } } if v, err := g.SetView("menu", 0, maxY-3, maxX-1, maxY-1); err != nil { if err != gocui.ErrUnknownView { return err } PrintMenu(v) } 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 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 layout(g *gocui.Gui) error { maxX, _ := g.Size() if v, err := g.SetView("legend", maxX-23, 0, maxX-1, 5); err != nil { if err != gocui.ErrUnknownView { return err } fmt.Fprintln(v, "KEYBINDINGS") fmt.Fprintln(v, "↑ ↓: Seek input") fmt.Fprintln(v, "A: Enable autoscroll") fmt.Fprintln(v, "^C: Exit") } if v, err := g.SetView("stdin", 0, 0, 80, 35); err != nil { if err != gocui.ErrUnknownView { return err } if _, err := g.SetCurrentView("stdin"); err != nil { return err } dumper := hex.Dumper(v) if _, err := io.Copy(dumper, os.Stdin); err != nil { return err } v.Wrap = true } return nil }
func layout(g *gocui.Gui) error { maxX, maxY := g.Size() // main if v, err := g.SetView("main", -1, -1, maxX, maxY); err != nil { if err != gocui.ErrorUnkView { return err } v.Wrap = true v.Autoscroll = true } // key bindings if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quitKey); err != nil { return err } // stats once.Do(func() { go func() { ticker := time.NewTicker(time.Second) for { select { case <-ticker.C: showUpdate() case <-stopChan: return } } }() }) return nil }
func layout(g *gocui.Gui) error { maxX, maxY := g.Size() if v, err := g.SetView("help", maxX-23, 0, maxX-1, 3); err != nil { if err != gocui.ErrUnknownView { return err } v.Title = "Keybindings" fmt.Fprintln(v, "^a: Set mask") fmt.Fprintln(v, "^c: Exit") } if v, err := g.SetView("input", 0, 0, maxX-24, maxY-1); err != nil { if err != gocui.ErrUnknownView { return err } if _, err := g.SetCurrentView("input"); err != nil { return err } v.Editable = true v.Wrap = true } 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 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 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 codeComplete(g *gocui.Gui, v *gocui.View) error { if v != nil { ox, oy := v.Origin() cx, cy := v.Cursor() x, y := ox+cx, oy+cy f := proj.GetFile("test.go") off := f.GetOffset(x, y) cands := codecomplete.Complete(proj, f, off) maxX, maxY := g.Size() maxY = maxY/2 - (len(cands) / 2) if v, err := g.SetView("msg", maxX/2-30, maxY, maxX/2+30, maxY+len(cands)+2); err != nil { if err != gocui.ErrorUnkView { return err } fmt.Fprintln(v, x, y, off) for _, c := range cands { fmt.Fprintln(v, c.Name, c.Perc) } if err := g.SetCurrentView("msg"); err != nil { return err } } } 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 layout(g *gocui.Gui) error { maxX, maxY := g.Size() if v, err := g.SetView("side", -1, -1, 30, maxY); err != nil { if err != gocui.ErrorUnkView { return err } v.Highlight = true list := proj.GetFileList() for _, f := range list { fmt.Fprintln(v, filepath.Base(f.GetPath())) } } if v, err := g.SetView("main", 30, -1, maxX, maxY); err != nil { if err != gocui.ErrorUnkView { return err } f := proj.GetFile("test.go") if f != nil { fmt.Fprintf(v, "%s", f.GetBody()) } v.Editable = true v.Wrap = false if err := g.SetCurrentView("main"); err != nil { return err } } return nil }
func layout(g *gocui.Gui) error { var err error maxX, maxY := g.Size() if backgroundView, err = g.SetView("background", 0, 0, maxX, maxY); err != nil { if err != gocui.ErrorUnkView { return err } } if profilePictureView, err = g.SetView("profilePicture", 1, 1, maxX-1, maxY-5); err != nil { if err != gocui.ErrorUnkView { return err } profilePictureView.Wrap = true fmt.Fprintln(profilePictureView, "Loading...") } if swipeLeftView, err = g.SetView("swipeLeft", 6, maxY-4, maxX/2-5, maxY-1); err != nil { if err != gocui.ErrorUnkView { return err } fmt.Fprintln(swipeLeftView, "X") } if swipeRightView, err = g.SetView("swipeRight", maxX-(maxX/2-5), maxY-4, maxX-6, maxY-1); err != nil { if err != gocui.ErrorUnkView { return err } fmt.Fprintln(swipeRightView, "<3") } if infoView, err = g.SetView("info", maxX/2-4, maxY-4, maxX/2+4, maxY-1); err != nil { if err != gocui.ErrorUnkView { return err } fmt.Fprintln(infoView, "i") } 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 (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 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 *gocui.Gui) error { theSizeX, theSizeY := 12, 6 maxX, maxY := g.Size() centerX, centerY := maxX/2, maxY/2 topLeftX, topLeftY := centerX-theSizeX, centerY-theSizeY bottomRightX, bottomRightY := centerX+theSizeX, centerY+theSizeY if v, err := g.SetView("yo", topLeftX, topLeftY, bottomRightX, bottomRightY); err != nil { if err != gocui.ErrUnknownView { return err } v.Editable = true v.Wrap = true fmt.Fprintln(v, " 1 2 3 | 4 5 6 | 7 8 9") fmt.Fprintln(v, " 1 2 3 | 4 5 6 | 7 8 9") fmt.Fprintln(v, " 1 2 3 | 4 5 6 | 7 8 9") fmt.Fprintln(v, " ---------------------") fmt.Fprintln(v, " 1 2 3 | 4 5 6 | 7 8 9") fmt.Fprintln(v, " 1 2 3 | 4 5 6 | 7 8 9") fmt.Fprintln(v, " 1 2 3 | 4 5 6 | 7 8 9") fmt.Fprintln(v, " ---------------------") fmt.Fprintln(v, " 1 2 3 | 4 5 6 | 7 8 9") fmt.Fprintln(v, " 1 2 3 | 4 5 6 | 7 8 9") fmt.Fprintln(v, " 1 2 3 | 4 5 6 | 7 8 9") } if err := g.SetCurrentView("yo"); err != nil { return err } return nil }
func layout(g *gocui.Gui) error { maxX, maxY := g.Size() if v, err := g.SetView("side", -1, -1, 30, maxY); err != nil { if err != gocui.ErrorUnkView { return err } v.Highlight = true fmt.Fprintln(v, "Item 1") fmt.Fprintln(v, "Item 2") fmt.Fprintln(v, "Item 3") fmt.Fprintln(v, "Item 4") } if v, err := g.SetView("main", 30, -1, maxX, maxY); err != nil { if err != gocui.ErrorUnkView { return err } b, err := ioutil.ReadFile("Mark.Twain-Tom.Sawyer.txt") if err != nil { panic(err) } fmt.Fprintf(v, "%s", b) v.Editable = true if err := g.SetCurrentView("main"); 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 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 layout(g *gocui.Gui) error { maxX, maxY := g.Size() if v, err := g.SetView("side", -1, -1, 30, maxY); err != nil { if err != gocui.ErrUnknownView { return err } v.Highlight = true v.SelBgColor = gocui.ColorGreen v.SelFgColor = gocui.ColorBlack fmt.Fprintln(v, "Item 1") fmt.Fprintln(v, "Item 2") fmt.Fprintln(v, "Item 3") fmt.Fprint(v, "\rWill be") fmt.Fprint(v, "deleted\rItem 4\nItem 5") } if v, err := g.SetView("main", 30, -1, maxX, maxY); err != nil { if err != gocui.ErrUnknownView { return err } b, err := ioutil.ReadFile("Mark.Twain-Tom.Sawyer.txt") if err != nil { panic(err) } fmt.Fprintf(v, "%s", b) v.Editable = true v.Wrap = true if _, err := g.SetCurrentView("main"); 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 layout(g *gocui.Gui) error { maxX, maxY := g.Size() if _, err := g.SetView("main", -1, -1, maxX, maxY); err != nil { if err := g.SetCurrentView("main"); err != nil { return err } } return nil }
func layout(g *gocui.Gui) error { maxX, maxY := g.Size() if v, err := g.SetView("hello", maxX/2-7, maxY/2, maxX/2+7, maxY/2+2); err != nil { if err != gocui.ErrUnknownView { return err } fmt.Fprintln(v, "Hello world!") } return nil }
func layout(g *gocui.Gui) error { maxX, maxY := g.Size() if v, err := g.SetView("center", maxX/2-10, maxY/2, maxX/2+10, maxY/2+2); err != nil { if err != gocui.ErrUnknownView { return err } fmt.Fprintln(v, "This is an example") } return nil }
func (w *Label) Layout(g *gocui.Gui) error { v, err := g.SetView(w.name, 0, 0, w.w, w.h) if err != nil { if err != gocui.ErrUnknownView { return err } fmt.Fprint(v, w.body) } return nil }
func (w *HelpWidget) Layout(g *gocui.Gui) error { v, err := g.SetView(w.name, w.x, w.y, w.x+w.w, w.y+w.h) if err != nil { if err != gocui.ErrUnknownView { return err } fmt.Fprint(v, w.body) } return nil }
func layout(g *gocui.Gui) error { maxX, maxY := g.Size() if v, err := g.SetView("info", maxX-53, 9, maxX-1, maxY-4); err != nil { if err != gocui.ErrorUnkView { return err } fmt.Fprintln(v, " PROJECT INFORMATION") } if v, err := g.SetView("list", 0, 1, maxX-54, maxY-1); err != nil { if err != gocui.ErrorUnkView { return err } v.Highlight = true for k, _ := range projects { fmt.Fprintln(v, k) } setView(g, "list") if l := len(projects); l != 0 { _, cy := v.Cursor() if current_name, err = v.Line(cy); err != nil { current_name = "" } updateProjInfo(g, v) } } if v, err := g.SetView("legend", maxX-53, 1, maxX-1, 8); err != nil { if err != gocui.ErrorUnkView { return err } fmt.Fprintln(v, " KEYBINDINGS") fmt.Fprintln(v, " A: Add new project") fmt.Fprintln(v, " D: Delete a project") fmt.Fprintln(v, " Enter: Activate a project") fmt.Fprintln(v, " ^C: Exit") } if v, err := g.SetView("label", maxX-53, maxY-3, maxX-1, maxY-1); err != nil { if err != gocui.ErrorUnkView { return err } fmt.Fprintln(v, " This is go-watch -- a time tracker") } if v, err := g.SetView("listlabel", 0, -1, 20, 1); err != nil { if err != gocui.ErrorUnkView { return err } fmt.Fprintln(v, "LIST OF PROJECTS") v.Frame = false } return nil }
func moveView(g *gocui.Gui, v *gocui.View, dx, dy int) error { name := v.Name() x0, y0, x1, y1, err := g.ViewPosition(name) if err != nil { return err } if _, err := g.SetView(name, x0+dx, y0+dy, x1+dx, y1+dy); err != nil { return err } return nil }
func (w *StatusbarWidget) Layout(g *gocui.Gui) error { v, err := g.SetView(w.name, w.x, w.y, w.x+w.w, w.y+2) if err != nil && err != gocui.ErrUnknownView { return err } v.Clear() rep := int(w.val * float64(w.w-1)) fmt.Fprint(v, strings.Repeat("▒", rep)) return nil }