File size: 480 Bytes
8ab4ccd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
package diffview

import (
	"fmt"
	"strings"

	"github.com/charmbracelet/x/ansi"
)

func pad(v any, width int) string {
	s := fmt.Sprintf("%v", v)
	w := ansi.StringWidth(s)
	if w >= width {
		return s
	}
	return strings.Repeat(" ", width-w) + s
}

func isEven(n int) bool {
	return n%2 == 0
}

func isOdd(n int) bool {
	return !isEven(n)
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func ternary[T any](cond bool, t, f T) T {
	if cond {
		return t
	}
	return f
}