-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
44 lines (37 loc) · 846 Bytes
/
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
package main
import (
"fmt"
"image/color"
"log"
"os"
"github.com/charmbracelet/x/exp/term"
)
func main() {
in, out := os.Stdin, os.Stdout
state, err := term.MakeRaw(in.Fd())
if err != nil {
log.Fatal(err)
}
hasKitty, _ := term.QueryKittyKeyboard(in, out)
bg, _ := term.QueryBackgroundColor(in, out)
if err := term.Restore(in.Fd(), state); err != nil {
log.Fatal(err)
}
log.Printf("Kitty keyboard support: %v", hasKitty)
log.Printf("Background color: %s", colorToHexString(bg))
}
// colorToHexString returns a hex string representation of a color.
func colorToHexString(c color.Color) string {
if c == nil {
return ""
}
shift := func(v uint32) uint32 {
if v > 0xff {
return v >> 8
}
return v
}
r, g, b, _ := c.RGBA()
r, g, b = shift(r), shift(g), shift(b)
return fmt.Sprintf("#%02x%02x%02x", r, g, b)
}