Compare commits
2 commits
afc4092824
...
16881d5e5a
Author | SHA1 | Date | |
---|---|---|---|
16881d5e5a | |||
9c8f71be07 |
26 changed files with 25 additions and 25 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,4 +4,4 @@
|
||||||
!*.go
|
!*.go
|
||||||
!*.md
|
!*.md
|
||||||
!*.mod
|
!*.mod
|
||||||
!*.sum
|
!*.sum
|
2
Color.go
2
Color.go
|
@ -39,4 +39,4 @@ func (c Color) Println(args ...any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\n\x1b[0m", c.R, c.G, c.B, fmt.Sprint(args...))
|
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\n\x1b[0m", c.R, c.G, c.B, fmt.Sprint(args...))
|
||||||
}
|
}
|
|
@ -52,4 +52,4 @@ func TestPrintln(t *testing.T) {
|
||||||
color.RGB(1, 0, 0).Println("red")
|
color.RGB(1, 0, 0).Println("red")
|
||||||
color.RGB(0, 1, 0).Println("green")
|
color.RGB(0, 1, 0).Println("green")
|
||||||
color.RGB(0, 0, 1).Println("blue")
|
color.RGB(0, 0, 1).Println("blue")
|
||||||
}
|
}
|
2
HSL.go
2
HSL.go
|
@ -26,4 +26,4 @@ func HSL(hue Value, saturation Value, lightness Value) Color {
|
||||||
|
|
||||||
m := lightness - c/2
|
m := lightness - c/2
|
||||||
return RGB(r+m, g+m, b+m)
|
return RGB(r+m, g+m, b+m)
|
||||||
}
|
}
|
|
@ -23,4 +23,4 @@ func TestHSLSpectrum(t *testing.T) {
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
}
|
}
|
2
HSV.go
2
HSV.go
|
@ -26,4 +26,4 @@ func HSV(hue Value, saturation Value, value Value) Color {
|
||||||
|
|
||||||
m := value - c
|
m := value - c
|
||||||
return RGB(r+m, g+m, b+m)
|
return RGB(r+m, g+m, b+m)
|
||||||
}
|
}
|
|
@ -23,4 +23,4 @@ func TestHSVSpectrum(t *testing.T) {
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
}
|
}
|
2
LCH.go
2
LCH.go
|
@ -57,4 +57,4 @@ func oklabToLinearRGB(lightness Value, a Value, b Value) (Value, Value, Value) {
|
||||||
blue := -0.0041960863*l - 0.7034186147*m + 1.7076147010*s
|
blue := -0.0041960863*l - 0.7034186147*m + 1.7076147010*s
|
||||||
|
|
||||||
return red, green, blue
|
return red, green, blue
|
||||||
}
|
}
|
|
@ -48,4 +48,4 @@ func TestLCHSpectrum(t *testing.T) {
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
}
|
}
|
2
RGB.go
2
RGB.go
|
@ -33,4 +33,4 @@ func sRGB(x Value) Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1.0
|
return 1.0
|
||||||
}
|
}
|
|
@ -26,4 +26,4 @@ func TestRGB(t *testing.T) {
|
||||||
for name, c := range rgbColors {
|
for name, c := range rgbColors {
|
||||||
c.Println("█ " + name)
|
c.Println("█ " + name)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,4 +10,4 @@ import (
|
||||||
var Terminal = tty.IsTerminal(os.Stdout.Fd())
|
var Terminal = tty.IsTerminal(os.Stdout.Fd())
|
||||||
|
|
||||||
// TrueColor indicates if the terminal has 24-bit color support.
|
// TrueColor indicates if the terminal has 24-bit color support.
|
||||||
var TrueColor = os.Getenv("COLORTERM") == "truecolor"
|
var TrueColor = os.Getenv("COLORTERM") == "truecolor"
|
2
Value.go
2
Value.go
|
@ -1,4 +1,4 @@
|
||||||
package color
|
package color
|
||||||
|
|
||||||
// Value is a type definition for the data type of a single color component.
|
// Value is a type definition for the data type of a single color component.
|
||||||
type Value = float64
|
type Value = float64
|
|
@ -37,4 +37,4 @@ func (code Code) Println(args ...any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\x1b[%dm%s\n\x1b[0m", code, fmt.Sprint(args...))
|
fmt.Printf("\x1b[%dm%s\n\x1b[0m", code, fmt.Sprint(args...))
|
||||||
}
|
}
|
|
@ -52,4 +52,4 @@ func testPrintln() {
|
||||||
ansi.Yellow.Println("Yellow")
|
ansi.Yellow.Println("Yellow")
|
||||||
ansi.Magenta.Println("Magenta")
|
ansi.Magenta.Println("Magenta")
|
||||||
ansi.Cyan.Println("Cyan")
|
ansi.Cyan.Println("Cyan")
|
||||||
}
|
}
|
|
@ -9,4 +9,4 @@ const (
|
||||||
Magenta
|
Magenta
|
||||||
Cyan
|
Cyan
|
||||||
White
|
White
|
||||||
)
|
)
|
|
@ -11,4 +11,4 @@ const (
|
||||||
Reverse
|
Reverse
|
||||||
Hidden
|
Hidden
|
||||||
Strikethrough
|
Strikethrough
|
||||||
)
|
)
|
|
@ -34,4 +34,4 @@ func BenchmarkPrintRaw(b *testing.B) {
|
||||||
for b.Loop() {
|
for b.Loop() {
|
||||||
c.Print("")
|
c.Print("")
|
||||||
}
|
}
|
||||||
}
|
}
|
2
go.mod
2
go.mod
|
@ -2,4 +2,4 @@ module git.urbach.dev/go/color
|
||||||
|
|
||||||
go 1.24
|
go 1.24
|
||||||
|
|
||||||
require golang.org/x/sys v0.31.0
|
require golang.org/x/sys v0.31.0
|
2
go.sum
2
go.sum
|
@ -1,2 +1,2 @@
|
||||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
|
@ -8,4 +8,4 @@ import "golang.org/x/sys/unix"
|
||||||
func IsTerminal(fd uintptr) bool {
|
func IsTerminal(fd uintptr) bool {
|
||||||
_, err := unix.IoctlGetTermios(int(fd), unix.TIOCGETA)
|
_, err := unix.IoctlGetTermios(int(fd), unix.TIOCGETA)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
|
@ -8,4 +8,4 @@ import "golang.org/x/sys/unix"
|
||||||
func IsTerminal(fd uintptr) bool {
|
func IsTerminal(fd uintptr) bool {
|
||||||
_, err := unix.IoctlGetTermios(int(fd), unix.TCGETS)
|
_, err := unix.IoctlGetTermios(int(fd), unix.TCGETS)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
|
@ -5,4 +5,4 @@ package tty
|
||||||
// IsTerminal is always false on unsupported platforms.
|
// IsTerminal is always false on unsupported platforms.
|
||||||
func IsTerminal(fd uintptr) bool {
|
func IsTerminal(fd uintptr) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
|
@ -9,4 +9,4 @@ import (
|
||||||
|
|
||||||
func TestIsTerminal(t *testing.T) {
|
func TestIsTerminal(t *testing.T) {
|
||||||
tty.IsTerminal(os.Stdout.Fd())
|
tty.IsTerminal(os.Stdout.Fd())
|
||||||
}
|
}
|
|
@ -9,4 +9,4 @@ func IsTerminal(fd uintptr) bool {
|
||||||
var mode uint32
|
var mode uint32
|
||||||
err := windows.GetConsoleMode(windows.Handle(fd), &mode)
|
err := windows.GetConsoleMode(windows.Handle(fd), &mode)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue