github.com/xyproto/orbiton/v2@v2.65.12-0.20240516144430-e10a419274ec/progress.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/xyproto/vt100"
     5  )
     6  
     7  // DrawProgress draws a small progress indicator on the right hand side
     8  func (e *Editor) DrawProgress(c *vt100.Canvas) {
     9  	var (
    10  		canvasWidth   = c.Width()
    11  		canvasHeight  = float64(c.Height())
    12  		lineNumberTop = float64(e.LineIndex())
    13  		allLines      = float64(e.Len())
    14  		x             = canvasWidth - 1
    15  		y             = canvasHeight - 1
    16  	)
    17  	if allLines > 0 {
    18  		y = (canvasHeight * lineNumberTop * (allLines + canvasHeight)) / (allLines * allLines)
    19  	}
    20  	if x >= canvasWidth {
    21  		x = canvasWidth - 1
    22  	}
    23  	if y >= canvasHeight {
    24  		y = canvasHeight - 1
    25  	}
    26  	c.WriteBackground(x, uint(y), e.MenuArrowColor.Background())
    27  	c.Draw()
    28  }