k9s/internal/dao/helpers.go

21 lines
411 B
Go

package dao
import (
"math"
"github.com/derailed/tview"
runewidth "github.com/mattn/go-runewidth"
)
func toPerc(v1, v2 float64) float64 {
if v2 == 0 {
return 0
}
return math.Round((v1 / v2) * 100)
}
// Truncate a string to the given l and suffix ellipsis if needed.
func Truncate(str string, width int) string {
return runewidth.Truncate(str, width, string(tview.SemigraphicsHorizontalEllipsis))
}