Exemple #1
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
}
Exemple #2
0
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
}
Exemple #3
0
func Handle(
	stdHandler *std.StdHandler,
	travianHandler *travian.TravianHandler,
	trav *travian.Game,
	ui *console.GUI,
	v *gocui.View) error {

	command := strings.Trim(v.Buffer(), "\n\r ")

	parsedCmd, _ := shellwords.Parse(command)

	if len(command) == 0 {
		return nil
	}

	if exists := stdHandler.Handle(parsedCmd, ui); exists {

	} else if exists := travianHandler.Handle(parsedCmd, trav, ui); exists {

	} else {
		ui.Println("Command not found")
	}

	v.Clear() // clears input view's input buffer

	return nil
}
Exemple #4
0
func saveMain(g *gocui.Gui, v *gocui.View) error {
	f, err := ioutil.TempFile("", "gocui_demo_")
	if err != nil {
		return err
	}
	defer f.Close()

	p := make([]byte, 5)
	v.Rewind()
	for {
		n, err := v.Read(p)
		if n > 0 {
			if _, err := f.Write(p[:n]); err != nil {
				return err
			}
		}
		if err == io.EOF {
			break
		}
		if err != nil {
			return err
		}
	}
	return nil
}
Exemple #5
0
func removeTrackCommand(g *gocui.Gui, v *gocui.View) error {
	switch v.Name() {
	case VIEW_PLAYLISTS:
		if playlist := gui.getSelectedPlaylist(); playlist != nil {
			playlists.Remove(playlist.Name())
			gui.updatePlaylistsView()
			gui.updateTracksView()
		}
	case VIEW_TRACKS:
		if playlist, index := gui.getSelectedPlaylistAndTrack(); index > -1 {
			for i := 1; i <= getOffsetFromTypedNumbers(); i++ {
				playlist.RemoveTrack(index)
			}
			gui.updateTracksView()
			goTo(g, v, index+1)
		}
	case VIEW_QUEUE:
		if index := gui.getQueueSelectedTrackIndex(); index > -1 {
			for i := 1; i <= getOffsetFromTypedNumbers(); i++ {
				if queue.Remove(index) != nil {
					continue
				}
			}
			gui.updateQueueView()
		}
	}
	return nil
}
Exemple #6
0
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
}
Exemple #7
0
func PrintTubeList(v *gocui.View) {
	line := fmt.Sprintf("%-35s %-22s %-22s", "Tube", "ready/delayed/buried", "waiting/watching/using")
	fmt.Fprintln(v, line)

	//Reload the tube stats - will detect new tubes and drop removed tubes
	cTubes.UseAll()

	//Calculate the size for paging
	_, vy := v.Size()
	cTubes.Pages = int(math.Ceil(float64(len(cTubes.Conns)) / float64(vy-1)))
	offset := vy * (cTubes.Page - 1)
	limit := vy * cTubes.Page
	if limit > len(cTubes.Conns) {
		limit = len(cTubes.Conns)
	}
	displayed := cTubes.Conns[offset:limit]

	for _, tube := range displayed {
		stats, _ := tube.Stats()
		jobStats := stats["current-jobs-ready"] + " / " + stats["current-jobs-delayed"] + " / " + stats["current-jobs-buried"]
		workerStats := stats["current-waiting"] + " / " + stats["current-watching"] + " / " + stats["current-using"]
		line := fmt.Sprintf("%-35s %-22s %-22s", tube.Name, jobStats, workerStats)
		fmt.Fprintln(v, line)
	}
}
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)
}
Exemple #9
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)
}
Exemple #10
0
func (self *stack) draw(v *gocui.View, refresh bool) {
	if refresh {
		self.written = false
	}

	if self.written {
		return
	}

	v.Clear()

	self.sx, self.sy = v.Size()

	blob := self.contents[self.bump:]

	for off, b := range blob {
		cur := self.lastaddr + uint16(off) + uint16(self.bump)
		if off%2 == 0 {
			if cur == self.lastsp {
				fmt.Fprintf(v, "%0.4x:>>    ", cur)
			} else {
				fmt.Fprintf(v, "%0.4x:      ", cur)
			}

			fmt.Fprintf(v, "%0.2x", b)
		} else {
			fmt.Fprintf(v, "%0.2x\n", b)
		}
	}

	self.written = true
}
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
}
Exemple #12
0
func cursorMoveTop(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		cx, _ := v.Cursor()
		v.SetCursor(cx, 0)
	}
	onMovingCursorRedrawView(g, v)
	return nil
}
Exemple #13
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
}
Exemple #14
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
}
Exemple #15
0
func (runner *appRunner) confirmStringDetail(gui *gocui.Gui, view *gocui.View) error {
	text := strings.TrimSpace(view.Buffer())

	runner.activeStringDetailController.Confirm(text)
	runner.restoreMainView()
	runner.gui.DeleteView(view.Name())
	return nil
}
func platformsMenuDown(g *gocui.Gui, v *gocui.View) error {
	length := 3
	_, cy := v.Cursor()
	_, oy := v.Origin()
	if cy+oy < length-1 {
		return menuDown(g, v)
	}
	return nil
}
func transcriptsMenuDown(g *gocui.Gui, v *gocui.View) error {
	length := 5
	_, cy := v.Cursor()
	_, oy := v.Origin()
	if cy+oy < length-1 {
		return menuDown(g, v)
	}
	return nil
}
func destinationsMenuDown(g *gocui.Gui, v *gocui.View) error {
	length := 9
	_, cy := v.Cursor()
	_, oy := v.Origin()
	if cy+oy < length-1 {
		return menuDown(g, v)
	}
	return nil
}
Exemple #19
0
func next(g *ui.Gui, v *ui.View) error {
	cx, cy := v.Cursor()
	if cy+1 >= len(cli.Nodes) {
		return nil
	}
	err := v.SetCursor(cx, cy+1)
	printNodes()
	printNode(g)
	return err
}
Exemple #20
0
func FocusInputView(g *gocui.Gui, v *gocui.View) error {

	v.SetCursor(len(v.Buffer()+"")-1, 0)

	if _, err := g.SetCurrentView("input"); err != nil {
		return err
	}

	return nil
}
Exemple #21
0
func prev(g *ui.Gui, v *ui.View) error {
	cx, cy := v.Cursor()
	if cy-1 < 0 {
		return nil
	}
	err := v.SetCursor(cx, cy-1)
	printNodes()
	printNode(g)
	return err
}
Exemple #22
0
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
}
Exemple #23
0
func scrollView(v *gocui.View, dy int) error {
	if v != nil {
		v.Autoscroll = false
		ox, oy := v.Origin()
		if err := v.SetOrigin(ox, oy+dy); err != nil {
			return err
		}
	}
	return nil
}
Exemple #24
0
func (self *tabbar) renderBar(v *gocui.View) {
	v.Clear()

	for i, vs := range self.options {
		if i == self.selected {
			fmt.Fprintf(v, " [%s]", strings.ToUpper(vs))
		} else {
			fmt.Fprintf(v, " %s", vs)
		}
	}
}
Exemple #25
0
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
}
Exemple #26
0
func (gui *Gui) getSelected(v *gocui.View) (string, error) {
	var l string
	var err error

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

	return l, err
}
Exemple #27
0
func cursorRight(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		cx, cy := v.Cursor()
		if err := v.SetCursor(cx+1, cy); err != nil {
			/*ox, oy := v.Origin()
			if err := v.SetOrigin(ox+1, oy); err != nil {
				return err
			}*/
		}
	}
	return nil
}
Exemple #28
0
func pageUpDownJumpCount(v *gocui.View) int {
	var jump int
	switch v.Name() {
	case "side", "summary":
		jump = 8
	case "detail":
		jump = 30
	default:
		jump = 8
	}
	return jump
}
Exemple #29
0
func saveVisualMain(g *gocui.Gui, v *gocui.View) error {
	f, err := ioutil.TempFile("", "gocui_demo_")
	if err != nil {
		return err
	}
	defer f.Close()

	vb := v.ViewBuffer()
	if _, err := io.Copy(f, strings.NewReader(vb)); err != nil {
		return err
	}
	return nil
}
Exemple #30
0
// redraw views
func onMovingCursorRedrawView(g *gocui.Gui, v *gocui.View) error {
	switch v.Name() {
	case "summary":
		if err := redrawDetail(g); err != nil {
			return err
		}
	case "side":
		if err := changeHost(g, v); err != nil {
			return err
		}
	}
	return nil
}