1package diffview
 2
 3import (
 4	"fmt"
 5	"strings"
 6
 7	"github.com/charmbracelet/x/ansi"
 8)
 9
10func pad(v any, width int) string {
11	s := fmt.Sprintf("%v", v)
12	w := ansi.StringWidth(s)
13	if w >= width {
14		return s
15	}
16	return strings.Repeat(" ", width-w) + s
17}
18
19func isEven(n int) bool {
20	return n%2 == 0
21}
22
23func isOdd(n int) bool {
24	return !isEven(n)
25}
26
27func btoi(b bool) int {
28	if b {
29		return 1
30	}
31	return 0
32}
33
34func ternary[T any](cond bool, t, f T) T {
35	if cond {
36		return t
37	}
38	return f
39}