forked from emprcl/runal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
45 lines (37 loc) · 768 Bytes
/
util.go
File metadata and controls
45 lines (37 loc) · 768 Bytes
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
41
42
43
44
45
package runal
import (
"os"
"strings"
"github.com/charmbracelet/log"
"golang.org/x/term"
)
func termSize() (int, int) {
w, h, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil {
log.Fatal("can't read terminal size")
}
return w, h
}
func forcePadding(s *strings.Builder, sLength, tLength int, padChar rune) {
if sLength >= tLength {
return
}
padding := strings.Repeat(string(padChar), tLength-sLength)
s.WriteString(padding)
}
func absInt(a int) int {
if a < 0 {
return -a
}
return a
}
func strIndex(str string, index int) rune {
return rune(str[index%len(str)])
}
func randomDir() string {
tmp, err := os.MkdirTemp(os.TempDir(), "runal")
if err != nil {
log.Fatalf("error creating temporary directory: %v", err)
}
return tmp
}