This repository has been archived by the owner on Oct 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
162 lines (137 loc) · 3.41 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"fmt"
"strings"
"strconv"
"math/rand"
"time"
"os"
flag "github.com/spf13/pflag"
ts "github.com/geremachek/tinyscr"
fu "przm/funcs"
)
const help = `Usage: przm [OPTION] [COLOR]
A simple, yet feature rich color picker and manipulator
--help, -h: Display this information
--rgb, -r: Return the color in the RGB format
--hex, -x: Return the color in the hexadecimal format
--output, -o: Don't clean up the output
--foreground, -f: Color the text foreground
--background, -b: Color the text background
h: Increment the 'R' value
j: Increment the 'G' value
k: Increment the 'B' value
l: Increment all values (brightens the color)
b: Decrement the 'R' value
n: Decrement the 'G' value
m: Decrement the 'B' value
,: Decrement all values (dims the color)
H: Randomly set the 'R' value
J: Randomly set the 'G' value
K: Randomly set the 'B' value
L: Randomly set all values
[space]: Sets the color to black
q: Exit the program
[number]: Set the increment to [number] (0 = 10)`
func main() {
var (
ch rune
olen int
r, g, b int
inc int = 1
)
if len(os.Args) == 2 {
if os.Args[1] == "-h" || os.Args[1] == "--help" {
fmt.Println(help)
return
}
}
printRGB := flag.BoolP("rgb", "r", false, "Return the color in the RGB format")
printHex := flag.BoolP("hex", "x", false, "Return the color in the hexadecimal format")
printOutput := flag.BoolP("output", "o", false, "Don't clean up the output")
ColorForeground := flag.BoolP("foreground", "f", false, "Color the text foreground")
ColorBackground := flag.BoolP("background", "b", false, "Color the text background")
flag.Parse()
ts.HideCursor()
args := flag.Args()
rand.Seed(time.Now().UnixNano())
if len(args) == 1 {
// hsl, rgb, etc later.
if rune(args[0][0]) == '#' {
r, g, b = fu.GetRGB(args[0][1:])
} else {
r, g, b = fu.GetRGB(args[0])
}
}
for {
if *ColorForeground {
olen = fu.PrintInfo("fore", r, g, b)
} else if *ColorBackground {
olen = fu.PrintInfo("back", r, g, b)
} else {
olen = fu.PrintInfo("normal", r, g, b)
}
var err error
ch, err = ts.Getch()
if err != nil {
ch = 'q'
}
if ch == 'q' {
if *printOutput {
} else {
fmt.Print("\r" + strings.Repeat(" ", olen) + "\r")
if *printRGB {
fmt.Print("rgb(" + strconv.Itoa(r) + ", " +
strconv.Itoa(g) + ", " + strconv.Itoa(b) + ")")
} else if *printHex {
fmt.Print(fu.GetHex(r, g, b))
} else {
fmt.Print("\033[1A")
}
}
break
} else if ch == 'h' {
r = fu.IncVal(r, inc)
} else if ch == 'j' {
g = fu.IncVal(g, inc)
} else if ch == 'k' {
b = fu.IncVal(b, inc)
} else if ch == 'l' {
r = fu.IncVal(r, inc)
g = fu.IncVal(g, inc)
b = fu.IncVal(b, inc)
} else if ch == 'b' {
r = fu.DecVal(r, inc)
} else if ch == 'n' {
g = fu.DecVal(g, inc)
} else if ch == 'm' {
b = fu.DecVal(b, inc)
} else if ch == ',' {
r = fu.DecVal(r, inc)
g = fu.DecVal(g, inc)
b = fu.DecVal(b, inc)
} else if ch == 'H' {
r = rand.Intn(256)
} else if ch == 'J' {
g = rand.Intn(256)
} else if ch == 'K' {
b = rand.Intn(256)
} else if ch == 'L' {
r = rand.Intn(256)
g = rand.Intn(256)
b = rand.Intn(256)
} else if ch == ' ' {
r, g, b = 0, 0, 0
} else if ch > 47 && ch < 58 {
if ch == '0' {
inc = 10
} else {
conv, _ := strconv.Atoi(string(ch))
inc = conv
}
}
fmt.Print("\r" + strings.Repeat(" ", olen) + "\r")
}
fmt.Println()
ts.ShowCursor()
}