Ejemplo n.º 1
0
Archivo: tui.go Proyecto: Rompei/vuls
func cursorPageDown(g *gocui.Gui, v *gocui.View) error {
	jump := pageUpDownJumpCount(v)

	if v != nil {
		cx, cy := v.Cursor()
		ox, oy := v.Origin()
		ok, yLimit := movable(v, oy+cy+jump)
		_, maxY := v.Size()

		if !ok {
			if yLimit < maxY {
				v.SetCursor(cx, yLimit)
			} else {
				v.SetCursor(cx, maxY-1)
				v.SetOrigin(ox, yLimit-maxY+1)
			}
		} else if yLimit < oy+jump+maxY {
			if yLimit < maxY {
				v.SetCursor(cx, yLimit)
			} else {
				v.SetOrigin(ox, yLimit-maxY+1)
				v.SetCursor(cx, maxY-1)
			}
		} else {
			v.SetCursor(cx, cy)
			v.SetOrigin(ox, oy+jump)
		}
		onMovingCursorRedrawView(g, v)
	}
	return nil
}
Ejemplo n.º 2
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
}
Ejemplo n.º 3
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)
	}
}
Ejemplo n.º 4
0
Archivo: tui.go Proyecto: Rompei/vuls
func cursorMoveMiddle(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		_, maxY := v.Size()
		cx, _ := v.Cursor()
		v.SetCursor(cx, maxY/2)
	}
	onMovingCursorRedrawView(g, v)
	return nil
}
Ejemplo n.º 5
0
// draw a simple hex dump, filling available space
func (self *dump) draw(v *gocui.View, refresh bool) {
	if refresh {
		self.written = false
	}

	if self.written {
		return
	}

	v.Clear()

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

	xpos := 0
	ypos := 0

	p, _ := fmt.Fprintf(v, "%0.4X:   ", self.addr)
	xpos += p
	bytesThisLine := 1

	for off, b := range self.contents {
		need := 3
		pad := " "
		if bytesThisLine != 1 && bytesThisLine%4 == 0 {
			need += 2
			pad = "   "
		}
		if xpos < (self.sx - need) {
			bytesThisLine++
			p, _ = fmt.Fprintf(v, "%.2x%s", b, pad)
			xpos += p
		} else {
			xpos = 0
			bytesThisLine = 2
			ypos += 1

			v.Write([]byte("\n"))

			if ypos == self.sy {
				break
			}

			p, _ = fmt.Fprintf(v, "%0.4X:   %0.2x ", self.addr+uint16(off), b)
			xpos += p
		}
	}

	v.Write([]byte("\n"))

	self.written = true
}
Ejemplo n.º 6
0
func cursorPgup(g *gocui.Gui, v *gocui.View) error {
	ox, oy := v.Origin()
	cx, cy := v.Cursor()
	_, pageSizeY := v.Size()
	pageSizeY--

	if newOriginY := oy - pageSizeY; newOriginY > 0 {
		v.SetOrigin(ox, newOriginY)
		v.SetCursor(cx, cy)
	} else {
		v.SetOrigin(ox, 0)
		v.SetCursor(cx, cy)
	}
	updateTracksView(g, v)
	return nil
}
Ejemplo n.º 7
0
func cursorEnd(g *gocui.Gui, v *gocui.View) error {
	if newIndex := getCurrentViewSize(v); newIndex > -1 {
		ox, _ := v.Origin()
		cx, _ := v.Cursor()
		_, sizeY := v.Size()
		sizeY--

		if newIndex > sizeY {
			v.SetOrigin(ox, newIndex-sizeY)
			v.SetCursor(cx, sizeY)
		} else {
			v.SetCursor(cx, newIndex)
		}

		updateTracksView(g, v)
	}
	return nil
}
Ejemplo n.º 8
0
func cursorPgdn(g *gocui.Gui, v *gocui.View) error {
	if maxSize := getCurrentViewSize(v); maxSize > -1 {
		ox, oy := v.Origin()
		cx, cy := v.Cursor()
		_, pageSizeY := v.Size()
		pageSizeY--

		newOriginY := oy + pageSizeY

		if hasMorePages(newOriginY, cy, maxSize) {
			v.SetOrigin(ox, newOriginY)
			v.SetCursor(cx, cy)
		} else if isNotInLastPage(oy, pageSizeY, maxSize) {
			v.SetOrigin(ox, maxSize-pageSizeY)
			v.SetCursor(cx, pageSizeY)
		}
		updateTracksView(g, v)
	}
	return nil
}
Ejemplo n.º 9
0
Archivo: tui.go Proyecto: Rompei/vuls
func showMsg(g *gocui.Gui, v *gocui.View) error {
	jump := 8
	_, cy := v.Cursor()
	_, oy := v.Origin()
	ok, yLimit := movable(v, oy+cy+jump)
	//  maxX, maxY := v.Size()
	_, maxY := v.Size()

	l := fmt.Sprintf("cy: %d, oy: %d, maxY: %d, yLimit: %d, curCve %d, ok: %v", cy, oy, maxY, yLimit, currentCveInfo, ok)
	//  if v, err := g.SetView("msg", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
	if v, err := g.SetView("msg", 10, maxY/2, 10+50, maxY/2+2); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
		fmt.Fprintln(v, l)
		if err := g.SetCurrentView("msg"); err != nil {
			return err
		}
	}
	return nil
}