summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/cjbassi/termui/utils.go
blob: 614828bc6f18261bdead370177d7bcbcdf372fbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package termui

import (
	"fmt"
	"math"
)

const DOTS = '…'

// MaxString trims a string and adds dots if the string is longer than a give length.
func MaxString(s string, l int) string {
	if l <= 0 {
		return ""
	}
	r := []rune(s)
	if len(r) > l {
		r = r[:l]
		r[l-1] = DOTS
	}
	return string(r)
}

func Round(f float64) float64 {
	return math.Floor(f + .5)
}

func Error(issue, diagnostics string) {
	Close()
	fmt.Println("Error caught. Exiting program.")
	fmt.Println()
	fmt.Println("Issue with " + issue + ".")
	fmt.Println()
	fmt.Println("Diagnostics:\n" + diagnostics)
	fmt.Println()
	panic(1)
}