-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (52 loc) · 1.06 KB
/
main.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"time"
"github.com/charmbracelet/lipgloss"
"github.com/mattn/go-isatty"
"github.com/muesli/termenv"
)
func main() {
rand.Seed(time.Now().UnixMilli())
var isPiped bool = false
vars, beginText := parseFlags(os.Args, newVars())
if !isatty.IsTerminal(os.Stdin.Fd()) {
isPiped = true
}
if vars.forceColor || isatty.IsTerminal(os.Stdout.Fd()) {
lipgloss.SetColorProfile(termenv.TrueColor)
}
if !isPiped && len(os.Args) < 2 {
interactive(vars)
quit()
}
// print rainbow bar
if !isPiped && os.Args[1] == "--bar" {
var barCount int64 = 1
if len(os.Args) > 2 {
barCount, _ = strconv.ParseInt(os.Args[2], 10, 64)
}
if barCount < 1 {
barCount = 1
}
fmt.Println(bar(vars, int(barCount)))
quit()
}
if isPiped {
rainbowPipe(vars)
} else {
str := strings.Join(os.Args[beginText:], " ")
fmt.Print(rainbow(str, 0, vars))
}
quit()
}
// pro tip: its rude to break peoples tty's
func quit() {
lipgloss.DefaultRenderer().Output().Reset()
fmt.Println("")
os.Exit(0)
}