feat: port the client to MyGo native UI (0.3.0)

Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
This commit is contained in:
OpenChamber committed 2026-11-18 13:22:59 +08:00
1 parent 2fb4a8ea79
commit 6c0ee61750
2538 files changed
+675779 -4792

No files matched your search

@@ -0,0 +1 @@
build/
+26
View File
@@ -0,0 +1,26 @@
# terminal
A terminal for [MyGo](https://github.com/egoist/mygo) apps of native UI: a
view that runs the user's shell, or any program, in a pseudo-terminal, with
[Ghostty](https://ghostty.org)'s terminal emulator, libghostty-vt, loaded
at run time with no cgo.
```go
import "github.com/egoist/mygo/plugins/terminal"
term, err := terminal.New(terminal.Options{})
// ...
mygo.NewWindow(mygo.WindowOptions{Title: "Terminal", Content: ui.View(func(c *ui.Context) {
terminal.View(c, term).Fill().AutoFocus()
})})
```
See [the documentation](../../docs/plugins/terminal.md), and
`examples/terminal` for an app.
`go generate` here builds libghostty-vt for every platform with Zig, from
the commit of Ghostty in `internal/libbuild`, into `build/`, and writes
`mygo-plugin.json`, which names the files and their SHA-256 for the CLI and
this package: publish them as the assets of the release that file points
at. It writes `ghostty_themes.go` too, the themes that Ghostty ships, which
`go run ./internal/libbuild -themes` writes alone, without Zig.
+87
View File
@@ -0,0 +1,87 @@
package terminal
import (
"fmt"
"strings"
"testing"
)
// A server's terminal has no View, but applications must still be able
// to query the colors configured for it.
func TestHeadlessThemeQueries(t *testing.T) {
loadLib(t)
for _, tc := range []struct {
name string
theme *Theme
mode int
}{
{"light", LightTheme(), 2},
{"dark", DarkTheme(), 1},
} {
t.Run(tc.name, func(t *testing.T) {
p := newPipe()
term, err := New(Options{Conn: p, Theme: tc.theme})
if err != nil {
t.Fatal(err)
}
defer term.Close()
term.Feed([]byte("\x1b]10;?\x1b\\\x1b]11;?\x1b\\\x1b[?996n"))
got := p.take(term)
for _, color := range []struct {
index int
r, g, b uint8
}{
{10, tc.theme.Foreground.R, tc.theme.Foreground.G, tc.theme.Foreground.B},
{11, tc.theme.Background.R, tc.theme.Background.G, tc.theme.Background.B},
} {
want := fmt.Sprintf("\x1b]%d;rgb:%04x/%04x/%04x\x1b\\", color.index,
uint16(color.r)*257, uint16(color.g)*257, uint16(color.b)*257)
if !strings.Contains(got, want) {
t.Errorf("query OSC %d: got %q, want %q", color.index, got, want)
}
}
if want := fmt.Sprintf("\x1b[?997;%dn", tc.mode); !strings.Contains(got, want) {
t.Errorf("scheme query: got %q, want %q", got, want)
}
})
}
}
func TestHeadlessAppearanceChanges(t *testing.T) {
loadLib(t)
p := newPipe()
term, err := New(Options{Conn: p, Theme: LightTheme()})
if err != nil {
t.Fatal(err)
}
defer term.Close()
// Applications that did not subscribe must receive no unsolicited
// input. Once subscribed, each preference change produces one report.
term.UseTheme(DarkTheme())
if got := p.take(term); got != "" {
t.Fatalf("unsubscribed application received %q", got)
}
term.Feed([]byte("\x1b[?2031h"))
p.take(term)
term.UseTheme(LightTheme())
if got, want := p.take(term), "\x1b[?997;2n"; got != want {
t.Fatalf("light change = %q, want %q", got, want)
}
term.UseTheme(LightTheme())
if got := p.take(term); got != "" {
t.Fatalf("unchanged preference sent %q", got)
}
term.UseTheme(DarkTheme())
if got, want := p.take(term), "\x1b[?997;1n"; got != want {
t.Fatalf("dark change = %q, want %q", got, want)
}
term.Feed([]byte("\x1b[?996n"))
if got, want := p.take(term), "\x1b[?997;1n"; got != want {
t.Fatalf("query after change = %q, want %q", got, want)
}
term.Feed([]byte("\x1b[?2031l"))
term.UseTheme(LightTheme())
if got := p.take(term); got != "" {
t.Fatalf("unsubscribed application received %q", got)
}
}
+90
View File
@@ -0,0 +1,90 @@
package terminal
import (
"fmt"
"strings"
"testing"
"github.com/egoist/mygo/ui"
)
// BenchmarkOutput measures how fast the terminal takes a program's output:
// lines of text with some colors.
func BenchmarkOutput(b *testing.B) {
if err := Load(); err != nil {
b.Skip(err)
}
term, err := New(Options{Conn: newPipe()})
if err != nil {
b.Fatal(err)
}
defer term.Close()
var sb strings.Builder
for i := range 1000 {
fmt.Fprintf(&sb, "\x1b[32m%6d\x1b[0m the quick brown fox jumps over the lazy dog \x1b[1;34m%x\x1b[0m\r\n", i, i*7919)
}
data := []byte(sb.String())
b.SetBytes(int64(len(data)))
for b.Loop() {
term.write(data)
}
}
// BenchmarkFrame measures a frame of a 1600×1000 window whose every row
// changed, as while a program scrolls.
func BenchmarkFrame(b *testing.B) {
if err := Load(); err != nil {
b.Skip(err)
}
term, err := New(Options{Conn: newPipe()})
if err != nil {
b.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 1600, 1000)
tt.SetScale(2)
i := 0
for b.Loop() {
i++
term.write([]byte(fmt.Sprintf("\x1b[32m%6d\x1b[0m the quick brown fox jumps over the lazy dog \x1b[1;34m%x\x1b[0m %s\r\n", i, i*7919, strings.Repeat("=", i%100))))
for range 60 {
term.write([]byte("line " + strings.Repeat("abc ", i%40) + "\r\n"))
}
tt.Frame()
}
}
// BenchmarkScroll measures a frame of a 1600×1000 window while a program
// prints a line or a few at a time, as a log scrolling: most rows only
// moved up.
func BenchmarkScroll(b *testing.B) {
for _, n := range []int{1, 16} {
b.Run(fmt.Sprintf("lines=%d", n), func(b *testing.B) {
if err := Load(); err != nil {
b.Skip(err)
}
term, err := New(Options{Conn: newPipe()})
if err != nil {
b.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 1600, 1000)
tt.SetScale(2)
i := 0
line := func() []byte {
i++
return fmt.Appendf(nil, "\x1b[32m%6d\x1b[0m the quick brown fox jumps over the lazy dog \x1b[1;34m%x\x1b[0m %s\r\n", i, i*7919, strings.Repeat("=", i%100))
}
for range 100 {
term.write(line())
}
tt.Frame()
for b.Loop() {
for range n {
term.write(line())
}
tt.Frame()
}
})
}
}
+332
View File
@@ -0,0 +1,332 @@
package terminal
import (
"math"
"github.com/egoist/mygo/ui"
)
// Characters of box drawing, blocks, legacy-computing sextants and
// Powerline's separators are drawn rather than taken from the font, as
// Ghostty draws them: fonts leave gaps between the lines of cells taller
// than their glyphs, and many lack the separators and the sextants.
// Weights of the arms of box drawing characters.
const (
armNone = iota
armLight
armHeavy
armDouble
)
// boxArms holds the arms of U+2500 to U+257F, from their Unicode names:
// the weights of up, right, down and left, a digit each; "" for those
// drawn otherwise (arcs, diagonals) or by the font (dashes).
var boxArms = [128]string{
"0101", "0202", "1010", "2020", "", "", "", "", "", "", "", "", "0110", "0210", "0120", "0220",
"0011", "0012", "0021", "0022", "1100", "1200", "2100", "2200", "1001", "1002", "2001", "2002", "1110", "1210", "2110", "1120",
"2120", "2210", "1220", "2220", "1011", "1012", "2011", "1021", "2021", "2012", "1022", "2022", "0111", "0112", "0211", "0212",
"0121", "0122", "0221", "0222", "1101", "1102", "1201", "1202", "2101", "2102", "2201", "2202", "1111", "1112", "1211", "1212",
"2111", "1121", "2121", "2112", "2211", "1122", "1221", "2212", "1222", "2122", "2221", "2222", "", "", "", "",
"0303", "3030", "0310", "0130", "0330", "0013", "0031", "0033", "1300", "3100", "3300", "1003", "3001", "3003", "1310", "3130",
"3330", "1013", "3031", "3033", "0313", "0131", "0333", "1303", "3101", "3303", "1313", "3131", "3333", "", "", "",
"", "", "", "", "0001", "1000", "0100", "0010", "0002", "2000", "0200", "0020", "0201", "1020", "0102", "2010",
}
// drawn reports whether the terminal draws r itself.
func drawn(r rune) bool {
switch {
case 0x2500 <= r && r <= 0x257f:
return boxArms[r-0x2500] != "" || 0x256d <= r && r <= 0x2573
case 0x2580 <= r && r <= 0x259f:
return true
case 0x1fb00 <= r && r <= 0x1fb3b:
return true
case 0xe0b0 <= r && r <= 0xe0b7:
return true
}
return false
}
// noMinContrast reports whether r is a shape rather than text, which
// keeps its color under the minimum contrast, as Ghostty's: box drawing,
// block elements, the legacy computing symbols and Powerline's. Copilot
// CLI edges its input box with half blocks in the box's color, which the
// contrast darkened into bars on a light background.
func noMinContrast(r rune) bool {
return 0x2500 <= r && r <= 0x259f || 0x1fb00 <= r && r <= 0x1fbff || 0xe0b0 <= r && r <= 0xe0d7
}
// drawBox draws r in cell c.
func drawBox(p *ui.Painter, r rune, c ui.Rect, col ui.Color) {
s := p.Scale()
// The cell in device pixels.
x0, y0 := float32(math.Round(float64(c.X*s))), float32(math.Round(float64(c.Y*s)))
x1, y1 := float32(math.Round(float64((c.X+c.W)*s))), float32(math.Round(float64((c.Y+c.H)*s)))
fill := func(ax, ay, bx, by float32) {
if bx > ax && by > ay {
p.Fill(ui.Rect{X: ax / s, Y: ay / s, W: (bx - ax) / s, H: (by - ay) / s}, col, 0)
}
}
w, h := x1-x0, y1-y0
switch {
case 0x2580 <= r && r <= 0x259f:
drawBlock(r, x0, y0, w, h, fill, p, col, s)
return
case 0x1fb00 <= r && r <= 0x1fb3b:
drawSextant(r, x0, y0, w, h, fill)
return
case 0xe0b0 <= r && r <= 0xe0b3:
var path ui.Path
if r == 0xe0b0 || r == 0xe0b1 {
path.MoveTo(x0/s, y0/s).LineTo(x1/s, (y0+h/2)/s).LineTo(x0/s, y1/s)
} else {
path.MoveTo(x1/s, y0/s).LineTo(x0/s, (y0+h/2)/s).LineTo(x1/s, y1/s)
}
if r == 0xe0b0 || r == 0xe0b2 {
path.Close()
p.FillPath(&path, col)
} else {
p.StrokePath(&path, max(1, float32(math.Round(float64(s))))/s, col)
}
return
case 0xe0b4 <= r && r <= 0xe0b7:
// Powerline's rounded caps: half an ellipse spanning the cell, as
// the triangles do. The font's glyph fell short of the taller cells
// a line height above 1 makes, next to the prompt's background.
const k = 0.5523 // a quarter circle's cubic control distance
ym := y0 + h/2
ex, fx := x1, x0 // the cap's tip and its flat side
if r >= 0xe0b6 {
ex, fx = x0, x1
}
kx, ky := fx+(ex-fx)*k, h/2*k
var path ui.Path
path.MoveTo(fx/s, y0/s).
CubeTo(kx/s, y0/s, ex/s, (ym-ky)/s, ex/s, ym/s).
CubeTo(ex/s, (ym+ky)/s, kx/s, y1/s, fx/s, y1/s)
if r == 0xe0b4 || r == 0xe0b6 {
path.Close()
p.FillPath(&path, col)
} else {
p.StrokePath(&path, max(1, float32(math.Round(float64(s))))/s, col)
}
return
}
light := max(1, float32(math.Round(float64(s))))
cx := x0 + float32(math.Floor(float64(w-light)/2))
cy := y0 + float32(math.Floor(float64(h-light)/2))
if 0x256d <= r && r <= 0x2573 {
var path ui.Path
mx, my := (cx+light/2)/s, (cy+light/2)/s
rad := min(w, h) / 2 / s
switch r {
case 0x256d: // ╭
path.MoveTo(mx, y1/s).LineTo(mx, my+rad).QuadTo(mx, my, mx+rad, my).LineTo(x1/s, my)
case 0x256e: // ╮
path.MoveTo(mx, y1/s).LineTo(mx, my+rad).QuadTo(mx, my, mx-rad, my).LineTo(x0/s, my)
case 0x256f: // ╯
path.MoveTo(mx, y0/s).LineTo(mx, my-rad).QuadTo(mx, my, mx-rad, my).LineTo(x0/s, my)
case 0x2570: // ╰
path.MoveTo(mx, y0/s).LineTo(mx, my-rad).QuadTo(mx, my, mx+rad, my).LineTo(x1/s, my)
case 0x2571: // ╱
path.MoveTo(x1/s, y0/s).LineTo(x0/s, y1/s)
case 0x2572: // ╲
path.MoveTo(x0/s, y0/s).LineTo(x1/s, y1/s)
case 0x2573: // ╳
path.MoveTo(x1/s, y0/s).LineTo(x0/s, y1/s)
p.StrokePath(&path, light/s, col)
path = ui.Path{}
path.MoveTo(x0/s, y0/s).LineTo(x1/s, y1/s)
}
p.StrokePath(&path, light/s, col)
return
}
arms := boxArms[r-0x2500]
if arms == "" {
return
}
drawArms(fill, [4]int{int(arms[0] - '0'), int(arms[1] - '0'), int(arms[2] - '0'), int(arms[3] - '0')}, x0, y0, x1, y1, cx+light/2, cy+light/2, light)
}
// drawArms draws the arms of a box drawing character (up, right, down,
// left) in the cell from x0, y0 to x1, y1, whose lines cross at mx, my,
// light pixels wide. Light and heavy arms are lines; a double arm is two
// light lines, a light line apart, which turn into the arm across them as
// a corner does, or go through.
func drawArms(fill func(ax, ay, bx, by float32), a [4]int, x0, y0, x1, y1, mx, my, light float32) {
up, right, down, left := a[0], a[1], a[2], a[3]
off := light // from the middle to each line of a double arm
vDouble := up == armDouble || down == armDouble
hDouble := left == armDouble || right == armDouble
thick := func(w int) float32 {
switch w {
case armHeavy:
return 2 * light
case armDouble:
return 2*off + light
}
return light
}
// The joint is as wide as the widest arm across.
hw := max(thick(left), thick(right))
vw := max(thick(up), thick(down))
single := func(w int) bool { return w == armLight || w == armHeavy }
if single(up) {
t, end := thick(up), my+hw/2
if hDouble && down == armNone {
end = my - off + light/2 // up to the upper line
}
fill(mx-t/2, y0, mx+t/2, end)
}
if single(down) {
t, start := thick(down), my-hw/2
if hDouble && up == armNone {
start = my + off - light/2
}
fill(mx-t/2, start, mx+t/2, y1)
}
if single(left) {
t, end := thick(left), mx+vw/2
if vDouble && right == armNone {
end = mx - off + light/2
}
fill(x0, my-t/2, end, my+t/2)
}
if single(right) {
t, start := thick(right), mx-vw/2
if vDouble && left == armNone {
start = mx + off - light/2
}
fill(start, my-t/2, x1, my+t/2)
}
// The lines of double arms. The one on a side with a double arm across
// is inside the corner it turns, and the other outside.
for _, side := range []float32{-1, 1} {
if vDouble {
lx := mx + side*off - light/2
across := left
if side > 0 {
across = right
}
if up == armDouble && down == armDouble && across != armDouble {
fill(lx, y0, lx+light, y1)
} else {
// Where the line meets the arms across: inside or outside
// their double lines, or at their single line.
in, out := my-off+light/2, my+off+light/2
if across == armDouble {
out = in
} else if !hDouble {
out = my + light/2
}
if up == armDouble {
fill(lx, y0, lx+light, out)
}
in, out = my+off-light/2, my-off-light/2
if across == armDouble {
out = in
} else if !hDouble {
out = my - light/2
}
if down == armDouble {
fill(lx, out, lx+light, y1)
}
}
}
if hDouble {
ly := my + side*off - light/2
across := up
if side > 0 {
across = down
}
if left == armDouble && right == armDouble && across != armDouble {
fill(x0, ly, x1, ly+light)
} else {
in, out := mx-off+light/2, mx+off+light/2
if across == armDouble {
out = in
} else if !vDouble {
out = mx + light/2
}
if left == armDouble {
fill(x0, ly, out, ly+light)
}
in, out = mx+off-light/2, mx-off-light/2
if across == armDouble {
out = in
} else if !vDouble {
out = mx - light/2
}
if right == armDouble {
fill(out, ly, x1, ly+light)
}
}
}
}
}
// drawSextant draws one of U+1FB00 to U+1FB3B across the whole cell.
// The sixty patterns are the six-bit masks except 0, 21, 42 and 63,
// which are a space, ▌, ▐ and █. Bit 0 is the upper left, then across
// and down; neighbors share an edge, as drawBlock's quadrants do.
func drawSextant(r rune, x0, y0, w, h float32, fill func(ax, ay, bx, by float32)) {
idx := int(r - 0x1fb00)
pattern := idx + idx/20 + 1
rx := func(f float32) float32 { return x0 + float32(math.Round(float64(w*f))) }
ry := func(f float32) float32 { return y0 + float32(math.Round(float64(h*f))) }
xm := rx(0.5)
ya, yb := ry(1.0/3), ry(2.0/3)
xs := [...]float32{x0, xm, x0 + w}
ys := [...]float32{y0, ya, yb, y0 + h}
for i := range 6 {
if pattern&(1<<i) == 0 {
continue
}
col, row := i%2, i/2
fill(xs[col], ys[row], xs[col+1], ys[row+1])
}
}
// drawBlock draws a block element (U+2580 to U+259F).
func drawBlock(r rune, x0, y0, w, h float32, fill func(ax, ay, bx, by float32), p *ui.Painter, col ui.Color, s float32) {
rx := func(f float32) float32 { return x0 + float32(math.Round(float64(w*f))) }
ry := func(f float32) float32 { return y0 + float32(math.Round(float64(h*f))) }
x1, y1 := x0+w, y0+h
switch {
case r == 0x2580:
fill(x0, y0, x1, ry(0.5))
case 0x2581 <= r && r <= 0x2588:
fill(x0, ry(1-float32(r-0x2580)/8), x1, y1)
case 0x2589 <= r && r <= 0x258f:
fill(x0, y0, rx(float32(0x2590-r)/8), y1)
case r == 0x2590:
fill(rx(0.5), y0, x1, y1)
case 0x2591 <= r && r <= 0x2593:
a := float32(r-0x2590) / 4
p.Fill(ui.Rect{X: x0 / s, Y: y0 / s, W: w / s, H: h / s}, col.Alpha(a), 0)
case r == 0x2594:
fill(x0, y0, x1, ry(1.0/8))
case r == 0x2595:
fill(rx(7.0/8), y0, x1, y1)
default:
// Quadrants: upper left, upper right, lower left, lower right.
q := map[rune]string{0x2596: "0010", 0x2597: "0001", 0x2598: "1000", 0x2599: "1011", 0x259a: "1001",
0x259b: "1110", 0x259c: "1101", 0x259d: "0100", 0x259e: "0110", 0x259f: "0111"}[r]
mx, my := rx(0.5), ry(0.5)
if len(q) == 4 {
if q[0] == '1' {
fill(x0, y0, mx, my)
}
if q[1] == '1' {
fill(mx, y0, x1, my)
}
if q[2] == '1' {
fill(x0, my, mx, y1)
}
if q[3] == '1' {
fill(mx, my, x1, y1)
}
}
}
}
+121
View File
@@ -0,0 +1,121 @@
package terminal
import (
"math"
"testing"
"github.com/egoist/mygo/ui"
)
// Powerline's rounded caps span the cell as its triangles do: at a line
// height of 1.22 the font's caps fell short of the prompt's background
// (kero#210).
func TestPowerlineRoundedCaps(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe(), Theme: LightTheme(), Font: Font{LineHeight: 1.6}})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 400, 200)
tt.Frame()
term.Feed([]byte("\x1b[38;2;255;0;0m"))
tt.Frame()
v := term.v
red := func(col, x, y int) bool {
c := tt.Image().RGBAAt(v.ox+col*v.cellW+x, v.oy+y)
return c.R > 200 && c.G < 100 && c.B < 100
}
w, h := v.cellW, v.cellH
for _, c := range []struct {
name string
col int
x, y int
filled bool
}{
{"E0B4 flat side, top", 0, 0, 1, true},
{"E0B4 flat side, bottom", 0, 0, h - 2, true},
{"E0B4 tip", 0, w - 1, h / 2, true},
{"E0B4 corner past the curve", 0, w - 1, 1, false},
{"E0B6 flat side, top", 1, w - 1, 1, true},
{"E0B6 flat side, bottom", 1, w - 1, h - 2, true},
{"E0B6 tip", 1, 0, h / 2, true},
{"E0B6 corner past the curve", 1, 0, 1, false},
{"E0B5 inside the outline", 2, w / 4, h / 2, false},
{"E0B7 inside the outline", 3, w - 1 - w/4, h / 2, false},
} {
if got := red(c.col, c.x, c.y); got != c.filled {
t.Errorf("%s (%d,%d in a %d×%d cell): drawn %v, want %v", c.name, c.x, c.y, w, h, got, c.filled)
}
}
}
// Sextants span the cell, two across and three down, sharing edges so a
// run of them has no seam. At a line height of 1.6 a font glyph stops
// short of that cell, so a pixel on its top and its bottom tells a drawn
// sextant from a glyph. U+1FB00 is the upper left block alone. U+1FB3B is
// the other five: its index sits past ▌, ▐ and █, so a wrong skip paints
// a different block. U+1FB3C starts the smooth mosaics, which stay with
// the font.
func TestSextants(t *testing.T) {
if !drawn(0x1fb00) || !drawn(0x1fb3b) || drawn(0x1fb3c) {
t.Fatalf("drawn U+1FB00 %v, U+1FB3B %v, U+1FB3C %v", drawn(0x1fb00), drawn(0x1fb3b), drawn(0x1fb3c))
}
loadLib(t)
term, err := New(Options{Conn: newPipe(), Theme: LightTheme(), Font: Font{LineHeight: 1.6}})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 400, 200)
tt.Frame()
term.Feed([]byte("\x1b[38;2;255;0;0m\U0001FB00\U0001FB3B"))
tt.Frame()
v := term.v
w, h := v.cellW, v.cellH
if w < 4 || h < 6 {
t.Fatalf("cell %d×%d is too small to resolve sextants", w, h)
}
// The same edges drawSextant rounds to. The pixel on a shared edge
// belongs to the block on its right or below.
edge := func(n, f float32) int { return int(math.Round(float64(n * f))) }
xm := edge(float32(w), 0.5)
ya := edge(float32(h), 1.0/3)
yb := edge(float32(h), 2.0/3)
// Bit 0 is the upper left, then upper right, middle left, middle
// right, lower left, lower right.
cells := []struct {
r rune
pattern int
}{{0x1fb00, 0b000001}, {0x1fb3b, 0b111110}}
red := func(col, x, y int) bool {
c := tt.Image().RGBAAt(v.ox+col*v.cellW+x, v.oy+y)
return c.R > 200 && c.G < 100 && c.B < 100
}
shown := 0
for col, cell := range cells {
for y := range h {
for x := range w {
bit := 0
if x >= xm {
bit = 1
}
switch {
case y >= yb:
bit += 4
case y >= ya:
bit += 2
}
want := cell.pattern&(1<<bit) != 0
if red(col, x, y) == want {
continue
}
t.Errorf("U+%04X (%d,%d in a %d×%d cell): drawn %v, want %v", cell.r, x, y, w, h, !want, want)
shown++
if shown == 8 {
t.Fatal("too many mismatched pixels")
}
}
}
}
}
+159
View File
@@ -0,0 +1,159 @@
package terminal
import (
"fmt"
"math"
"strings"
"testing"
"github.com/egoist/mygo/ui"
"golang.org/x/image/font/gofont/gomono"
"golang.org/x/image/font/gofont/goregular"
)
func TestCellWidthLiveGrid(t *testing.T) {
loadLib(t)
if err := ui.RegisterFont(gomono.TTF, "MyGo Cell Width Mono"); err != nil {
t.Fatal(err)
}
conn := newPipe()
font := Font{Family: "MyGo Cell Width Mono", Size: 14}
term, err := New(Options{Conn: conn, Font: font, CopyOnSelect: CopyOnSelectClipboard, NoBlink: true})
if err != nil {
t.Fatal(err)
}
defer term.Close()
term.Feed([]byte("A中文B"))
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill().AutoFocus() }, 640, 240)
baseW, baseH := term.v.cellW, term.v.cellH
baseCols, baseRows := term.Size()
for _, width := range []float32{1.03, 1.5, 0.8, 1} {
font.CellWidth = width
term.SetFont(font)
tt.Frame()
v := term.v
cols, rows := term.Size()
if v.cellH != baseH || rows != baseRows {
t.Fatalf("width %g changed rows from %d at %d pixels to %d at %d pixels", width, baseRows, baseH, rows, v.cellH)
}
if width == 1.5 && (v.cellW <= baseW || cols >= baseCols) {
t.Fatalf("wider cells left width %d and %d columns, from %d and %d", v.cellW, cols, baseW, baseCols)
}
if width == 0.8 && (v.cellW >= baseW || cols <= baseCols) {
t.Fatalf("narrower cells left width %d and %d columns, from %d and %d", v.cellW, cols, baseW, baseCols)
}
if width == 1 && (v.cellW != baseW || cols != baseCols) {
t.Fatalf("reset left width %d and %d columns, want %d and %d", v.cellW, cols, baseW, baseCols)
}
term.Feed([]byte("\x1b[16t\x1b[6n"))
want := fmt.Sprintf("\x1b[6;%d;%dt\x1b[1;7R", v.cellH, v.cellW)
if got := conn.take(term); got != want {
t.Fatalf("width %g: cell and mixed-width cursor queries = %q, want %q", width, got, want)
}
tt.SetClipboard("")
x, y := cellCenter(term, 0, 0)
tt.Press(x-2, y)
x, y = cellCenter(term, 4, 0)
tt.Move(x+2, y)
tt.Release(x+2, y)
if got := tt.Clipboard(); got != "A中文" {
t.Fatalf("width %g: mixed-width selection = %q", width, got)
}
term.Feed([]byte("\x1b[?1000h\x1b[?1006h"))
tt.Frame()
x, y = cellCenter(term, 12, 2)
tt.ClickAt(x, y)
if got := conn.take(term); !strings.Contains(got, "\x1b[<0;13;3M") {
t.Fatalf("width %g: click in column 13, row 3 reported %q", width, got)
}
term.Feed([]byte("\x1b[?1000l\x1b[?1006l"))
tt.Frame()
// Move the selection gesture's last click away from the next drag.
tt.ClickAt(x, y)
}
}
// Glyphs too wide for a cell shrink to the cell the font's own advance
// makes, so that wider columns space them out without enlarging them.
func TestCellWidthKeepsFittedGlyphs(t *testing.T) {
loadLib(t)
if err := ui.RegisterFont(goregular.TTF, "MyGo Cell Width Sans"); err != nil {
t.Fatal(err)
}
advance := func(width float32) float32 {
term, err := New(Options{Conn: newPipe(), Font: Font{Family: "MyGo Cell Width Sans", Size: 14, CellWidth: width}, NoBlink: true})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 400, 120)
// Go Regular draws DŽ wider than any of its ASCII glyphs.
term.Feed([]byte("DŽ"))
tt.Frame()
term.mu.Lock()
defer term.mu.Unlock()
for _, r := range term.v.lines[0].runs {
for i, g := range r.glyphs {
if r.cols[i] == 0 {
return g.Advance
}
}
}
t.Fatalf("width %g: no glyph in the first cell", width)
return 0
}
// Narrower cells leave it its size too, as they do every glyph.
fitted := advance(1)
for _, width := range []float32{1.5, 0.8} {
if got := advance(width); got != fitted {
t.Errorf("a glyph too wide for its cell is %v wide in cells %g times as wide, %v in the font's", got, width, fitted)
}
}
}
// A glyph that shrinks to fit its cell stays in the middle of the line,
// where it would be at its own size, rather than sink to the baseline.
func TestCellWidthShrinksToTheMiddle(t *testing.T) {
loadLib(t)
if err := ui.RegisterFont(goregular.TTF, "MyGo Cell Width Sans"); err != nil {
t.Fatal(err)
}
term, err := New(Options{Conn: newPipe(), Theme: LightTheme(), Font: Font{Family: "MyGo Cell Width Sans", Size: 40}, NoBlink: true})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 800, 200)
// Go Regular draws the digraph DZ wider than any of its ASCII glyphs,
// and D and Z, which make it, each fit a cell.
term.Feed([]byte("\x1b[38;2;255;0;0mDZ DZ"))
tt.Frame()
term.mu.Lock()
v := term.v
term.mu.Unlock()
img := tt.Image()
// The middle of the ink in columns col0 to col1.
middle := func(col0, col1 int) float64 {
top, bottom := -1, -1
for y := range v.cellH {
for x := col0 * v.cellW; x < (col1+1)*v.cellW; x++ {
if c := img.RGBAAt(v.ox+x, v.oy+y); c.R > 200 && c.G < 150 && c.B < 150 {
if top < 0 {
top = y
}
bottom = y
break
}
}
}
if top < 0 {
t.Fatalf("no ink in columns %d to %d", col0, col1)
}
return float64(top+bottom) / 2
}
shrunk, full := middle(0, 0), middle(2, 3)
t.Logf("cell %d×%d, middle %.1f shrunk, %.1f at full size", v.cellW, v.cellH, shrunk, full)
if math.Abs(shrunk-full) > 1 {
t.Errorf("a shrunk glyph's middle is %.1f pixels from the top of its cell, %.1f at full size", shrunk, full)
}
}
+68
View File
@@ -0,0 +1,68 @@
package terminal
import (
"testing"
"github.com/egoist/mygo/ui"
)
func TestContrasted(t *testing.T) {
white, black := ui.RGB(255, 255, 255), ui.RGB(0, 0, 0)
for _, c := range []struct {
fg, bg ui.Color
ratio float32
}{
{ui.RGB(240, 240, 240), white, 3}, // a dark theme's gray on a light one
{ui.RGB(30, 30, 30), black, 3}, // a light theme's on a dark one
{ui.RGB(229, 229, 16), white, 4.5}, // bright yellow
} {
got := contrasted(c.fg, c.bg, c.ratio)
r := contrast(luminance(got), luminance(c.bg))
if r < c.ratio || r > c.ratio*1.1 {
t.Errorf("contrasted(%v, %v, %v) = %v, a ratio of %v", c.fg, c.bg, c.ratio, got, r)
}
}
if got := contrasted(black, white, 4.5); got != black {
t.Errorf("black on white changed to %v", got)
}
// Short of the ratio even at black or white, the text takes the one
// that contrasts more.
if got := contrasted(ui.RGB(100, 100, 100), ui.RGB(128, 128, 128), 21); got != black {
t.Errorf("gray on gray at 21 = %v, want black", got)
}
}
// Shapes keep their colors under the minimum contrast, as in Ghostty, and
// text takes it: Copilot CLI's input box, a light gray edged with half
// blocks of that gray, showed dark bars on a white background.
func TestMinimumContrastShapes(t *testing.T) {
loadLib(t)
light := &Theme{Foreground: ui.RGB(0x20, 0x20, 0x20), Background: ui.RGB(255, 255, 255)}
term, err := New(Options{Conn: newPipe(), Theme: light, MinimumContrast: 3})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 400, 200)
gray := ui.RGB(232, 233, 235)
term.Feed([]byte("\x1b[38;2;232;233;235m▄▀█\U0001fb82A"))
tt.Frame()
term.mu.Lock()
line := term.v.lines[0]
term.mu.Unlock()
for _, b := range line.boxes {
if b.c != gray {
t.Errorf("%q drawn in %v, want %v", b.r, b.c, gray)
}
}
if len(line.boxes) != 4 {
t.Errorf("drew %d shapes, want 4", len(line.boxes))
}
var text []ui.Color
for _, r := range line.runs {
text = append(text, r.c)
}
if len(text) == 0 || text[len(text)-1] == gray {
t.Errorf("text in %v: not contrasted from %v", text, gray)
}
}
+129
View File
@@ -0,0 +1,129 @@
package terminal
import (
"math"
"runtime"
"strings"
"github.com/egoist/mygo/ui"
)
// Font is the font of a terminal's text, with what Ghostty's font options
// set.
type Font struct {
// Family is the font family, a comma-separated list as
// ui.Element.Font takes it, to which ui.RegisterFont adds the app's
// own fonts: "monospace", the system's, when empty.
Family string
// Size is the size in DIPs: 13 when zero.
Size float32
// Weight is how heavy text is, from 100 (thin) to 900 (black), of the
// weights the family has: 400 when zero. Bold text is 300 heavier, and
// at least 700.
Weight int
// Features turn OpenType features of the font on and off by tag, as
// Ghostty's font-feature: "ss01" or "+ss01" turns one on, "calt=0" or
// "-calt" off, and "cv05=2" picks an alternate. Coding fonts make
// most of their ligatures with calt, and the others with liga.
// On macOS, kerning is off unless they name kern: each character
// keeps its place in its cells.
Features []string
// CellWidth is the width of columns, as a multiple of the font's
// advance: 1 when zero or less. It changes the grid, not the font's
// size or the height of rows: glyphs keep their size, centered in
// their cells, and below 1 they overlap. Widths round up to whole
// display pixels.
CellWidth float32
// LineHeight is the height of rows, as a multiple of the font's own
// line height: 1 when zero, and 1.2 rows 20% taller, as Ghostty's
// adjust-cell-height = 20%. Text is centered in its row.
LineHeight float32
// Thicken draws text with a thicker stroke, as Ghostty's font-thicken:
// on macOS, with Core Text's font smoothing at its strongest, whatever
// the text's color and the system's setting. It changes nothing on
// Linux and Windows.
Thicken bool
}
// fontKey is a Font at a scale, with the defaults, comparable.
type fontKey struct {
family string
size float32
weight int
features string
cellWidth float32
lineHeight float32
thicken bool
scale float32
}
func (f *Font) key(scale float32) fontKey {
k := fontKey{family: f.Family, size: f.Size, weight: f.Weight, features: featureList(f.Features), cellWidth: f.CellWidth, lineHeight: f.LineHeight, thicken: f.Thicken, scale: scale}
if runtime.GOOS == "darwin" {
k.features = unkerned(k.features)
}
if strings.TrimSpace(k.family) == "" {
k.family = "monospace"
}
if k.size <= 0 {
k.size = 13
}
if k.weight <= 0 {
k.weight = 400
}
k.weight = min(max(k.weight, 100), 900)
if !(k.cellWidth > 0) || math.IsInf(float64(k.cellWidth), 0) {
k.cellWidth = 1
}
if k.lineHeight <= 0 {
k.lineHeight = 1
}
return k
}
// variant returns the font of a variant of text: bold (1) and italic (2).
func (k fontKey) variant(i int) ui.Font {
w := k.weight
if i&1 != 0 {
w = min(max(w+300, 700), 900)
}
return ui.Font{Family: k.family, Size: k.size, Weight: w, Italic: i&2 != 0, Features: k.features, Thicken: k.thicken}
}
// featureList converts features as Font.Features has them into the list
// ui.Font.Features takes.
func featureList(features []string) string {
var out []string
for _, f := range features {
f = strings.TrimSpace(f)
if tag, ok := strings.CutPrefix(f, "-"); ok {
f = strings.TrimSpace(tag) + "=0"
} else if tag, ok := strings.CutPrefix(f, "+"); ok {
f = strings.TrimSpace(tag)
}
if f != "" {
out = append(out, f)
}
}
return strings.Join(out, ",")
}
// unkerned adds kern=0 to a list of features that does not name kern.
// Kerning moves characters within their cells, and Core Text shrinks the
// CJK punctuation of the system's fonts that ends a run, as a 。 being
// typed does, to half its width: centered in its two cells, it jumps
// when text follows. Only macOS needs it: elsewhere, a list of features
// could cost the font its default ones, as DirectWrite's typography
// might.
func unkerned(list string) string {
for _, f := range strings.Split(list, ",") {
tag, _, _ := strings.Cut(f, "=")
if strings.TrimSpace(tag) == "kern" {
return list
}
}
if list == "" {
return "kern=0"
}
return "kern=0," + list
}
+249
View File
@@ -0,0 +1,249 @@
package terminal
import (
"bufio"
"bytes"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"runtime"
"slices"
"strconv"
"strings"
"github.com/egoist/mygo/ui"
)
// GhosttyTheme returns a theme of Ghostty's by its name, as Ghostty's
// theme option takes it ("Catppuccin Mocha", "Dracula", "Rose Pine
// Dawn"…): a theme file of the user's in Ghostty's themes directory
// ($XDG_CONFIG_HOME/ghostty/themes, ~/.config/ghostty/themes by
// default), else one of the themes Ghostty ships, which the plugin
// carries, of any case; or the theme file a path names. Each call returns
// a new Theme.
func GhosttyTheme(name string) (*Theme, error) {
if filepath.IsAbs(name) {
return readGhosttyTheme(name)
}
if name == "" || strings.ContainsAny(name, `/\`) || name == "." || name == ".." {
return nil, fmt.Errorf("terminal: %q names no theme of Ghostty's", name)
}
if dir := ghosttyThemesDir(); dir != "" {
th, err := readGhosttyTheme(filepath.Join(dir, name))
if !errors.Is(err, fs.ErrNotExist) {
return th, err
}
}
i := slices.IndexFunc(ghosttyThemes[:], func(t ghosttyTheme) bool { return t.name == name })
if i < 0 {
i = slices.IndexFunc(ghosttyThemes[:], func(t ghosttyTheme) bool { return strings.EqualFold(t.name, name) })
}
if i < 0 {
return nil, fmt.Errorf("terminal: Ghostty has no theme %q", name)
}
return ghosttyThemes[i].theme(), nil
}
// GhosttyThemes returns the names GhosttyTheme takes, sorted: those of the
// user's theme files and of the themes Ghostty ships.
func GhosttyThemes() []string {
names := make([]string, 0, len(ghosttyThemes))
for _, t := range ghosttyThemes {
names = append(names, t.name)
}
if dir := ghosttyThemesDir(); dir != "" {
entries, _ := os.ReadDir(dir)
for _, e := range entries {
if !e.IsDir() && !strings.HasPrefix(e.Name(), ".") {
names = append(names, e.Name())
}
}
}
slices.SortFunc(names, func(a, b string) int {
if c := strings.Compare(strings.ToLower(a), strings.ToLower(b)); c != 0 {
return c
}
return strings.Compare(a, b)
})
return slices.Compact(names)
}
// ghosttyThemesDir returns the directory of the user's themes of Ghostty,
// as Ghostty finds it.
func ghosttyThemesDir() string {
dir := os.Getenv("XDG_CONFIG_HOME")
if dir == "" && runtime.GOOS == "windows" {
dir = os.Getenv("LOCALAPPDATA")
}
if dir == "" {
home, err := os.UserHomeDir()
if err != nil {
return ""
}
dir = filepath.Join(home, ".config")
}
return filepath.Join(dir, "ghostty", "themes")
}
func readGhosttyTheme(path string) (*Theme, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("terminal: %w", err)
}
th, err := ParseGhosttyTheme(data)
if err != nil {
return nil, fmt.Errorf("%w in %s", err, path)
}
return th, nil
}
// ParseGhosttyTheme reads a theme in Ghostty's format, Ghostty's
// configuration's lines that set colors:
//
// palette = 0=#45475a
// …
// palette = 15=#a6adc8
// background = #1e1e2e
// foreground = #cdd6f4
// cursor-color = #f5e0dc
// cursor-text = #1e1e2e
// selection-background = #f5e0dc
// selection-foreground = #1e1e2e
//
// Colors are in hex (#rgb, #rrggbb, rrggbb…). Other lines of Ghostty's
// configuration are ignored, as are the palette's colors past the 16th,
// and the colors set to cell-foreground or cell-background, which the
// terminal then picks itself (see Theme). The colors a theme leaves out
// are those of DarkTheme, or LightTheme when its background is light.
func ParseGhosttyTheme(data []byte) (*Theme, error) {
var (
th Theme
set = map[string]bool{}
)
sc := bufio.NewScanner(bytes.NewReader(data))
for n := 1; sc.Scan(); n++ {
line := strings.TrimSpace(sc.Text())
if line == "" || line[0] == '#' {
continue
}
key, value, ok := strings.Cut(line, "=")
if !ok {
return nil, fmt.Errorf("terminal: line %d of the theme sets nothing", n)
}
key, value = strings.TrimSpace(key), strings.TrimSpace(value)
if len(value) >= 2 && value[0] == '"' && value[len(value)-1] == '"' {
value = value[1 : len(value)-1]
}
var dst *ui.Color
switch key {
case "background":
dst = &th.Background
case "foreground":
dst = &th.Foreground
case "cursor-color":
dst = &th.Cursor
case "cursor-text":
dst = &th.CursorText
case "selection-background":
dst = &th.Selection
case "selection-foreground":
dst = &th.SelectionText
case "search-background":
dst = &th.Search
case "search-foreground":
dst = &th.SearchText
case "search-selected-background":
dst = &th.SearchSelected
case "search-selected-foreground":
dst = &th.SearchSelectedText
case "palette":
i, c, ok := strings.Cut(value, "=")
index, err := strconv.ParseUint(strings.TrimSpace(i), 0, 8)
if !ok || err != nil {
return nil, fmt.Errorf("terminal: line %d of the theme: %q is no palette entry, as 0=#000000", n, value)
}
if index >= 16 {
continue
}
dst, value, key = &th.Palette[index], strings.TrimSpace(c), "palette"+strconv.Itoa(int(index))
default:
continue
}
if value == "" || value == "cell-foreground" || value == "cell-background" {
*dst, set[key] = ui.Color{}, false
continue
}
c, ok := parseHexColor(value)
if !ok {
return nil, fmt.Errorf("terminal: line %d of the theme: %q is no color in hex", n, value)
}
*dst, set[key] = c, true
}
if err := sc.Err(); err != nil {
return nil, err
}
def := DarkTheme()
if set["background"] && !th.dark() {
def = LightTheme()
}
if !set["background"] {
th.Background = def.Background
}
if !set["foreground"] {
th.Foreground = def.Foreground
}
for i := range th.Palette {
if !set["palette"+strconv.Itoa(i)] {
th.Palette[i] = def.Palette[i]
}
}
return &th, nil
}
// parseHexColor parses a color as Ghostty does in hex: #rgb, #rrggbb,
// #rrrgggbbb or #rrrrggggbbbb, or the first two without #.
func parseHexColor(s string) (ui.Color, bool) {
hex, ok := strings.CutPrefix(s, "#")
if !ok && len(hex) != 3 && len(hex) != 6 {
return ui.Color{}, false
}
if len(hex) == 0 || len(hex)%3 != 0 || len(hex) > 12 {
return ui.Color{}, false
}
w := len(hex) / 3
var rgb [3]uint8
for i := range rgb {
v, err := strconv.ParseUint(hex[i*w:(i+1)*w], 16, 16)
if err != nil {
return ui.Color{}, false
}
rgb[i] = uint8(v * 255 / (1<<(4*w) - 1))
}
return ui.RGB(rgb[0], rgb[1], rgb[2]), true
}
// ghosttyTheme is a theme Ghostty ships: the palette's 16 colors, then the
// background, the foreground, the cursor's color and text, and the
// selection's background and text, as 0xRRGGBB.
type ghosttyTheme struct {
name string
colors [22]uint32
}
func (t *ghosttyTheme) theme() *Theme {
c := func(i int) ui.Color {
v := t.colors[i]
return ui.RGB(uint8(v>>16), uint8(v>>8), uint8(v))
}
th := &Theme{
Background: c(16), Foreground: c(17),
Cursor: c(18), CursorText: c(19),
Selection: c(20), SelectionText: c(21),
}
for i := range th.Palette {
th.Palette[i] = c(i)
}
return th
}
+107
View File
@@ -0,0 +1,107 @@
package terminal
import (
"os"
"path/filepath"
"slices"
"strings"
"testing"
"github.com/egoist/mygo/ui"
)
func TestParseGhosttyTheme(t *testing.T) {
th, err := ParseGhosttyTheme([]byte(`# A theme
palette = 0=#123
palette = 0b1=#aaabbbccc
palette = 0x2 = 445566
palette = 200=#ffffff
background = "#fdf6e3"
foreground=#657b83
cursor-color = cell-foreground
cursor-text = #002b36
selection-background = #eee8d5
selection-foreground = #586e75
font-family = "Iosevka"
`))
if err != nil {
t.Fatal(err)
}
want := map[string][2]ui.Color{
"palette 0": {th.Palette[0], ui.Hex("#112233")},
"palette 1": {th.Palette[1], ui.RGB(0xaa, 0xbb, 0xcc)},
"palette 2": {th.Palette[2], ui.Hex("#445566")},
"background": {th.Background, ui.Hex("#fdf6e3")},
"foreground": {th.Foreground, ui.Hex("#657b83")},
"cursor": {th.Cursor, {}},
"cursor text": {th.CursorText, ui.Hex("#002b36")},
"selection": {th.Selection, ui.Hex("#eee8d5")},
"selected text": {th.SelectionText, ui.Hex("#586e75")},
// What the theme leaves out comes from the light theme, as its
// background is light.
"palette 3": {th.Palette[3], LightTheme().Palette[3]},
}
for name, c := range want {
if c[0] != c[1] {
t.Errorf("%s = %v, want %v", name, c[0], c[1])
}
}
empty, err := ParseGhosttyTheme(nil)
if err != nil || *empty != *DarkTheme() {
t.Errorf("an empty theme is %+v, %v; want the dark theme", empty, err)
}
for _, bad := range []string{"background = red", "palette = 300=#000000", "palette = #000000", "background"} {
if _, err := ParseGhosttyTheme([]byte(bad)); err == nil || !strings.Contains(err.Error(), "line 1") {
t.Errorf("%q: err = %v", bad, err)
}
}
}
func TestGhosttyTheme(t *testing.T) {
config := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", config)
if len(ghosttyThemes) < 500 || !slices.IsSortedFunc(ghosttyThemes[:], func(a, b ghosttyTheme) int { return strings.Compare(a.name, b.name) }) {
t.Fatalf("%d themes, sorted: want hundreds", len(ghosttyThemes))
}
mocha, err := GhosttyTheme("Catppuccin Mocha")
if err != nil {
t.Fatal(err)
}
if mocha.Background != ui.Hex("#1e1e2e") || mocha.Foreground != ui.Hex("#cdd6f4") || mocha.Palette[1] != ui.Hex("#f38ba8") ||
mocha.Cursor != ui.Hex("#f5e0dc") || mocha.SelectionText != ui.Hex("#1e1e2e") || !mocha.dark() {
t.Errorf("Catppuccin Mocha is %+v", mocha)
}
if th, err := GhosttyTheme("catppuccin mocha"); err != nil || *th != *mocha {
t.Errorf("names of another case: %+v, %v", th, err)
}
if th, _ := GhosttyTheme("Catppuccin Mocha"); th == mocha {
t.Error("two calls returned the same theme")
}
for _, bad := range []string{"", "No Such Theme", "../Dracula", "."} {
if _, err := GhosttyTheme(bad); err == nil {
t.Errorf("%q found a theme", bad)
}
}
// The user's themes come first, as in Ghostty.
dir := filepath.Join(config, "ghostty", "themes")
os.MkdirAll(dir, 0o755)
os.WriteFile(filepath.Join(dir, "Mine"), []byte("background = #102030\n"), 0o644)
os.WriteFile(filepath.Join(dir, "Dracula"), []byte("background = #010203\n"), 0o644)
os.WriteFile(filepath.Join(dir, "Broken"), []byte("background = nope\n"), 0o644)
for name, bg := range map[string]string{"Mine": "#102030", "Dracula": "#010203", filepath.Join(dir, "Mine"): "#102030"} {
if th, err := GhosttyTheme(name); err != nil || th.Background != ui.Hex(bg) {
t.Errorf("%s: %+v, %v", name, th, err)
}
}
if _, err := GhosttyTheme("Broken"); err == nil || !strings.Contains(err.Error(), "Broken") {
t.Errorf("a broken theme: %v", err)
}
names := GhosttyThemes()
if !slices.Contains(names, "Mine") || !slices.Contains(names, "Catppuccin Latte") || len(slices.Compact(slices.Clone(names))) != len(names) {
t.Errorf("GhosttyThemes misses the user's or Ghostty's themes, or repeats some: %d names", len(names))
}
if n := len(names); n != len(ghosttyThemes)+2 {
t.Errorf("%d names, want %d", n, len(ghosttyThemes)+2)
}
}
+651
View File
@@ -0,0 +1,651 @@
// Code generated by go generate (internal/libbuild); DO NOT EDIT.
package terminal
// ghosttyThemes are the themes the Ghostty this package binds ships, from
// iTerm2-Color-Schemes (https://github.com/mbadolato/iTerm2-Color-Schemes),
// as ghostty-themes-release-20260921-150923-0b55a9e.tgz has them:
//
// MIT License
//
// Copyright (c) 2011 to Present Mark Badolato
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// This license covers the iTerm-Color-Schemes repository collection of themes.
// The copyright/license for each individual theme belongs to the author of that theme.
var ghosttyThemes = [...]ghosttyTheme{
{"0x96f", [22]uint32{0x262427, 0xff666d, 0xb3e03a, 0xffc739, 0x00cde8, 0xa392e8, 0x9deaf6, 0xfcfcfa, 0x545452, 0xff7e83, 0xbee55e, 0xffd05e, 0x1bd5eb, 0xb0a3eb, 0xacedf8, 0xfcfcfa, 0x262427, 0xfcfcfa, 0xfcfcfa, 0x000000, 0xfcfcfa, 0x262427}},
{"12-bit Rainbow", [22]uint32{0x000000, 0xa03050, 0x40d080, 0xe09040, 0x3060b0, 0x603090, 0x0090c0, 0xdbded8, 0x685656, 0xc06060, 0x90d050, 0xe0d000, 0x00b0c0, 0x801070, 0x20b0c0, 0xffffff, 0x040404, 0xfeffff, 0xe0d000, 0x000000, 0x606060, 0xffffff}},
{"3024 Day", [22]uint32{0x090300, 0xdb2d20, 0x01a252, 0xcaba00, 0x01a0e4, 0xa16a94, 0x8fbece, 0xa5a2a2, 0x5c5855, 0xdbaec3, 0x3a3432, 0x4a4543, 0x807d7c, 0xbcbbba, 0xcdab53, 0xf7f7f7, 0xf7f7f7, 0x4a4543, 0x4a4543, 0xf7f7f7, 0xa5a2a2, 0x4a4543}},
{"3024 Night", [22]uint32{0x090300, 0xdb2d20, 0x01a252, 0xfded02, 0x01a0e4, 0xa16a94, 0xb5e4f4, 0xa5a2a2, 0x5c5855, 0xe8bbd0, 0x47413f, 0x4a4543, 0x807d7c, 0xd6d5d4, 0xcdab53, 0xf7f7f7, 0x090300, 0xa5a2a2, 0xa5a2a2, 0x090300, 0x4a4543, 0xa5a2a2}},
{"Aardvark Blue", [22]uint32{0x191919, 0xaa342e, 0x4b8c0f, 0xdbba00, 0x1370d3, 0xc43ac3, 0x008eb0, 0xbebebe, 0x525252, 0xf05b50, 0x95dc55, 0xffe763, 0x60a4ec, 0xe26be2, 0x60b6cb, 0xf7f7f7, 0x102040, 0xdddddd, 0x007acc, 0xbfdbfe, 0xbfdbfe, 0x000000}},
{"Aardvark Ink", [22]uint32{0x222734, 0xc26265, 0x52aa60, 0xad9b49, 0x487fd4, 0xaf5bd1, 0x269d9a, 0x5a6377, 0x3a4152, 0xe48383, 0x75cf84, 0xc7b461, 0x76a8f2, 0xd58bf0, 0x52c4c0, 0xdfe5ee, 0x0f141f, 0xb4bcca, 0xb4bcca, 0x0f141f, 0x2a3645, 0xdfe5ee}},
{"Abernathy", [22]uint32{0x000000, 0xcd0000, 0x00cd00, 0xcdcd00, 0x1093f5, 0xcd00cd, 0x00cdcd, 0xfaebd7, 0x404040, 0xff0000, 0x00ff00, 0xffff00, 0x11b5f6, 0xff00ff, 0x00ffff, 0xffffff, 0x111416, 0xeeeeec, 0xbbbbbb, 0xffffff, 0xeeeeec, 0x333333}},
{"Acid Lime", [22]uint32{0x131d0c, 0xff3344, 0x97e63c, 0xeeff5c, 0x4deca0, 0xa6ff6b, 0x50ffb4, 0xbfe0a4, 0x4a6b36, 0xff3344, 0x97e63c, 0xdbff45, 0x4deca0, 0xa6ff6b, 0x50ffb4, 0xd4efbc, 0x080c05, 0xd4efbc, 0xc2ff33, 0x080c05, 0x1b2a10, 0x545852}},
{"Adventure", [22]uint32{0x040404, 0xd84a33, 0x5da602, 0xeebb6e, 0x417ab3, 0xe5c499, 0xbdcfe5, 0xdbded8, 0x685656, 0xd76b42, 0x99b52c, 0xffb670, 0x97d7ef, 0xaa7900, 0xbdcfe5, 0xe4d5c7, 0x040404, 0xfeffff, 0xfeffff, 0x000000, 0x606060, 0xffffff}},
{"Adventure Time", [22]uint32{0x050404, 0xbd0013, 0x4ab118, 0xe7741e, 0x0f4ac6, 0x665993, 0x70a598, 0xf8dcc0, 0x4e7cbf, 0xfc5f5a, 0x9eff6e, 0xefc11a, 0x1997c6, 0x9b5953, 0xc8faf4, 0xf6f5fb, 0x1f1d45, 0xf8dcc0, 0xefbf38, 0x08080a, 0x706b4e, 0xf3d9c4}},
{"Adwaita", [22]uint32{0x1d1d20, 0xc01c28, 0x26a269, 0xa2734c, 0x12488b, 0xa347ba, 0x2aa1b3, 0xc2c2c2, 0x5d5d5d, 0xf66151, 0x33d17a, 0xe9ad0c, 0x2a7bde, 0xc061cb, 0x33c7de, 0xffffff, 0xffffff, 0x1d1d20, 0x1d1d20, 0xffffff, 0x1d1d20, 0xffffff}},
{"Adwaita Dark", [22]uint32{0x241f31, 0xc01c28, 0x2ec27e, 0xf5c211, 0x1e78e4, 0x9841bb, 0x0ab9dc, 0xc0bfbc, 0x5e5c64, 0xed333b, 0x57e389, 0xf8e45c, 0x51a1ff, 0xc061cb, 0x4fd2fd, 0xf6f5f4, 0x1c1c1f, 0xffffff, 0xffffff, 0x1c1c1f, 0xffffff, 0x1c1c1f}},
{"Afterglow", [22]uint32{0x151515, 0xac4142, 0x7e8e50, 0xe5b567, 0x6c99bb, 0x9f4e85, 0x7dd6cf, 0xd0d0d0, 0x505050, 0xac4142, 0x7e8e50, 0xe5b567, 0x6c99bb, 0x9f4e85, 0x7dd6cf, 0xf5f5f5, 0x212121, 0xd0d0d0, 0xd0d0d0, 0x151515, 0x303030, 0xd0d0d0}},
{"Aizen Dark", [22]uint32{0x1a1a1a, 0xf08898, 0xa4e09c, 0xf5dea4, 0x84b4f8, 0xc8a2f4, 0x90dcd0, 0xd0d6f0, 0x444444, 0xf08898, 0xa4e09c, 0xf5dea4, 0x84b4f8, 0xc8a2f4, 0x90dcd0, 0xffffff, 0x1a1a1a, 0xd0d6f0, 0xf8b080, 0x1a1a1a, 0x333333, 0xd0d6f0}},
{"Aizen Light", [22]uint32{0xf0f2f6, 0xd00c36, 0x3e9e28, 0xdd8c1a, 0x1c64f2, 0x8636ec, 0x159096, 0x4a4d66, 0xadb2bc, 0xd00c36, 0x3e9e28, 0xdd8c1a, 0x1c64f2, 0x8636ec, 0x159096, 0x4a4d66, 0xf0f2f6, 0x4a4d66, 0xfc6008, 0xf0f2f6, 0xbdc2cc, 0x4a4d66}},
{"Alabaster", [22]uint32{0x000000, 0xaa3731, 0x448c27, 0xcb9000, 0x325cc0, 0x7a3e9d, 0x0083b2, 0xb7b7b7, 0x777777, 0xf05050, 0x60cb00, 0xf2af50, 0x007acc, 0xe64ce6, 0x00aacb, 0xf7f7f7, 0xf7f7f7, 0x000000, 0x007acc, 0xbfdbfe, 0xbfdbfe, 0x000000}},
{"Alien Blood", [22]uint32{0x112616, 0x7f2b27, 0x2f7e25, 0x717f24, 0x2f6a7f, 0x47587f, 0x327f77, 0x647d75, 0x3c4812, 0xe08009, 0x18e000, 0xbde000, 0x00aae0, 0x0058e0, 0x00e0c4, 0x73fa91, 0x0f1610, 0x637d75, 0x73fa91, 0x0f1610, 0x1d4125, 0x73fa91}},
{"Amber CRT Retro", [22]uint32{0x2a1e00, 0xff6a00, 0xffb000, 0xffc742, 0xff8c00, 0xffa033, 0xffd27f, 0xffd9a0, 0x6a4e00, 0xff8a1e, 0xffc742, 0xffe08a, 0xffab3d, 0xffc266, 0xffe3b0, 0xfff0d6, 0x1a1200, 0xffb000, 0xffb000, 0x1a1200, 0x3a2a00, 0x5a5240}},
{"Andromeda", [22]uint32{0x000000, 0xcd3131, 0x05bc79, 0xe5e512, 0x2472c8, 0xbc3fbc, 0x0fa8cd, 0xe5e5e5, 0x666666, 0xcd3131, 0x05bc79, 0xe5e512, 0x2472c8, 0xbc3fbc, 0x0fa8cd, 0xe5e5e5, 0x262a33, 0xe5e5e5, 0xf8f8f0, 0xb5b5a8, 0x5a5c62, 0xece7e7}},
{"Apple Classic", [22]uint32{0x000000, 0xc91b00, 0x00c200, 0xc7c400, 0x1c3fe1, 0xca30c7, 0x00c5c7, 0xc7c7c7, 0x686868, 0xff6e67, 0x5ffa68, 0xfffc67, 0x6871ff, 0xff77ff, 0x60fdff, 0xffffff, 0x2c2b2b, 0xd5a200, 0xc7c7c7, 0x8c8c8c, 0x6b5b02, 0x67e000}},
{"Apple System Colors", [22]uint32{0x1a1a1a, 0xcc372e, 0x26a439, 0xcdac08, 0x0869cb, 0x9647bf, 0x479ec2, 0x98989d, 0x464646, 0xff453a, 0x32d74b, 0xffd60a, 0x0a84ff, 0xbf5af2, 0x76d6ff, 0xffffff, 0x1e1e1e, 0xffffff, 0x98989d, 0xffffff, 0x3f638b, 0xffffff}},
{"Apple System Colors Light", [22]uint32{0x1a1a1a, 0xcc372e, 0x26a439, 0xcdac08, 0x0869cb, 0x9647bf, 0x479ec2, 0x98989d, 0x464646, 0xff453a, 0x32d74b, 0xe5bc00, 0x0a84ff, 0xbf5af2, 0x69c9f2, 0xffffff, 0xfeffff, 0x000000, 0x98989d, 0xffffff, 0xabd8ff, 0x000000}},
{"Arcoiris", [22]uint32{0x333333, 0xda2700, 0x12c258, 0xffc656, 0x518bfc, 0xe37bd9, 0x63fad5, 0xbab2b2, 0x777777, 0xffb9b9, 0xe3f6aa, 0xffddaa, 0xb3e8f3, 0xcbbaf9, 0xbcffc7, 0xefefef, 0x201f1e, 0xeee4d9, 0x872929, 0xfffbf2, 0x25524a, 0xf3fffd}},
{"Ardoise", [22]uint32{0x2c2c2c, 0xd3322d, 0x588b35, 0xfca93a, 0x2465c2, 0x7332b4, 0x64e1b8, 0xf7f7f7, 0x535353, 0xfa5852, 0x8dc252, 0xffea51, 0x6ab5f8, 0xbe68ca, 0x89ffdb, 0xfefefe, 0x1e1e1e, 0xeaeaea, 0xf7f7f7, 0x000000, 0x46515e, 0xf1f3f5}},
{"Argonaut", [22]uint32{0x232323, 0xff000f, 0x8ce10b, 0xffb900, 0x008df8, 0x6d43a6, 0x00d8eb, 0xffffff, 0x444444, 0xff2740, 0xabe15b, 0xffd242, 0x0092ff, 0x9a5feb, 0x67fff0, 0xffffff, 0x0e1019, 0xfffaf4, 0xff0018, 0xff8ca4, 0x002a3b, 0xffffff}},
{"Arthur", [22]uint32{0x3d352a, 0xcd5c5c, 0x86af80, 0xe8ae5b, 0x6495ed, 0xdeb887, 0xb0c4de, 0xbbaa99, 0x554444, 0xcc5533, 0x88aa22, 0xffa75d, 0x87ceeb, 0x996600, 0xb0c4de, 0xddccbb, 0x1c1c1c, 0xddeedd, 0xe2bbef, 0x000000, 0x4d4d4d, 0xffffff}},
{"Atelier Sulphurpool", [22]uint32{0x202746, 0xc94922, 0xac9739, 0xc08b30, 0x3d8fd1, 0x6679cc, 0x22a2c9, 0x979db4, 0x6b7394, 0xc76b29, 0x4f587c, 0x5e6687, 0x898ea4, 0xdfe2f1, 0x9c637a, 0xf5f7ff, 0x202746, 0x979db4, 0x979db4, 0x202746, 0x5e6687, 0x979db4}},
{"Atlas Ragnarok", [22]uint32{0x000000, 0xff8080, 0x99ffe4, 0x2563eb, 0xa0a0a0, 0x3b82f6, 0x99ffe4, 0xffffff, 0x505050, 0xff9999, 0xb3ffe4, 0x60a5fa, 0xb0b0b0, 0x93c5fd, 0x99ffe4, 0xffffff, 0x000000, 0xffffff, 0x3b82f6, 0xffffff, 0x1e3a5f, 0xffffff}},
{"Atom", [22]uint32{0x000000, 0xfd5ff1, 0x87c38a, 0xffd7b1, 0x85befd, 0xb9b6fc, 0x85befd, 0xe0e0e0, 0x4c4c4c, 0xfd5ff1, 0x94fa36, 0xf5ffa8, 0x96cbfe, 0xb9b6fc, 0x85befd, 0xe0e0e0, 0x161719, 0xc5c8c6, 0xd0d0d0, 0x151515, 0x444444, 0xc5c8c6}},
{"Atom One Dark", [22]uint32{0x21252b, 0xe06c75, 0x98c379, 0xe5c07b, 0x61afef, 0xc678dd, 0x56b6c2, 0xabb2bf, 0x767676, 0xe06c75, 0x98c379, 0xe5c07b, 0x61afef, 0xc678dd, 0x56b6c2, 0xabb2bf, 0x21252b, 0xabb2bf, 0xabb2bf, 0x21252b, 0x323844, 0xabb2bf}},
{"Atom One Light", [22]uint32{0x000000, 0xde3e35, 0x3f953a, 0xd2b67c, 0x2f5af3, 0x950095, 0x3f953a, 0xbbbbbb, 0x000000, 0xde3e35, 0x3f953a, 0xd2b67c, 0x2f5af3, 0xa00095, 0x3f953a, 0xffffff, 0xf9f9f9, 0x2a2c33, 0xbbbbbb, 0xffffff, 0xededed, 0x2a2c33}},
{"Aubade", [22]uint32{0x33293f, 0xc0303a, 0x2e7d6e, 0x8c610c, 0x4a3cc0, 0x8a4bc0, 0xae3f84, 0xb2b2b2, 0x9a8fa8, 0xc0303a, 0x2e7d6e, 0xae3f84, 0x4a3cc0, 0xd8b670, 0xae3f84, 0x3a3340, 0xfbf6fb, 0x3a3340, 0xae3f84, 0xfbf6fb, 0xebe2ee, 0xaea9ae}},
{"Aura", [22]uint32{0x110f18, 0xff6767, 0x61ffca, 0xffca85, 0xa277ff, 0xa277ff, 0x61ffca, 0xedecee, 0x4d4d4d, 0xffca85, 0xa277ff, 0xffca85, 0xa277ff, 0xa277ff, 0x61ffca, 0xedecee, 0x15141b, 0xedecee, 0xa277ff, 0xedecee, 0xa277ff, 0xedecee}},
{"Aura Dark", [22]uint32{0x15141b, 0xff6767, 0x61ffca, 0xffca85, 0xa277ff, 0x61ffca, 0xa277ff, 0xcdccce, 0x464646, 0xffca85, 0xa277ff, 0xffca85, 0xa277ff, 0x61ffca, 0x61ffca, 0xedecee, 0x15141b, 0xcdccce, 0xa277ff, 0x15141b, 0xcdccce, 0x15141b}},
{"Aurora", [22]uint32{0x23262e, 0xf0266f, 0x8fd46d, 0xffe66d, 0x102ee4, 0xee5d43, 0x03d6b8, 0xc74ded, 0x4f545e, 0xf92672, 0x8fd46d, 0xffe66d, 0x03d6b8, 0xee5d43, 0x03d6b8, 0xc74ded, 0x23262e, 0xffca28, 0xee5d43, 0xffd29c, 0x292e38, 0x00e8c6}},
{"Ayu", [22]uint32{0x11151c, 0xea6c73, 0x7fd962, 0xf9af4f, 0x53bdfa, 0xcda1fa, 0x90e1c6, 0xc7c7c7, 0x686868, 0xf07178, 0xaad94c, 0xffb454, 0x59c2ff, 0xd2a6ff, 0x95e6cb, 0xffffff, 0x0b0e14, 0xbfbdb6, 0xe6b450, 0x0b0e14, 0x409fff, 0x0b0e14}},
{"Ayu Light", [22]uint32{0x000000, 0xea6c6d, 0x6cbf43, 0xeca944, 0x3199e1, 0x9e75c7, 0x46ba94, 0xbababa, 0x686868, 0xf07171, 0x86b300, 0xf2ae49, 0x399ee6, 0xa37acc, 0x4cbf99, 0xd1d1d1, 0xf8f9fa, 0x5c6166, 0xffaa33, 0xf8f9fa, 0x035bd6, 0xf8f9fa}},
{"Ayu Mirage", [22]uint32{0x171b24, 0xed8274, 0x87d96c, 0xfacc6e, 0x6dcbfa, 0xdabafa, 0x90e1c6, 0xc7c7c7, 0x686868, 0xf28779, 0xd5ff80, 0xffd173, 0x73d0ff, 0xdfbfff, 0x95e6cb, 0xffffff, 0x1f2430, 0xcccac2, 0xffcc66, 0x1f2430, 0x409fff, 0x1f2430}},
{"Banana Blueberry", [22]uint32{0x17141f, 0xff6b7f, 0x00bd9c, 0xe6c62f, 0x22e8df, 0xdc396a, 0x56b6c2, 0xf1f1f1, 0x495162, 0xfe9ea1, 0x98c379, 0xf9e46b, 0x91fff4, 0xda70d6, 0xbcf3ff, 0xffffff, 0x191323, 0xcccccc, 0xe07d13, 0xffffff, 0x220525, 0xf4f4f4}},
{"Batman", [22]uint32{0x1b1d1e, 0xe6dc44, 0xc8be46, 0xf4fd22, 0x737174, 0x747271, 0x62605f, 0xc6c5bf, 0x505354, 0xfff78e, 0xfff27d, 0xfeed6c, 0x919495, 0x9a9a9d, 0xa3a3a6, 0xdadbd6, 0x1b1d1e, 0x6f6f6f, 0xfcef0c, 0x000000, 0x4d504c, 0xf0e04a}},
{"Belafonte Day", [22]uint32{0x20111b, 0xbe100e, 0x858162, 0xd08b30, 0x426a79, 0x97522c, 0x989a9c, 0x968c83, 0x5e5252, 0xbe100e, 0x858162, 0xd08b30, 0x426a79, 0x97522c, 0x989a9c, 0xd5ccba, 0xd5ccba, 0x45373c, 0x45373c, 0xd5ccba, 0x968c83, 0x45373c}},
{"Belafonte Night", [22]uint32{0x20111b, 0xbe100e, 0x858162, 0xeaa549, 0x426a79, 0x97522c, 0x989a9c, 0x968c83, 0x5e5252, 0xbe100e, 0x858162, 0xeaa549, 0x426a79, 0x97522c, 0x989a9c, 0xd5ccba, 0x20111b, 0x968c83, 0x968c83, 0x20111b, 0x45373c, 0x968c83}},
{"Birds Of Paradise", [22]uint32{0x573d26, 0xbe2d26, 0x6ba18a, 0xe99d2a, 0x5a86ad, 0xac80a6, 0x74a6ad, 0xe0dbb7, 0x9b6c4a, 0xe84627, 0x95d8ba, 0xd0d150, 0xb8d3ed, 0xd19ecb, 0x93cfd7, 0xfff9d5, 0x2a1f1d, 0xe0dbb7, 0x644a33, 0x8a7059, 0x563c27, 0xe0dbbb}},
{"Black Metal", [22]uint32{0x000000, 0x486e6f, 0xdd9999, 0xa06666, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x486e6f, 0xdd9999, 0xa06666, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Bathory)", [22]uint32{0x000000, 0x5f8787, 0xfbcb97, 0xe78a53, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0xfbcb97, 0xe78a53, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Burzum)", [22]uint32{0x000000, 0x5f8787, 0xddeecc, 0x99bbaa, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0xddeecc, 0x99bbaa, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Dark Funeral)", [22]uint32{0x000000, 0x5f8787, 0xd0dfee, 0x5f81a5, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0xd0dfee, 0x5f81a5, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Gorgoroth)", [22]uint32{0x000000, 0x5f8787, 0x9b8d7f, 0x8c7f70, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0x9b8d7f, 0x8c7f70, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Immortal)", [22]uint32{0x000000, 0x5f8787, 0x7799bb, 0x556677, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0x7799bb, 0x556677, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Khold)", [22]uint32{0x000000, 0x5f8787, 0xeceee3, 0x974b46, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0xeceee3, 0x974b46, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Marduk)", [22]uint32{0x000000, 0x5f8787, 0xa5aaa7, 0x626b67, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0xa5aaa7, 0x626b67, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Mayhem)", [22]uint32{0x000000, 0x5f8787, 0xf3ecd4, 0xeecc6c, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0xf3ecd4, 0xeecc6c, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Nile)", [22]uint32{0x000000, 0x5f8787, 0xaa9988, 0x777755, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0xaa9988, 0x777755, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Black Metal (Venom)", [22]uint32{0x000000, 0x5f8787, 0xf8f7f2, 0x79241f, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x404040, 0x5f8787, 0xf8f7f2, 0x79241f, 0x888888, 0x999999, 0xaaaaaa, 0xc1c1c1, 0x000000, 0xc1c1c1, 0xc1c1c1, 0x8e8e8e, 0xc1c1c1, 0x000000}},
{"Blazer", [22]uint32{0x000000, 0xb87a7a, 0x7ab87a, 0xb8b87a, 0x7a7ab8, 0xb87ab8, 0x7ab8b8, 0xd9d9d9, 0x4c4c4c, 0xdbbdbd, 0xbddbbd, 0xdbdbbd, 0xbdbddb, 0xdbbddb, 0xbddbdb, 0xffffff, 0x0d1926, 0xd9e6f2, 0xd9e6f2, 0x0d1926, 0xc1ddff, 0x000000}},
{"Blue Berry Pie", [22]uint32{0x0a4c62, 0x99246e, 0x5cb1b3, 0xeab9a8, 0x90a5bd, 0x9d54a7, 0x7e83cc, 0xf0e8d6, 0x463c5d, 0xc87272, 0x0a6c7e, 0x7a3188, 0x5f3d63, 0xbc94b7, 0x5e6071, 0x0a6c7e, 0x1c0c28, 0xbabab9, 0xfcfad6, 0x000000, 0x606060, 0xffffff}},
{"Blue Dolphin", [22]uint32{0x292d3e, 0xff8288, 0xb4e88d, 0xf4d69f, 0x82aaff, 0xe9c1ff, 0x89ebff, 0xd0d0d0, 0x9094a4, 0xff8b92, 0xddffa7, 0xffe585, 0x9cc4ff, 0xddb0f6, 0xa3f7ff, 0xffffff, 0x006984, 0xc5f2ff, 0xffcc00, 0x292d3e, 0x2baeca, 0xeceff1}},
{"Blue Matrix", [22]uint32{0x101116, 0xff5680, 0x00ff9c, 0xfffc58, 0x00b0ff, 0xd57bff, 0x76c1ff, 0xc7c7c7, 0x686868, 0xff6e67, 0x5ffa68, 0xfffc67, 0x6871ff, 0xd682ec, 0x60fdff, 0xffffff, 0x101116, 0x00a2ff, 0x76ff9f, 0xa6a6a6, 0xc1deff, 0x000000}},
{"Bluloco Dark", [22]uint32{0x41444d, 0xfc2f52, 0x25a45c, 0xff936a, 0x3476ff, 0x7a82da, 0x4483aa, 0xcdd4e0, 0x8f9aae, 0xff6480, 0x3fc56b, 0xf9c859, 0x10b1fe, 0xff78f8, 0x5fb9bc, 0xffffff, 0x282c34, 0xb9c0cb, 0xffcc00, 0x282c34, 0xb9c0ca, 0x272b33}},
{"Bluloco Light", [22]uint32{0x373a41, 0xd52753, 0x23974a, 0xdf631c, 0x275fe4, 0x823ff1, 0x27618d, 0xbabbc2, 0x676a77, 0xff6480, 0x3cbc66, 0xc5a332, 0x0099e1, 0xce33c0, 0x6d93bb, 0xd3d3d3, 0xf9f9f9, 0x373a41, 0xf32759, 0xffffff, 0xdaf0ff, 0x373a41}},
{"Borland", [22]uint32{0x4f4f4f, 0xff6c60, 0xa8ff60, 0xffffb6, 0x96cbfe, 0xff73fd, 0xc6c5fe, 0xeeeeee, 0x7c7c7c, 0xffb6b0, 0xceffac, 0xffffcc, 0xb5dcff, 0xff9cfe, 0xdfdffe, 0xffffff, 0x0000a4, 0xffff4e, 0xffa560, 0xffffff, 0xa4a4a4, 0x0000a4}},
{"Box", [22]uint32{0x000000, 0xcc0403, 0x19cb00, 0xcecb00, 0x0d73cc, 0xcb1ed1, 0x0dcdcd, 0xdddddd, 0x767676, 0xf2201f, 0x23fd00, 0xfffd00, 0x1a8fff, 0xfd28ff, 0x14ffff, 0xffffff, 0x141d2b, 0x9fef00, 0x9fef00, 0x111111, 0xa4b1cd, 0x141d2b}},
{"Breadog", [22]uint32{0x362c24, 0xb10b00, 0x007232, 0x8b4c00, 0x005cb4, 0x9b0097, 0x006a78, 0xbaa99d, 0x514337, 0xde1100, 0x008f40, 0xae6000, 0x0074e1, 0xc300bd, 0x008697, 0xeae1da, 0xf1ebe6, 0x362c24, 0x362c24, 0xf1ebe6, 0x362c24, 0xf1ebe6}},
{"Breeze", [22]uint32{0x31363b, 0xed1515, 0x11d116, 0xf67400, 0x1d99f3, 0x9b59b6, 0x1abc9c, 0xeff0f1, 0x7f8c8d, 0xc0392b, 0x1cdc9a, 0xfdbc4b, 0x3daee9, 0x8e44ad, 0x16a085, 0xfcfcfc, 0x31363b, 0xeff0f1, 0xeff0f1, 0x31363b, 0xeff0f1, 0x31363b}},
{"Bright Lights", [22]uint32{0x191919, 0xff355b, 0xb7e876, 0xffc251, 0x76d4ff, 0xba76e7, 0x6cbfb5, 0xc2c8d7, 0x4c4c4c, 0xff355b, 0xb7e876, 0xffc251, 0x76d5ff, 0xba76e7, 0x6cbfb5, 0xc2c8d7, 0x191919, 0xb3c9d7, 0xf34b00, 0x002831, 0xb3c9d7, 0x191919}},
{"Broadcast", [22]uint32{0x000000, 0xda4939, 0x519f50, 0xffd24a, 0x6d9cbe, 0xd0d0ff, 0x6e9cbe, 0xffffff, 0x585858, 0xff7b6b, 0x83d182, 0xffff7c, 0x9fcef0, 0xffffff, 0xa0cef0, 0xffffff, 0x2b2b2b, 0xe6e1dc, 0xffffff, 0xc0bbb6, 0x5a647e, 0xe6e1dc}},
{"Brogrammer", [22]uint32{0x1f1f1f, 0xf81118, 0x2dc55e, 0xecba0f, 0x2a84d2, 0x4e5ab7, 0x1081d6, 0xd6dbe5, 0xd6dbe5, 0xde352e, 0x1dd361, 0xf3bd09, 0x1081d6, 0x5350b9, 0x0f7ddb, 0xffffff, 0x131313, 0xd6dbe5, 0xb9b9b9, 0x101010, 0x1f1f1f, 0xd6dbe5}},
{"Builtin Dark", [22]uint32{0x000000, 0xbb0000, 0x00bb00, 0xbbbb00, 0x0d0dc8, 0xbb00bb, 0x00bbbb, 0xbbbbbb, 0x555555, 0xff5555, 0x55ff55, 0xffff55, 0x5555ff, 0xff55ff, 0x55ffff, 0xffffff, 0x000000, 0xbbbbbb, 0xbbbbbb, 0xffffff, 0xb5d5ff, 0x000000}},
{"Builtin Light", [22]uint32{0x000000, 0xbb0000, 0x00bb00, 0xbbbb00, 0x0000bb, 0xbb00bb, 0x00bbbb, 0xbbbbbb, 0x555555, 0xff5555, 0x2fd92f, 0xbfbf15, 0x5555ff, 0xff55ff, 0x22cccc, 0xffffff, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xb5d5ff, 0x000000}},
{"Builtin Pastel Dark", [22]uint32{0x4f4f4f, 0xff6c60, 0xa8ff60, 0xffffb6, 0x96cbfe, 0xff73fd, 0xc6c5fe, 0xeeeeee, 0x7c7c7c, 0xffb6b0, 0xceffac, 0xffffcc, 0xb5dcff, 0xff9cfe, 0xdfdffe, 0xffffff, 0x000000, 0xbbbbbb, 0xffa560, 0xffffff, 0x363983, 0xf2f2f2}},
{"Builtin Tango Dark", [22]uint32{0x000000, 0xcc0000, 0x4e9a06, 0xc4a000, 0x3465a4, 0x75507b, 0x06989a, 0xd3d7cf, 0x555753, 0xef2929, 0x8ae234, 0xfce94f, 0x729fcf, 0xad7fa8, 0x34e2e2, 0xeeeeec, 0x000000, 0xffffff, 0xffffff, 0x000000, 0xb5d5ff, 0x000000}},
{"Builtin Tango Light", [22]uint32{0x000000, 0xcc0000, 0x4e9a06, 0xc4a000, 0x3465a4, 0x75507b, 0x06989a, 0xb9bdb5, 0x555753, 0xef2929, 0x7dd527, 0xd6c329, 0x729fcf, 0xad7fa8, 0x27d5d5, 0xeeeeec, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xb5d5ff, 0x000000}},
{"C64", [22]uint32{0x090300, 0xa2524c, 0x55a049, 0xbfce72, 0x6657b3, 0x984ca3, 0x67b6bd, 0xffffff, 0x000000, 0xa2524c, 0x55a049, 0xbfce72, 0x6657b3, 0x984ca3, 0x67b6bd, 0xf7f7f7, 0x40318d, 0x7869c4, 0x7869c4, 0x40318d, 0x7869c4, 0x40318d}},
{"CGA", [22]uint32{0x000000, 0xaa0000, 0x00aa00, 0xaa5500, 0x0d0db7, 0xaa00aa, 0x00aaaa, 0xaaaaaa, 0x555555, 0xff5555, 0x55ff55, 0xffff55, 0x5555ff, 0xff55ff, 0x55ffff, 0xffffff, 0x000000, 0xaaaaaa, 0xb8b8b8, 0xffffff, 0xc1deff, 0x000000}},
{"CLRS", [22]uint32{0x000000, 0xf8282a, 0x328a5d, 0xfa701d, 0x135cd0, 0x9f00bd, 0x33c3c1, 0xb3b3b3, 0x555753, 0xfb0416, 0x2cc631, 0xe3bd0e, 0x1670ff, 0xe900b0, 0x3ad5ce, 0xeeeeec, 0xffffff, 0x262626, 0x62c6ef, 0xffffff, 0x6fd3fc, 0x041730}},
{"CRT Amber", [22]uint32{0x4c422f, 0xef4444, 0x84cc16, 0xfde68a, 0xc084fc, 0xf97316, 0xf59e0b, 0xd8a657, 0x544435, 0xf26969, 0x9dd645, 0xfdeb9f, 0xcd9dfd, 0xfa8f45, 0xf7b13c, 0xfff3c4, 0x1a1005, 0xfff3c4, 0xfff3c4, 0x1a1005, 0xfff3c4, 0x1a1005}},
{"Calamity", [22]uint32{0x2f2833, 0xfc644d, 0xa5f69c, 0xe9d7a5, 0x3b79c7, 0xf92672, 0x74d3de, 0xd5ced9, 0x7e6c88, 0xfc644d, 0xa5f69c, 0xe9d7a5, 0x3b79c7, 0xf92672, 0x74d3de, 0xffffff, 0x2f2833, 0xd5ced9, 0xd5ced9, 0x2f2833, 0x7e6c88, 0xd5ced9}},
{"Carbonfox", [22]uint32{0x282828, 0xee5396, 0x25be6a, 0x08bdba, 0x78a9ff, 0xbe95ff, 0x33b1ff, 0xdfdfe0, 0x484848, 0xf16da6, 0x46c880, 0x2dc7c4, 0x8cb6ff, 0xc8a5ff, 0x52bdff, 0xe4e4e5, 0x161616, 0xf2f4f8, 0xf2f4f8, 0x161616, 0x2a2a2a, 0xf2f4f8}},
{"Cassette Tape", [22]uint32{0x514339, 0xb91c1c, 0x3f6212, 0xbe123c, 0x7c2d12, 0x0f766e, 0xb45309, 0x6b4f3f, 0xc4b39a, 0x941616, 0x324e0e, 0x9c0f31, 0x63240e, 0x0c5e58, 0x904207, 0x2b1b12, 0xfff7ed, 0x2b1b12, 0x2b1b12, 0xfff7ed, 0x2b1b12, 0xfff7ed}},
{"Catppuccin Frappe", [22]uint32{0x51576d, 0xe78284, 0xa6d189, 0xe5c890, 0x8caaee, 0xf4b8e4, 0x81c8be, 0xb5bfe2, 0x626880, 0xeda0a2, 0xb9dba2, 0xecd7ae, 0xadc2f3, 0xf38ed8, 0x98d2ca, 0xa5adce, 0x303446, 0xc6d0f5, 0xf2d5cf, 0x303446, 0xf2d5cf, 0x303446}},
{"Catppuccin Latte", [22]uint32{0xbcc0cc, 0xd20f39, 0x40a02b, 0xdf8e1d, 0x1e66f5, 0xea76cb, 0x179299, 0x5c5f77, 0xacb0be, 0xe7103f, 0x46b02f, 0xe49931, 0x3878f6, 0xef95d7, 0x19a1a8, 0x6c6f85, 0xeff1f5, 0x4c4f69, 0xdc8a78, 0xeff1f5, 0xdc8a78, 0xeff1f5}},
{"Catppuccin Macchiato", [22]uint32{0x494d64, 0xed8796, 0xa6da95, 0xeed49f, 0x8aadf4, 0xf5bde6, 0x8bd5ca, 0xb8c0e0, 0x5b6078, 0xf2a7b2, 0xbde3b0, 0xf4e3c1, 0xadc5f7, 0xf493da, 0xa5ded6, 0xa5adcb, 0x24273a, 0xcad3f5, 0xf4dbd6, 0x24273a, 0xf4dbd6, 0x24273a}},
{"Catppuccin Mocha", [22]uint32{0x45475a, 0xf38ba8, 0xa6e3a1, 0xf9e2af, 0x89b4fa, 0xf5c2e7, 0x94e2d5, 0xbac2de, 0x585b70, 0xf7aec2, 0xc2ecbf, 0xfcd682, 0xaeccfc, 0xf398da, 0xb1eae1, 0xa6adc8, 0x1e1e2e, 0xcdd6f4, 0xf5e0dc, 0x1e1e2e, 0xf5e0dc, 0x1e1e2e}},
{"Catthode", [22]uint32{0x141414, 0xff6b6b, 0xb9d665, 0xffb86c, 0x9cd9e6, 0xeba4be, 0xaee6d6, 0xb3b3b3, 0x636363, 0xff6b6b, 0xb9d665, 0xfae2c8, 0x9cd9e6, 0xeba4be, 0xaee6d6, 0xffffff, 0x000000, 0xffffff, 0xff9e3b, 0x000000, 0x2d2d2d, 0xffffff}},
{"Chalk", [22]uint32{0x7d8b8f, 0xb23a52, 0x789b6a, 0xb9ac4a, 0x2a7fac, 0xbd4f5a, 0x44a799, 0xd2d8d9, 0x888888, 0xf24840, 0x80c470, 0xffeb62, 0x4196ff, 0xfc5275, 0x53cdbd, 0xd2d8d9, 0x2b2d2e, 0xd2d8d9, 0x708284, 0x002831, 0xe4e8ed, 0x3f4041}},
{"Chalkboard", [22]uint32{0x000000, 0xc37372, 0x72c373, 0xc2c372, 0x7372c3, 0xc372c2, 0x72c2c3, 0xd9d9d9, 0x585858, 0xdbaaaa, 0xaadbaa, 0xdadbaa, 0xaaaadb, 0xdbaada, 0xaadadb, 0xffffff, 0x29262f, 0xd9e6f2, 0xd9e6f2, 0x29262f, 0x073642, 0xffffff}},
{"Challenger Deep", [22]uint32{0x141228, 0xff5458, 0x62d196, 0xffb378, 0x65b2ff, 0x906cff, 0x63f2f1, 0xa6b3cc, 0x565575, 0xff8080, 0x95ffa4, 0xffe9aa, 0x91ddff, 0xc991e1, 0xaaffe4, 0xcbe3e7, 0x1e1c31, 0xcbe1e7, 0xfbfcfc, 0xff271d, 0xcbe1e7, 0x1e1c31}},
{"Chester", [22]uint32{0x080200, 0xfa5e5b, 0x16c98d, 0xffc83f, 0x288ad6, 0xd34590, 0x28ddde, 0xe7e7e7, 0x6f6b68, 0xfa5e5b, 0x16c98d, 0xfeef6d, 0x278ad6, 0xd34590, 0x27dede, 0xffffff, 0x2c3643, 0xffffff, 0xb4b1b1, 0x000000, 0x67747c, 0xffffff}},
{"Ciapre", [22]uint32{0x181818, 0x8e0d16, 0x48513b, 0xcc8b3f, 0x576d8c, 0x724d7c, 0x5c4f4b, 0xaea47f, 0x555555, 0xac3835, 0xa6a75d, 0xdcdf7c, 0x3097c6, 0xd33061, 0xf3dbb2, 0xf4f4f4, 0x191c27, 0xaea47a, 0x92805b, 0x181818, 0x172539, 0xaea47f}},
{"Citrus Ink", [22]uint32{0x14201e, 0xff6b5b, 0x5fd3a0, 0xe6c84a, 0xc2ef45, 0xf2b441, 0xcfe89a, 0xeaf0e2, 0x4f6b5e, 0xff8174, 0x72d8ab, 0xf2a23e, 0xb8e62e, 0xb8e62e, 0xd5eba6, 0xffffff, 0x0b1413, 0xeaf0e2, 0xb8e62e, 0x0b1413, 0x1f302d, 0x4b5453}},
{"Citruszest", [22]uint32{0x404040, 0xff5454, 0x00cc7a, 0xffd400, 0x00bfff, 0xff90fe, 0x48d1cc, 0xbfbfbf, 0x808080, 0xff1a75, 0x1affa3, 0xffff00, 0x33cfff, 0xffb2fe, 0x00fff2, 0xf9f9f9, 0x121212, 0xbfbfbf, 0x666666, 0xf9f9f9, 0xff8c00, 0xf4f4f4}},
{"Claude", [22]uint32{0xc15f3c, 0x788c5d, 0xb16803, 0x6a9bcc, 0x8b6cb0, 0x2e8b8b, 0xb5b3a9, 0x3d3d3c, 0xd97757, 0x8fa86b, 0xd4952b, 0x7bafd4, 0xa080c8, 0x4eaaaa, 0xbab9b5, 0x141413, 0xfaf9f5, 0x141413, 0xd97757, 0xfaf9f5, 0xe8e6dc, 0x141413}},
{"Claude Dark", [22]uint32{0x888681, 0xd47563, 0x9aca86, 0xe8c96b, 0x6a9bcc, 0x9b87f5, 0x3cbe8c, 0xe2e1da, 0xa6a59b, 0xf4a9a9, 0xa8d166, 0xfab319, 0x9fc5f4, 0xf3aac5, 0x79d7b3, 0xefeeeb, 0x262624, 0xe5e4e1, 0xd97757, 0x262624, 0x363634, 0xe5e4e1}},
{"Claude Light", [22]uint32{0x0a0a0a, 0xa84b3a, 0x2e7c4c, 0x8a6220, 0x184e95, 0x882b4d, 0x066049, 0xb6b5aa, 0x51504d, 0xe34a4a, 0x639900, 0xb87700, 0x3886e5, 0xd55382, 0x199f70, 0xe2e1da, 0xfaf9f5, 0x141413, 0xd97757, 0xfaf9f5, 0xf0eee6, 0x141413}},
{"Clear Dark", [22]uint32{0x35424c, 0xb45648, 0x6caa71, 0xc4ac62, 0x6d96b4, 0xbd7bcd, 0x7ccbcd, 0xdee5eb, 0x465c6d, 0xdf6c5a, 0x79be7e, 0xe5c872, 0x67b5ed, 0xd389e5, 0x84dde0, 0xe5eff5, 0x212734, 0xe6e6e6, 0x9d9d9d, 0x212734, 0x334e5e, 0x6e7380}},
{"Clear Light", [22]uint32{0x2d3840, 0xb45648, 0x6caa71, 0xc4ac62, 0x5685a8, 0xad64be, 0x69c6c9, 0xb4bbbf, 0x506573, 0xdf6c5a, 0x79be7e, 0xd8bb65, 0x49a2e1, 0xd389e5, 0x5ec7cb, 0xd8e1e7, 0xffffff, 0x3a4851, 0x919191, 0xffffff, 0xe5ecf1, 0xb2b2b2}},
{"Cobalt Neon", [22]uint32{0x142631, 0xff2320, 0x3ba5ff, 0xe9e75c, 0x8ff586, 0x781aa0, 0x8ff586, 0xba46b2, 0xfff688, 0xd4312e, 0x8ff586, 0xe9f06d, 0x3c7dd2, 0x8230a7, 0x6cbc67, 0x8ff586, 0x142838, 0x8ff586, 0xc4206f, 0x8ff586, 0x094fb1, 0x8ff586}},
{"Cobalt Next", [22]uint32{0x000000, 0xff527b, 0x8cc98f, 0xffc64c, 0x409dd4, 0xcba3c7, 0x37b5b4, 0xd7deea, 0x62747f, 0xe47e8b, 0xbaddbb, 0xffdc91, 0x7ac0eb, 0xf3ccef, 0x84e4e3, 0xffffff, 0x162c35, 0xd7deea, 0xffc64c, 0x8a919d, 0x4c5b67, 0xffffff}},
{"Cobalt Next Dark", [22]uint32{0x262f37, 0xf94967, 0x8cc98f, 0xffc64c, 0x409dd4, 0xcba3c7, 0x37b5b4, 0xd7deea, 0x62747f, 0xe47e8b, 0xbaddbb, 0xffdc91, 0x7ac0eb, 0xf3ccef, 0x84e4e3, 0xffffff, 0x0b1c24, 0xd7deea, 0xffc64c, 0x999999, 0x37b5b4, 0xffffff}},
{"Cobalt Next Minimal", [22]uint32{0x323d47, 0xff657a, 0x8cc98f, 0xffc64c, 0x409dd4, 0xcba3c7, 0x37b5b4, 0xd7deea, 0x62747f, 0xe47e8b, 0xbaddbb, 0xffdc91, 0x7ac0eb, 0xf3ccef, 0x84e4e3, 0xffffff, 0x0b1c24, 0xd7deea, 0x37b5b4, 0xffffff, 0x37b5b4, 0xffffff}},
{"Cobalt2", [22]uint32{0x000000, 0xff0000, 0x38de21, 0xffe50a, 0x1460d2, 0xff005d, 0x00bbbb, 0xbbbbbb, 0x555555, 0xf40e17, 0x3bd01d, 0xedc809, 0x5555ff, 0xff55ff, 0x6ae3fa, 0xffffff, 0x132738, 0xffffff, 0xf0cc09, 0x98998c, 0x18354f, 0xb5b5b5}},
{"Coffee Theme", [22]uint32{0x000000, 0xc91b00, 0x00c200, 0xadaa00, 0x0225c7, 0xca30c7, 0x00b8ba, 0xa1a1a1, 0x686868, 0xff6e67, 0x1fba28, 0xb2af1b, 0x6871ff, 0xf26af2, 0x20bdbf, 0xffffff, 0xf5deb3, 0x000000, 0xa1a1a1, 0xfffc67, 0xc1deff, 0x000000}},
{"Cool Night", [22]uint32{0x0b3b61, 0xff3a3a, 0x52ffd0, 0xfff383, 0x1376f9, 0xc792ea, 0xff5ed4, 0x16fda2, 0x63686d, 0xff54b0, 0x74ffd8, 0xfcf5ae, 0x388eff, 0xae81ff, 0xff6ad7, 0x60fbbf, 0x010c18, 0xecdef4, 0x38ff9d, 0x000000, 0x38ff9c, 0x000000}},
{"Crayon Pony Fish", [22]uint32{0x2b1b1d, 0x91002b, 0x579524, 0xab311b, 0x8c87b0, 0x692f50, 0xe8a866, 0x68525a, 0x4a383b, 0xc5255d, 0x8dff57, 0xc8381d, 0xcfc9ff, 0xfc6cba, 0xffceaf, 0xb0949d, 0x150707, 0x68525a, 0x68525a, 0x140707, 0x2b1b1d, 0x69525a}},
{"Cursor Dark", [22]uint32{0x242424, 0xfc6b83, 0x3fa266, 0xd2943e, 0x81a1c1, 0xb48ead, 0x88c0d0, 0xe4e4e4, 0x4a4a4a, 0xfc6b83, 0x70b489, 0xf1b467, 0x87a6c4, 0xb48ead, 0x88c0d0, 0xe4e4e4, 0x141414, 0xd4d4d4, 0xd4d4d4, 0x141414, 0x2c2c2c, 0xe4e4e4}},
{"Cursor Light", [22]uint32{0x252525, 0xcf2d56, 0x1f8a65, 0xa16900, 0x3c7cab, 0xb8448b, 0x4c7f8c, 0xafafaf, 0x5c5c5c, 0xe75e78, 0x55a583, 0xc08532, 0x6299c3, 0xd06ba6, 0x6f9ba6, 0xffffff, 0xf3f3f3, 0x252525, 0x252525, 0xf3f3f3, 0xd9d9d9, 0x252525}},
{"Cutie Pro", [22]uint32{0x000000, 0xf56e7f, 0xbec975, 0xf58669, 0x42d9c5, 0xd286b7, 0x37cb8a, 0xd5c3c3, 0x88847f, 0xe5a1a3, 0xe8d6a7, 0xf1bb79, 0x80c5de, 0xb294bb, 0x9dccbb, 0xffffff, 0x181818, 0xd5d0c9, 0xefc4cd, 0x181818, 0x363636, 0xd5d0c9}},
{"Cyberdyne", [22]uint32{0x080808, 0xff8373, 0x00c172, 0xd2a700, 0x0071cf, 0xff90fe, 0x6bffdd, 0xf1f1f1, 0x484848, 0xffc4be, 0xd6fcba, 0xfffed5, 0xc2e3ff, 0xffb2fe, 0xe6e7fe, 0xffffff, 0x151144, 0x00ff92, 0x00ff9c, 0xa6a6a6, 0x454d96, 0xf4f4f4}},
{"Cyberpunk", [22]uint32{0x000000, 0xff7092, 0x00fbac, 0xfffa6a, 0x00bfff, 0xdf95ff, 0x86cbfe, 0xffffff, 0x595959, 0xff8aa4, 0x21f6bc, 0xfff787, 0x1bccfd, 0xe6aefe, 0x99d6fc, 0xffffff, 0x332a57, 0xe5e5e5, 0x21f6bc, 0x999999, 0xc1deff, 0x000000}},
{"Cyberpunk Scarlet Protocol", [22]uint32{0x101116, 0xff0051, 0x01dc84, 0xfaf945, 0x0271b6, 0xc930c7, 0x00c5c7, 0xc7c7c7, 0x686868, 0xff6e67, 0x60fa68, 0xfffc67, 0x6871ff, 0xbd35ec, 0x60fdff, 0xffffff, 0x101116, 0xe41951, 0x76ff9f, 0xa6a6a6, 0xc1deff, 0x000000}},
{"Dalton Dark", [22]uint32{0x282828, 0xd85050, 0x5b914e, 0xc4c40c, 0x7aa2f7, 0xa050d0, 0x56717f, 0xb8b8b8, 0x494949, 0xf07068, 0x88b97d, 0xeded02, 0x97b1f1, 0xc070f0, 0x6691a7, 0xd8d8d8, 0x1b1b1b, 0xc8c9cc, 0x9a9a9a, 0x1b1b1b, 0xc8c9cc, 0x1b1b1b}},
{"Dark Modern", [22]uint32{0x272727, 0xf74949, 0x2ea043, 0x9e6a03, 0x0078d4, 0xd01273, 0x1db4d6, 0xcccccc, 0x5d5d5d, 0xdc5452, 0x23d18b, 0xf5f543, 0x3b8eea, 0xd670d6, 0x29b8db, 0xe5e5e5, 0x1f1f1f, 0xcccccc, 0xffffff, 0x000000, 0x3a3d41, 0xe0e0e0}},
{"Dark Pastel", [22]uint32{0x000000, 0xff5555, 0x55ff55, 0xffff55, 0x5555ff, 0xff55ff, 0x55ffff, 0xbbbbbb, 0x555555, 0xff5555, 0x55ff55, 0xffff55, 0x5555ff, 0xff55ff, 0x55ffff, 0xffffff, 0x000000, 0xffffff, 0xbbbbbb, 0xffffff, 0xb5d5ff, 0x000000}},
{"Dark+", [22]uint32{0x000000, 0xcd3131, 0x0dbc79, 0xe5e510, 0x2472c8, 0xbc3fbc, 0x11a8cd, 0xe5e5e5, 0x666666, 0xf14c4c, 0x23d18b, 0xf5f543, 0x3b8eea, 0xd670d6, 0x29b8db, 0xe5e5e5, 0x1e1e1e, 0xcccccc, 0xffffff, 0x000000, 0x3a3d41, 0xe0e0e0}},
{"Darkermatrix", [22]uint32{0x091013, 0x1a4831, 0x6fa64c, 0x595900, 0x00cb6b, 0x4e375a, 0x125459, 0x1a4833, 0x404040, 0x0d452a, 0x90d762, 0xe2e500, 0x00ff87, 0x4e375a, 0x176c73, 0x00381e, 0x070c0e, 0x35451a, 0x444733, 0x00ff87, 0x0f191c, 0x00ff87}},
{"Darkmatrix", [22]uint32{0x091013, 0x006536, 0x6fa64c, 0x7e8000, 0x2c9a84, 0x523a60, 0x114d53, 0x006536, 0x404040, 0x00733d, 0x90d762, 0xe2e500, 0x46d8b8, 0x573d66, 0x12545a, 0x006536, 0x070c0e, 0x3e5715, 0x9fa86e, 0x00ff87, 0x0f191c, 0x00ff87}},
{"Darkside", [22]uint32{0x000000, 0xe8341c, 0x68c256, 0xf2d42c, 0x1c98e8, 0x8e69c9, 0x1c98e8, 0xbababa, 0x4c4c4c, 0xe05a4f, 0x77b869, 0xefd64b, 0x387cd3, 0x957bbe, 0x3d97e2, 0xbababa, 0x222324, 0xbababa, 0xbbbbbb, 0xffffff, 0x303333, 0xbababa}},
{"Dawnfox", [22]uint32{0x575279, 0xb4637a, 0x618774, 0xea9d34, 0x286983, 0x907aa9, 0x56949f, 0xb2b6bd, 0x5f5695, 0xc26d85, 0x629f81, 0xeea846, 0x2d81a3, 0x9a80b9, 0x5ca7b4, 0xe6ebf3, 0xfaf4ed, 0x575279, 0x575279, 0xfaf4ed, 0xd0d8d8, 0x575279}},
{"Daybreak", [22]uint32{0x44413b, 0xaf2817, 0x3c6a12, 0x795900, 0x186875, 0x754193, 0x006a62, 0x6e6b62, 0x8c8579, 0xc03a27, 0x538625, 0x9a4c1f, 0x207887, 0x8552a3, 0x087a71, 0x2e2c27, 0xf3efe8, 0x44413b, 0xa25327, 0xf3efe8, 0xe2daca, 0xa6a29b}},
{"Dayfox", [22]uint32{0x352c24, 0xa5222f, 0x396847, 0xac5402, 0x2848a9, 0x6e33ce, 0x287980, 0xbfb6ae, 0x534c45, 0xb3434e, 0x577f63, 0xb86e28, 0x4863b6, 0x8452d5, 0x488d93, 0xf4ece6, 0xf6f2ee, 0x3d2b5a, 0x3d2b5a, 0xf6f2ee, 0xe7d2be, 0x3d2b5a}},
{"Deep", [22]uint32{0x000000, 0xd70005, 0x1cd915, 0xd9bd26, 0x5665ff, 0xb052da, 0x50d2da, 0xe0e0e0, 0x535353, 0xfb0007, 0x22ff18, 0xfedc2b, 0x9fa9ff, 0xe09aff, 0x8df9ff, 0xffffff, 0x090909, 0xcdcdcd, 0xd0d0d0, 0x151515, 0x780002, 0xececec}},
{"Desert", [22]uint32{0x4d4d4d, 0xff2b2b, 0x98fb98, 0xf0e68c, 0xcd853f, 0xffdead, 0xffa0a0, 0xf5deb3, 0x626262, 0xff5555, 0x55ff55, 0xffff55, 0x87ceff, 0xff55ff, 0xffd700, 0xffffff, 0x333333, 0xffffff, 0x00ff00, 0x000000, 0xb5d5ff, 0x000000}},
{"Detuned", [22]uint32{0x171717, 0xfe4386, 0xa6e32d, 0xe6da73, 0x0094d9, 0x9b37ff, 0x50b7d9, 0xc7c7c7, 0x686868, 0xfa80ac, 0xbde371, 0xfff27f, 0x00beff, 0xbe9eff, 0x5ed7ff, 0xffffff, 0x000000, 0xc7c7c7, 0xc7c7c7, 0x8c8c8c, 0xc1deff, 0x000000}},
{"Dimidium", [22]uint32{0x000000, 0xcf494c, 0x60b442, 0xdb9c11, 0x0575d8, 0xaf5ed2, 0x1db6bb, 0xbab7b6, 0x817e7e, 0xff643b, 0x37e57b, 0xfccd1a, 0x688dfd, 0xed6fe9, 0x32e0fb, 0xdee3e4, 0x141414, 0xbab7b6, 0x37e57b, 0x141414, 0x8db8e5, 0x141414}},
{"Dimmed Monokai", [22]uint32{0x3a3d43, 0xbe3f48, 0x879a3b, 0xc5a635, 0x4f76a1, 0x855c8d, 0x578fa4, 0xb9bcba, 0x888987, 0xfb001f, 0x0f722f, 0xc47033, 0x186de3, 0xfb0067, 0x2e706d, 0xfdffb9, 0x1f1f1f, 0xb9bcba, 0xf83e19, 0x171717, 0x2a2d32, 0xb9bcba}},
{"Django", [22]uint32{0x000000, 0xfd6209, 0x41a83e, 0xffe862, 0x315d3f, 0xf8f8f8, 0x9df39f, 0xffffff, 0x585858, 0xff943b, 0x73da70, 0xffff94, 0x568264, 0xffffff, 0xcfffd1, 0xffffff, 0x0b2f20, 0xf8f8f8, 0x336442, 0xf8f8f8, 0x245032, 0xf8f8f8}},
{"Django Reborn Again", [22]uint32{0x000000, 0xfd6209, 0x41a83e, 0xffe862, 0x245032, 0xf8f8f8, 0x9df39f, 0xffffff, 0x4c4c4c, 0xff943b, 0x73da70, 0xffff94, 0x568264, 0xffffff, 0xcfffd1, 0xffffff, 0x051f14, 0xdadedc, 0xffcc00, 0x9a9e9c, 0x203727, 0xdadedc}},
{"Django Smooth", [22]uint32{0x000000, 0xfd6209, 0x41a83e, 0xffe862, 0x989898, 0xf8f8f8, 0x9df39f, 0xe8e8e7, 0x727272, 0xff943b, 0x73da70, 0xffff94, 0xcacaca, 0xffffff, 0xcfffd1, 0xffffff, 0x245032, 0xf8f8f8, 0x4c7e5c, 0xf8f8f8, 0x336442, 0xf8f8f8}},
{"Dogxi Misty", [22]uint32{0x000000, 0xff5c57, 0x94e362, 0xeebd70, 0x99ecfe, 0xff6ac1, 0x5fdeed, 0xf1f1f0, 0x686868, 0xff5c57, 0x94e362, 0xefc781, 0x99ecfe, 0xff6ac1, 0x87e0f0, 0xf1f1f0, 0x282a36, 0xeff0eb, 0xeaeaea, 0x282a36, 0x92bcd0, 0x000000}},
{"Doom One", [22]uint32{0x000000, 0xff6c6b, 0x98be65, 0xecbe7b, 0xa9a1e1, 0xc678dd, 0x51afef, 0xbbc2cf, 0x595959, 0xff6655, 0x99bb66, 0xecbe7b, 0xa9a1e1, 0xc678dd, 0x51afef, 0xbfbfbf, 0x282c34, 0xbbc2cf, 0x51afef, 0x1b1b1b, 0x42444b, 0xbbc2cf}},
{"Doom Peacock", [22]uint32{0x1c1f24, 0xcb4b16, 0x26a6a6, 0xbcd42a, 0x2a6cc6, 0xa9a1e1, 0x5699af, 0xede0ce, 0x51504d, 0xff5d38, 0x98be65, 0xe6f972, 0x51afef, 0xc678dd, 0x46d9ff, 0xdfdfdf, 0x2b2a27, 0xede0ce, 0x9c9c9d, 0x36312b, 0xa60033, 0xffffff}},
{"Dot Gov", [22]uint32{0x191919, 0xbf091d, 0x3d9751, 0xf6bb34, 0x17b2e0, 0x7830b0, 0x8bd2ed, 0xffffff, 0x595959, 0xbf091d, 0x3d9751, 0xf6bb34, 0x17b2e0, 0x7830b0, 0x8bd2ed, 0xffffff, 0x262c35, 0xebebeb, 0xd9002f, 0xffffff, 0x1a4080, 0xffffff}},
{"Dracula", [22]uint32{0x21222c, 0xff5555, 0x50fa7b, 0xf1fa8c, 0xbd93f9, 0xff79c6, 0x8be9fd, 0xf8f8f2, 0x6272a4, 0xff6e6e, 0x69ff94, 0xffffa5, 0xd6acff, 0xff92df, 0xa4ffff, 0xffffff, 0x282a36, 0xf8f8f2, 0xf8f8f2, 0x282a36, 0x44475a, 0xffffff}},
{"Dracula+", [22]uint32{0x21222c, 0xff5555, 0x50fa7b, 0xffcb6b, 0x82aaff, 0xc792ea, 0x8be9fd, 0xf8f8f2, 0x545454, 0xff6e6e, 0x69ff94, 0xffcb6b, 0xd6acff, 0xff92df, 0xa4ffff, 0xf8f8f2, 0x212121, 0xf8f8f2, 0xeceff4, 0x282828, 0xf8f8f2, 0x545454}},
{"Driftwood", [22]uint32{0x211d19, 0xe77467, 0xaab971, 0xe1b869, 0x78b3b5, 0xc9a0bd, 0xa5c4b1, 0xc2b7a6, 0x9a8e7c, 0xf38f7e, 0xbecc8a, 0xe39962, 0x92c6c7, 0xdab6d1, 0xbbd6c3, 0xf2eadb, 0x2a2622, 0xe6ddd0, 0xdfb666, 0x2a2622, 0x39332b, 0x5d5955}},
{"Duckbones", [22]uint32{0x0e101a, 0xe03600, 0x5dcd97, 0xe39500, 0x00a3cb, 0x795ccc, 0x00a3cb, 0xebefc0, 0x444860, 0xff4821, 0x58db9e, 0xf6a100, 0x00b4e0, 0xb3a1e6, 0x00b4e0, 0xb3b692, 0x0e101a, 0xebefc0, 0xedf2c2, 0x0e101a, 0x37382d, 0xebefc0}},
{"Duotone Dark", [22]uint32{0x1f1d27, 0xd9393e, 0x2dcd73, 0xd9b76e, 0xffc284, 0xde8d40, 0x2488ff, 0xb7a1ff, 0x4e4a60, 0xd9393e, 0x2dcd73, 0xd9b76e, 0xffc284, 0xde8d40, 0x2488ff, 0xeae5ff, 0x1f1d27, 0xb7a1ff, 0xff9839, 0x1f1d27, 0x353147, 0xb7a2ff}},
{"Duskfox", [22]uint32{0x393552, 0xeb6f92, 0xa3be8c, 0xf6c177, 0x569fba, 0xc4a7e7, 0x9ccfd8, 0xe0def4, 0x544d8a, 0xf083a2, 0xb1d196, 0xf9cb8c, 0x65b1cd, 0xccb1ed, 0xa6dae3, 0xe2e0f7, 0x232136, 0xe0def4, 0xe0def4, 0x232136, 0x433c59, 0xe0def4}},
{"ENCOM", [22]uint32{0x000000, 0x9f0000, 0x008b00, 0xffd000, 0x0081ff, 0xbc00ca, 0x008b8b, 0xbbbbbb, 0x555555, 0xff0000, 0x00ee00, 0xffff00, 0x0000ff, 0xff00ff, 0x00cdcd, 0xffffff, 0x000000, 0x00a595, 0xbbbbbb, 0xffffff, 0x00a48c, 0x3de1c9}},
{"Earl Grey", [22]uint32{0x605a52, 0x8f5652, 0x747b4d, 0x897d43, 0x556995, 0x83577d, 0x477a7b, 0xc2beb8, 0xa8a094, 0x82403c, 0x656d37, 0x796d2f, 0x3e5588, 0x77406f, 0x326b6c, 0xc2beb8, 0xfcfbf9, 0x605a52, 0x605a52, 0xfcfbf9, 0xe1ddd6, 0x605a52}},
{"Earthsong", [22]uint32{0x121418, 0xc94234, 0x85c54c, 0xf5ae2e, 0x1398b9, 0xd0633d, 0x509552, 0xe5c6aa, 0x675f54, 0xff645a, 0x98e036, 0xe0d561, 0x5fdaff, 0xff9269, 0x84f088, 0xf6f7ec, 0x292520, 0xe5c7a9, 0xf6f7ec, 0x292520, 0x121418, 0xe5c7a9}},
{"Eclipse", [22]uint32{0x0a0d12, 0xff6366, 0x85df5e, 0xf1c655, 0x5fb9ff, 0xcea5ff, 0x3addc4, 0xb7c0ce, 0x5c6675, 0xff8688, 0xa0ec7e, 0xfad77c, 0x84ccff, 0xddbfff, 0x68ead3, 0xf4f8fd, 0x0e1116, 0xdce3ed, 0xf6c45f, 0x0e1116, 0x25324a, 0x5a5e62}},
{"Electron Highlighter", [22]uint32{0x15161f, 0xff6c8d, 0x00ffc3, 0xffebb1, 0x77abff, 0xdaa4f4, 0x00e5ff, 0x7187b7, 0x4b5b8c, 0xff6c8d, 0x00ffc3, 0xffebb1, 0x77abff, 0xdaa4f4, 0x00e5ff, 0xc3cde2, 0x23283d, 0xa5b6d4, 0xa5b6d4, 0x171b29, 0x293257, 0xa5b6d4}},
{"Electron Highlighter Day", [22]uint32{0xc2c6d4, 0xf52a65, 0x10a877, 0xdf8e1d, 0x366ff0, 0x8b4fe0, 0x0a9fbf, 0x59647e, 0x7b88a8, 0xf52a65, 0x10a877, 0xdf8e1d, 0x366ff0, 0x8b4fe0, 0x0a9fbf, 0x2f3b54, 0xeef0f5, 0x2f3b54, 0x2f3b54, 0xeef0f5, 0xd6def5, 0x2f3b54}},
{"Elegant", [22]uint32{0x0a1222, 0xff0257, 0x85cc95, 0xffcb8b, 0x8dabe1, 0xc792eb, 0x78ccf0, 0xffffff, 0x575656, 0xff0057, 0x85cc95, 0xffcb8b, 0x8dabe1, 0xc792eb, 0x3facef, 0xffffff, 0x292b31, 0xced2d6, 0x00beff, 0xffffff, 0xd5d5d5, 0x144385}},
{"Elemental", [22]uint32{0x3c3c30, 0x98290f, 0x479a43, 0x7f7111, 0x497f7d, 0x7f4e2f, 0x387f58, 0x807974, 0x555445, 0xe0502a, 0x61e070, 0xd69927, 0x79d9d9, 0xcd7c54, 0x59d599, 0xfff1e9, 0x22211d, 0x807a74, 0xfacb80, 0x161611, 0x413829, 0xfacd77}},
{"Elementary", [22]uint32{0x242424, 0xd71c15, 0x5aa513, 0xfdb40c, 0x134899, 0xe40038, 0x2595e1, 0xefefef, 0x4b4b4b, 0xfc1c18, 0x6bc219, 0xfec80e, 0x0955ff, 0xfb0050, 0x3ea8fc, 0x8c00ec, 0x181818, 0xefefef, 0xbbbbbb, 0xffffff, 0xb5d5ff, 0x000000}},
{"Embark", [22]uint32{0x1e1c31, 0xf0719b, 0xa1efd3, 0xffe9aa, 0x57c7ff, 0xc792ea, 0x87dfeb, 0xf8f8f2, 0x585273, 0xf02e6e, 0x2ce592, 0xffb378, 0x1da0e2, 0xa742ea, 0x63f2f1, 0xa6b3cc, 0x1e1c31, 0xeeffff, 0xa1efd3, 0x1e1c31, 0xfbfcfc, 0x1e1c31}},
{"Embers Dark", [22]uint32{0x16130f, 0x826d57, 0x57826d, 0x6d8257, 0x6d5782, 0x82576d, 0x576d82, 0xa39a90, 0x5a5047, 0x828257, 0x464039, 0x50483f, 0x8a8075, 0xbeb6ae, 0x825757, 0xdbd6d1, 0x16130f, 0xa39a90, 0xa39a90, 0x16130f, 0x433b32, 0xa39a90}},
{"Emerald Synth", [22]uint32{0x0a0118, 0xff2a6d, 0x00e67e, 0xffcc66, 0x8b9cf7, 0xff79c6, 0x4dd0e1, 0xf0e6ff, 0x6a5585, 0xff5c8a, 0x40ffdd, 0xffe099, 0xb0b8fc, 0xff9ed0, 0x7ee0ec, 0xffffff, 0x0d0221, 0x00ffcc, 0xff79c6, 0x0d0221, 0x2e6b5f, 0x00ffcc}},
{"Espresso", [22]uint32{0x353535, 0xd25252, 0xa5c261, 0xffc66d, 0x6c99bb, 0xd197d9, 0xbed6ff, 0xeeeeec, 0x606060, 0xf00c0c, 0xc2e075, 0xe1e48b, 0x8ab7d9, 0xefb5f7, 0xdcf4ff, 0xffffff, 0x323232, 0xffffff, 0xd6d6d6, 0x999999, 0x5b5b5b, 0xffffff}},
{"Espresso Libre", [22]uint32{0x000000, 0xcc0000, 0x1a921c, 0xf0e53a, 0x0066ff, 0xc5656b, 0x06989a, 0xd3d7cf, 0x555753, 0xef2929, 0x9aff87, 0xfffb5c, 0x43a8ed, 0xff818a, 0x34e2e2, 0xeeeeec, 0x2a211c, 0xb8a898, 0xffffff, 0x000000, 0xc3dcff, 0xab9b8b}},
{"Everblush", [22]uint32{0x232a2d, 0xe57474, 0x8ccf7e, 0xe5c76b, 0x67b0e8, 0xc47fd5, 0x6cbfbf, 0xb3b9b8, 0x464e50, 0xef7e7e, 0x96d988, 0xf4d67a, 0x71baf2, 0xce89df, 0x67cbe7, 0xbdc3c2, 0x141b1e, 0xdadada, 0xdadada, 0x141b1e, 0x141b1e, 0xdadada}},
{"Everforest Dark Hard", [22]uint32{0x7a8478, 0xe67e80, 0xa7c080, 0xdbbc7f, 0x7fbbb3, 0xd699b6, 0x83c092, 0xf2efdf, 0xa6b0a0, 0xf85552, 0x8da101, 0xdfa000, 0x3a94c5, 0xdf69ba, 0x35a77c, 0xfffbef, 0x1e2326, 0xd3c6aa, 0xe69875, 0x4c3743, 0x4c3743, 0xd3c6aa}},
{"Everforest Dark Med", [22]uint32{0x7a8478, 0xe67e80, 0xa7c080, 0xdbbc7f, 0x7fbbb3, 0xd699b6, 0x83c092, 0xf2efdf, 0xa6b0a0, 0xf85552, 0x8da101, 0xdfa000, 0x3a94c5, 0xdf69ba, 0x35a77c, 0xfffbef, 0x232a2e, 0xd3c6aa, 0xe69875, 0x543a48, 0x543a48, 0xd3c6aa}},
{"Everforest Dark Soft", [22]uint32{0x7a8478, 0xe67e80, 0xa7c080, 0xdbbc7f, 0x7fbbb3, 0xd699b6, 0x83c092, 0xf2efdf, 0xa6b0a0, 0xf85552, 0x8da101, 0xdfa000, 0x3a94c5, 0xdf69ba, 0x35a77c, 0xfffbef, 0x293136, 0xd3c6aa, 0xe69875, 0x5c3f4f, 0x5c3f4f, 0xd3c6aa}},
{"Everforest Light Hard", [22]uint32{0x7a8478, 0xe67e80, 0x9ab373, 0xceaf72, 0x7fbbb3, 0xd699b6, 0x83c092, 0xb2af9f, 0xa6b0a0, 0xf85552, 0x8da101, 0xdfa000, 0x3a94c5, 0xdf69ba, 0x35a77c, 0xfffbef, 0xf2efdf, 0x5c6a72, 0xf57d26, 0xf0f2d4, 0xf0f2d4, 0x5c6a72}},
{"Everforest Light Med", [22]uint32{0x7a8478, 0xe67e80, 0x9ab373, 0xc1a266, 0x7fbbb3, 0xd699b6, 0x83c092, 0xb2af9f, 0xa6b0a0, 0xf85552, 0x8da101, 0xdfa000, 0x3a94c5, 0xdf69ba, 0x35a77c, 0xfffbef, 0xefebd4, 0x5c6a72, 0xf57d26, 0xeaedc8, 0xeaedc8, 0x5c6a72}},
{"Everforest Light Soft", [22]uint32{0x7a8478, 0xe67e80, 0x8da666, 0xc1a266, 0x72aea6, 0xc98ca9, 0x76b385, 0xa5a292, 0x99a393, 0xf85552, 0x8da101, 0xd29300, 0x3a94c5, 0xdf69ba, 0x35a77c, 0xfffbef, 0xe5dfc5, 0x5c6a72, 0xf57d26, 0xe1e4bd, 0xe1e4bd, 0x5c6a72}},
{"Fahrenheit", [22]uint32{0x1d1d1d, 0xcda074, 0x9e744d, 0xfecf75, 0x7f0e0f, 0x734c4d, 0x979797, 0xffffce, 0x404040, 0xfecea0, 0xcc734d, 0xfd9f4d, 0xcb4a05, 0x4e739f, 0xfed04d, 0xffffff, 0x000000, 0xffffce, 0xbbbbbb, 0xffffff, 0x4e739f, 0xffffce}},
{"Fairyfloss", [22]uint32{0x040303, 0xf92672, 0xc2ffdf, 0xe6c000, 0xc2ffdf, 0xffb8d1, 0xc5a3ff, 0xf8f8f0, 0x6090cb, 0xff857f, 0xc2ffdf, 0xffea00, 0xc2ffdf, 0xffb8d1, 0xc5a3ff, 0xf8f8f0, 0x5a5475, 0xf8f8f2, 0xf8f8f0, 0x060709, 0x8077a8, 0xf6e1ce}},
{"Farmhouse Dark", [22]uint32{0x1d2027, 0xba0004, 0x549d00, 0xc87300, 0x0049e6, 0x9f1b61, 0x1fb65c, 0xe8e4e1, 0x464d54, 0xeb0009, 0x7ac100, 0xea9a00, 0x006efe, 0xbf3b7f, 0x19e062, 0xf4eef0, 0x1d2027, 0xe8e4e1, 0x006efe, 0xe8e4e1, 0x4d5658, 0xb3b1aa}},
{"Farmhouse Light", [22]uint32{0x1d2027, 0x8d0003, 0x3a7d00, 0xa95600, 0x092ccd, 0x820046, 0x229256, 0xa8a4a1, 0x394047, 0xeb0009, 0x7ac100, 0xea9a00, 0x006efe, 0xbf3b7f, 0x00c649, 0xf4eef0, 0xe8e4e1, 0x1d2027, 0x006efe, 0x1d2027, 0xb3b1aa, 0x4d5658}},
{"Fideloper", [22]uint32{0x292f33, 0xcb1e2d, 0xedb8ac, 0xb7ab9b, 0x2e78c2, 0xc0236f, 0x309186, 0xeae3ce, 0x496068, 0xd4605a, 0xd4605a, 0xa86671, 0x7c85c4, 0x5c5db2, 0x819090, 0xfcf4df, 0x292f33, 0xdbdae0, 0xd4605a, 0xfefff2, 0xefb8ac, 0x8c8c8c}},
{"Firefly Traditional", [22]uint32{0x000000, 0xc23720, 0x33bc26, 0xafad24, 0x5a63ff, 0xd53ad2, 0x33bbc7, 0xcccccc, 0x828282, 0xff3b1e, 0x2ee720, 0xecec16, 0x838dff, 0xff5cfe, 0x29f0f0, 0xebebeb, 0x000000, 0xf5f5f5, 0x00f900, 0x999999, 0xcfeac6, 0x000000}},
{"Firefox Dev", [22]uint32{0x002831, 0xe63853, 0x5eb83c, 0xa57706, 0x359ddf, 0xd75cff, 0x4b73a2, 0xdcdcdc, 0x26444d, 0xe1003f, 0x1d9000, 0xcd9409, 0x006fc0, 0xa200da, 0x005794, 0xe2e2e2, 0x0e1011, 0x7c8fa4, 0x708284, 0x002831, 0x163c61, 0xf2f5f9}},
{"Firewatch", [22]uint32{0x585f6d, 0xd95360, 0x5ab977, 0xdfb563, 0x4d89c4, 0xd55119, 0x44a8b6, 0xe6e5ff, 0x585f6d, 0xd95360, 0x5ab977, 0xdfb563, 0x4c89c5, 0xd55119, 0x44a8b6, 0xe6e5ff, 0x1e2027, 0x9ba2b2, 0xf6f7ec, 0xb7b8a8, 0x2f363e, 0x7d8fa4}},
{"Fish Tank", [22]uint32{0x03073c, 0xc6004a, 0xacf157, 0xfecd5e, 0x525fb8, 0x986f82, 0x968763, 0xecf0fc, 0x6c5b30, 0xda4b8a, 0xdbffa9, 0xfee6a9, 0xb2befa, 0xfda5cd, 0xa5bd86, 0xf6ffec, 0x232537, 0xecf0fe, 0xfecd5e, 0x232537, 0xfcf7e9, 0x232537}},
{"Flat", [22]uint32{0x222d3f, 0xa82320, 0x32a548, 0xe58d11, 0x3167ac, 0x781aa0, 0x2c9370, 0xb0b6ba, 0x475262, 0xd4312e, 0x2d9440, 0xe5be0c, 0x3c7dd2, 0x8230a7, 0x35b387, 0xe7eced, 0x002240, 0x2cc55d, 0xe5be0c, 0xffffff, 0x792b9c, 0xffffff}},
{"Flatland", [22]uint32{0x1d1d19, 0xf18339, 0x9fd364, 0xf4ef6d, 0x5096be, 0x695abc, 0xd63865, 0xffffff, 0x50504c, 0xd22a24, 0xa7d42c, 0xff8949, 0x61b9d0, 0x695abc, 0xd63865, 0xffffff, 0x1d1f21, 0xb8dbef, 0x708284, 0x002831, 0x2b2a24, 0xffffff}},
{"Flexoki Dark", [22]uint32{0x100f0f, 0xd14d41, 0x879a39, 0xd0a215, 0x4385be, 0xce5d97, 0x3aa99f, 0x878580, 0x575653, 0xaf3029, 0x66800b, 0xad8301, 0x205ea6, 0xa02f6f, 0x24837b, 0xcecdc3, 0x100f0f, 0xcecdc3, 0xcecdc3, 0x100f0f, 0x403e3c, 0xcecdc3}},
{"Flexoki Light", [22]uint32{0x100f0f, 0xaf3029, 0x66800b, 0xad8301, 0x205ea6, 0xa02f6f, 0x24837b, 0x6f6e69, 0xb7b5ac, 0xd14d41, 0x879a39, 0xd0a215, 0x4385be, 0xce5d97, 0x3aa99f, 0xcecdc3, 0xfffcf0, 0x100f0f, 0x100f0f, 0xfffcf0, 0xcecdc3, 0x100f0f}},
{"Floraverse", [22]uint32{0x08002e, 0x7e1a46, 0x5d731a, 0xcd751c, 0x1d6da1, 0xb7077e, 0x42a38c, 0xf3e0b8, 0x4c3866, 0xd02063, 0xb4ce59, 0xfac357, 0x40a4cf, 0xf12aae, 0x62caa8, 0xfff5db, 0x0e0d15, 0xdbd1b9, 0xbbbbbb, 0xffffff, 0xf3e0b8, 0x08002e}},
{"Forest Blue", [22]uint32{0x333333, 0xf8818e, 0x92d3a2, 0x1a8e63, 0x8ed0ce, 0x5e468c, 0x31658c, 0xe2d8cd, 0x4a4a4a, 0xfb3d66, 0x6bb48d, 0x30c85a, 0x39a7a2, 0x7e62b3, 0x6096bf, 0xe2d8cd, 0x051519, 0xe2d8cd, 0x9e9ecb, 0x000000, 0x4d4d4d, 0xffffff}},
{"Forge Ember", [22]uint32{0x241810, 0xff4733, 0xc4c24a, 0xffb347, 0xf0a24f, 0xff6a4d, 0xffd27a, 0xe6d2b6, 0x7a6248, 0xff4733, 0xc4c24a, 0xff7a2d, 0xf0a24f, 0xff6a4d, 0xffd27a, 0xf4e2c8, 0x140c07, 0xf4e2c8, 0xff6a1f, 0x140c07, 0x33220f, 0x544c47}},
{"Framer", [22]uint32{0x141414, 0xff5555, 0x98ec65, 0xffcc33, 0x00aaff, 0xaa88ff, 0x88ddff, 0xcccccc, 0x414141, 0xff8888, 0xb6f292, 0xffd966, 0x33bbff, 0xcebbff, 0xbbecff, 0xffffff, 0x111111, 0x777777, 0xfcdc08, 0x161616, 0x666666, 0xffffff}},
{"Front End Delight", [22]uint32{0x242526, 0xf8511b, 0x565747, 0xfa771d, 0x2c70b7, 0xf02e4f, 0x3ca1a6, 0xadadad, 0x5fac6d, 0xf74319, 0x74ec4c, 0xfdc325, 0x3393ca, 0xe75e4f, 0x4fbce6, 0x8c735b, 0x1b1c1d, 0xadadad, 0xcdcdcd, 0x1b1c1d, 0xea6154, 0x1b1c1d}},
{"Frostbyte", [22]uint32{0x283645, 0xc2384f, 0x2e7a56, 0x876010, 0x1a66be, 0x5552cc, 0x1a7e9e, 0x586878, 0x93a4b6, 0xc2384f, 0x2e7a56, 0x9a5220, 0x1a66be, 0x5552cc, 0x1a7e9e, 0x283645, 0xeef5fc, 0x283645, 0x1f73cc, 0xeef5fc, 0xd2e4f4, 0xa1a8af}},
{"Fun Forrest", [22]uint32{0x000000, 0xd6262b, 0x919c00, 0xbe8a13, 0x4699a3, 0x8d4331, 0xda8213, 0xddc265, 0x7f6a55, 0xe55a1c, 0xbfc65a, 0xffcb1b, 0x7cc9cf, 0xd26349, 0xe6a96b, 0xffeaa3, 0x251200, 0xdec165, 0xe5591c, 0x000000, 0xe5591c, 0x000000}},
{"Galaxy", [22]uint32{0x000000, 0xf9555f, 0x21b089, 0xfef02a, 0x589df6, 0x944d95, 0x1f9ee7, 0xbbbbbb, 0x555555, 0xfa8c8f, 0x35bb9a, 0xffff55, 0x589df6, 0xe75699, 0x3979bc, 0xffffff, 0x1d2837, 0xffffff, 0xbbbbbb, 0xffffff, 0xb5d5ff, 0x000000}},
{"Galizur", [22]uint32{0x223344, 0xaa1122, 0x33aa11, 0xccaa22, 0x2255cc, 0x7755aa, 0x22bbdd, 0x8899aa, 0x556677, 0xff1133, 0x33ff11, 0xffdd33, 0x3377ff, 0xaa77ff, 0x33ddff, 0xbbccdd, 0x071317, 0xddeeff, 0xddeeff, 0x071317, 0x071317, 0xddeeff}},
{"Ghostty Default Style Dark", [22]uint32{0x1d1f21, 0xcc6566, 0xb6bd68, 0xf0c674, 0x82a2be, 0xb294bb, 0x8abeb7, 0xc4c8c6, 0x666666, 0xd54e53, 0xb9ca4b, 0xe7c547, 0x7aa6da, 0xc397d8, 0x70c0b1, 0xeaeaea, 0x282c34, 0xffffff, 0xffffff, 0x353a44, 0xffffff, 0x282c34}},
{"GitHub", [22]uint32{0x3e3e3e, 0x970b16, 0x07962a, 0xc5bb94, 0x003e8a, 0xe94691, 0x7cc4df, 0xb2b2b2, 0x666666, 0xde0000, 0x7ac895, 0xd7b600, 0x2e6cba, 0xf29592, 0x00c7cb, 0xffffff, 0xf4f4f4, 0x3e3e3e, 0x3f3f3f, 0xf4f4f4, 0xa9c1e2, 0x535353}},
{"GitHub Dark", [22]uint32{0x000000, 0xf78166, 0x56d364, 0xe3b341, 0x6ca4f8, 0xdb61a2, 0x2b7489, 0xffffff, 0x4d4d4d, 0xf78166, 0x56d364, 0xe3b341, 0x6ca4f8, 0xdb61a2, 0x2b7489, 0xffffff, 0x101216, 0x8b949e, 0xc9d1d9, 0x101216, 0x3b5070, 0xffffff}},
{"GitHub Dark Colorblind", [22]uint32{0x484f58, 0xec8e2c, 0x58a6ff, 0xd29922, 0x58a6ff, 0xbc8cff, 0x39c5cf, 0xb1bac4, 0x6e7681, 0xfdac54, 0x79c0ff, 0xe3b341, 0x79c0ff, 0xd2a8ff, 0x56d4dd, 0xffffff, 0x0d1117, 0xc9d1d9, 0x58a6ff, 0x98e6ff, 0xc9d1d9, 0x0d1117}},
{"GitHub Dark Default", [22]uint32{0x484f58, 0xff7b72, 0x3fb950, 0xd29922, 0x58a6ff, 0xbc8cff, 0x39c5cf, 0xb1bac4, 0x6e7681, 0xffa198, 0x56d364, 0xe3b341, 0x79c0ff, 0xd2a8ff, 0x56d4dd, 0xffffff, 0x0d1117, 0xe6edf3, 0x2f81f7, 0x6fc1ff, 0xe6edf3, 0x0d1117}},
{"GitHub Dark Dimmed", [22]uint32{0x545d68, 0xf47067, 0x57ab5a, 0xc69026, 0x539bf5, 0xb083f0, 0x39c5cf, 0x909dab, 0x636e7b, 0xff938a, 0x6bc46d, 0xdaaa3f, 0x6cb6ff, 0xdcbdfb, 0x56d4dd, 0xcdd9e5, 0x22272e, 0xadbac7, 0x539bf5, 0x93dbff, 0xadbac7, 0x22272e}},
{"GitHub Dark High Contrast", [22]uint32{0x7a828e, 0xff9492, 0x26cd4d, 0xf0b72f, 0x71b7ff, 0xcb9eff, 0x39c5cf, 0xd9dee3, 0x9ea7b3, 0xffb1af, 0x4ae168, 0xf7c843, 0x91cbff, 0xdbb7ff, 0x56d4dd, 0xffffff, 0x0a0c10, 0xf0f3f6, 0x71b7ff, 0xb1f7ff, 0xf0f3f6, 0x0a0c10}},
{"GitHub Light Colorblind", [22]uint32{0x24292f, 0xb35900, 0x0550ae, 0x4d2d00, 0x0969da, 0x8250df, 0x1b7c83, 0x6e7781, 0x57606a, 0x8a4600, 0x0969da, 0x633c01, 0x218bff, 0xa475f9, 0x3192aa, 0x8c959f, 0xffffff, 0x24292f, 0x0969da, 0x3c9cff, 0x24292f, 0xffffff}},
{"GitHub Light Default", [22]uint32{0x24292f, 0xcf222e, 0x116329, 0x4d2d00, 0x0969da, 0x8250df, 0x1b7c83, 0x6e7781, 0x57606a, 0xa40e26, 0x1a7f37, 0x633c01, 0x218bff, 0xa475f9, 0x3192aa, 0x8c959f, 0xffffff, 0x1f2328, 0x0969da, 0x3c9cff, 0x1f2328, 0xffffff}},
{"GitHub Light High Contrast", [22]uint32{0x0e1116, 0xa0111f, 0x024c1a, 0x3f2200, 0x0349b4, 0x622cbc, 0x1b7c83, 0x66707b, 0x4b535d, 0x86061d, 0x055d20, 0x4e2c00, 0x1168e3, 0x844ae7, 0x3192aa, 0x88929d, 0xffffff, 0x0e1116, 0x0349b4, 0x367ce7, 0x0e1116, 0xffffff}},
{"GitLab Dark", [22]uint32{0x000000, 0xf57f6c, 0x52b87a, 0xd99530, 0x7fb6ed, 0xf88aaf, 0x32c5d2, 0xffffff, 0x666666, 0xfcb5aa, 0x91d4a8, 0xe9be74, 0x498dd1, 0xfcacc5, 0x5edee3, 0xffffff, 0x28262b, 0xffffff, 0xffffff, 0xbfbfbf, 0xad95e9, 0x28262b}},
{"GitLab Dark Grey", [22]uint32{0x000000, 0xf57f6c, 0x52b87a, 0xd99530, 0x7fb6ed, 0xf88aaf, 0x32c5d2, 0xffffff, 0x666666, 0xfcb5aa, 0x91d4a8, 0xe9be74, 0x498dd1, 0xfcacc5, 0x5edee3, 0xffffff, 0x222222, 0xffffff, 0xffffff, 0xbfbfbf, 0xad95e9, 0x222222}},
{"GitLab Light", [22]uint32{0x303030, 0xa31700, 0x0a7f3d, 0xaf551d, 0x006cd8, 0x583cac, 0x00798a, 0x303030, 0x303030, 0xa31700, 0x0a7f3d, 0xaf551d, 0x006cd8, 0x583cac, 0x00798a, 0x303030, 0xfafaff, 0x303030, 0x303030, 0x565656, 0xad95e9, 0xfafaff}},
{"Glacier", [22]uint32{0x2e343c, 0xbd0f2f, 0x35a770, 0xfb9435, 0x1f5872, 0xbd2523, 0x778397, 0xffffff, 0x404a55, 0xbd0f2f, 0x49e998, 0xfddf6e, 0x2a8bc1, 0xea4727, 0xa0b6d3, 0xffffff, 0x0c1115, 0xffffff, 0x6c6c6c, 0x9f9f9f, 0xbd2523, 0xffffff}},
{"Gleam", [22]uint32{0x000000, 0xf44747, 0xaadd8b, 0xffd596, 0x6796e6, 0xfe7ab2, 0xb181ec, 0xf7f7f7, 0x808080, 0xff4a4a, 0xc8ffa7, 0xfdffab, 0x9ce7ff, 0xffaff3, 0xd9baff, 0xffffff, 0x292d3e, 0xffffff, 0xffffff, 0x2f2f2f, 0x393f57, 0xffffff}},
{"Gleam Classic", [22]uint32{0x000000, 0xf44747, 0xaadd8b, 0xffd596, 0x6796e6, 0xfe7ab2, 0xb181ec, 0xf7f7f7, 0x808080, 0xff4a4a, 0xc8ffa7, 0xfdffab, 0x9ce7ff, 0xffaff3, 0xd9baff, 0xffffff, 0x1e1e1e, 0xffffff, 0xffffff, 0x2f2f2f, 0x777777, 0xffffff}},
{"Grape", [22]uint32{0x2d283f, 0xed2261, 0x1fa91b, 0x8ddc20, 0x487df4, 0x8d35c9, 0x3bdeed, 0x9e9ea0, 0x59516a, 0xf0729a, 0x53aa5e, 0xb2dc87, 0xa9bcec, 0xad81c2, 0x9de3eb, 0xa288f7, 0x171423, 0x9f9fa1, 0xa288f7, 0x171422, 0x493d70, 0x171422}},
{"Graphite", [22]uint32{0x15171a, 0xe58888, 0xa7c59f, 0xcec59d, 0x8db4d0, 0xbaabcb, 0xa8c6d4, 0xb4b9c0, 0x7e8590, 0xf19f9f, 0xb9d5b1, 0xcfba97, 0xa5c6de, 0xccbedd, 0xbcd6e2, 0xeceff3, 0x1c1e22, 0xd2d6dc, 0xc4cedb, 0x1c1e22, 0x2e333b, 0x5c5e62}},
{"Grass", [22]uint32{0x000000, 0xff5959, 0x00bb00, 0xe7b000, 0x0000a3, 0xee59bb, 0x00bbbb, 0xbbbbbb, 0x959595, 0xff5959, 0x00bb00, 0xe7b000, 0x0000bb, 0xff55ff, 0x55ffff, 0xffffff, 0x13773d, 0xfff0a5, 0xd9744c, 0xffffff, 0xb64926, 0xffffff}},
{"Green Phosphor CRT", [22]uint32{0x002200, 0x00aa00, 0x33ff33, 0x66ff66, 0x00cc44, 0x00ff88, 0x66ffaa, 0xb6ffb6, 0x0a5a0a, 0x19cc19, 0x66ff66, 0x99ff99, 0x33ff77, 0x66ffaa, 0x99ffcc, 0xe6ffe6, 0x0b0f0b, 0x33ff33, 0x33ff33, 0x0b0f0b, 0x0a3a0a, 0x575b57}},
{"Grey Green", [22]uint32{0x000000, 0xfe1414, 0x74ff00, 0xf1ff01, 0x00deff, 0xff00f0, 0x00ffbc, 0xffffff, 0x666666, 0xff3939, 0x00ff44, 0xffd100, 0x00afff, 0xff008a, 0x00ffd3, 0xf5ecec, 0x002a1a, 0xffffff, 0xfff400, 0xaeb1b0, 0x517e50, 0xe2e2e2}},
{"Grok Day", [22]uint32{0x262626, 0xcd3048, 0x378e23, 0xa27612, 0x2f64d2, 0x7d4bc6, 0x0082aa, 0xbbbbbb, 0x767676, 0xcd3048, 0x378e23, 0xa27612, 0x2f64d2, 0x7d4bc6, 0x0082aa, 0x444444, 0xf5f5f5, 0x262626, 0x7d4bc6, 0xf5f5f5, 0xdedede, 0x262626}},
{"Grok Night", [22]uint32{0x0a0a0a, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xc8c8c8, 0x6c6c6c, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xe1e1e1, 0x141414, 0xe1e1e1, 0xe0af68, 0x141414, 0x242424, 0xe1e1e1}},
{"Gruber Darker", [22]uint32{0x181818, 0xff0a36, 0x42dc00, 0xffdb00, 0x92a7cb, 0xa095cb, 0x90aa9e, 0xe4e4e4, 0x54494e, 0xff3851, 0x42dc00, 0xffdb00, 0x92a7cb, 0xafafda, 0x90aa9e, 0xf5f5f5, 0x181818, 0xe4e4e4, 0xffdb00, 0xa6a6a6, 0xffffff, 0x54494e}},
{"Gruvbox Dark", [22]uint32{0x282828, 0xcc241d, 0x98971a, 0xd79921, 0x458588, 0xb16286, 0x689d6a, 0xa89984, 0x928374, 0xfb4934, 0xb8bb26, 0xfabd2f, 0x83a598, 0xd3869b, 0x8ec07c, 0xebdbb2, 0x282828, 0xebdbb2, 0xebdbb2, 0x282828, 0x665c54, 0xebdbb2}},
{"Gruvbox Dark Hard", [22]uint32{0x1d2021, 0xcc241d, 0x98971a, 0xd79921, 0x458588, 0xb16286, 0x689d6a, 0xa89984, 0x928374, 0xfb4934, 0xb8bb26, 0xfabd2f, 0x83a598, 0xd3869b, 0x8ec07c, 0xebdbb2, 0x1d2021, 0xebdbb2, 0xebdbb2, 0x1d2021, 0x665c54, 0xebdbb2}},
{"Gruvbox Light", [22]uint32{0xfbf1c7, 0xcc241d, 0x98971a, 0xd79921, 0x458588, 0xb16286, 0x689d6a, 0x7c6f64, 0x928374, 0x9d0006, 0x79740e, 0xb57614, 0x076678, 0x8f3f71, 0x427b58, 0x3c3836, 0xfbf1c7, 0x3c3836, 0x3c3836, 0xfbf1c7, 0x3c3836, 0xfbf1c7}},
{"Gruvbox Light Hard", [22]uint32{0xf9f5d7, 0xcc241d, 0x98971a, 0xd79921, 0x458588, 0xb16286, 0x689d6a, 0x7c6f64, 0x928374, 0x9d0006, 0x79740e, 0xb57614, 0x076678, 0x8f3f71, 0x427b58, 0x3c3836, 0xf9f5d7, 0x3c3836, 0x3c3836, 0xf9f5d7, 0x3c3836, 0xf9f5d7}},
{"Gruvbox Material", [22]uint32{0x141617, 0xea6926, 0xc1d041, 0xeecf75, 0x6da3ec, 0xfd9bc1, 0xfe9d6e, 0xffffff, 0x4c4c4c, 0xd3573b, 0xc1d041, 0xeecf75, 0x2c86ff, 0xfd9bc1, 0x92a5df, 0xffffff, 0x1d2021, 0xd4be98, 0xffffff, 0x000000, 0x2b2c3f, 0x7cfb70}},
{"Gruvbox Material Dark", [22]uint32{0x282828, 0xea6962, 0xa9b665, 0xd8a657, 0x7daea3, 0xd3869b, 0x89b482, 0xd4be98, 0x7c6f64, 0xea6962, 0xa9b665, 0xd8a657, 0x7daea3, 0xd3869b, 0x89b482, 0xddc7a1, 0x282828, 0xd4be98, 0xd4be98, 0x282828, 0xd4be98, 0x282828}},
{"Gruvbox Material Light", [22]uint32{0xfbf1c7, 0xc14a4a, 0x6c782e, 0xb47109, 0x45707a, 0x945e80, 0x4c7a5d, 0x654735, 0xa89984, 0xc14a4a, 0x6c782e, 0xb47109, 0x45707a, 0x945e80, 0x4c7a5d, 0x4f3829, 0xfbf1c7, 0x654735, 0x654735, 0xfbf1c7, 0x654735, 0xfbf1c7}},
{"Guezwhoz", [22]uint32{0x333333, 0xe85181, 0x7ad694, 0xb7d074, 0x5aa0d6, 0x9a90e0, 0x58d6ce, 0xd9d9d9, 0x808080, 0xe85181, 0xafd7af, 0xd1ed85, 0x64b2ed, 0xa398ed, 0x61ede4, 0xededed, 0x1d1d1d, 0xd9d9d9, 0x99d4b1, 0x1d1d1d, 0x245354, 0x58d6ce}},
{"HaX0R Blue", [22]uint32{0x010921, 0x10b6ff, 0x10b6ff, 0x10b6ff, 0x10b6ff, 0x10b6ff, 0x10b6ff, 0xfafafa, 0x484157, 0x00b3f7, 0x00b3f7, 0x00b3f7, 0x00b3f7, 0x00b3f7, 0x00b3f7, 0xfefefe, 0x010515, 0x11b7ff, 0x10b6ff, 0xffffff, 0xc1e4ff, 0xa9a9a9}},
{"HaX0R Gr33N", [22]uint32{0x001f0b, 0x15d00d, 0x15d00d, 0x15d00d, 0x15d00d, 0x15d00d, 0x15d00d, 0xfafafa, 0x334843, 0x19e20e, 0x19e20e, 0x19e20e, 0x19e20e, 0x19e20e, 0x19e20e, 0xfefefe, 0x020f01, 0x16b10e, 0x15d00d, 0xffffff, 0xd4ffc1, 0xb0b0b0}},
{"HaX0R R3D", [22]uint32{0x1f0000, 0xb00d0d, 0xb00d0d, 0xb00d0d, 0xb00d0d, 0xb00d0d, 0xb00d0d, 0xfafafa, 0x554040, 0xff1111, 0xff1010, 0xff1010, 0xff1010, 0xff1010, 0xff1010, 0xfefefe, 0x200101, 0xb10e0e, 0xb00d0d, 0xffffff, 0xebc1ff, 0x979797}},
{"Hacktober", [22]uint32{0x191918, 0xb34538, 0x587744, 0xd08949, 0x206ec5, 0x864651, 0xac9166, 0xf1eee7, 0x464444, 0xb33323, 0x42824a, 0xc75a22, 0x5389c5, 0xe795a5, 0xebc587, 0xffffff, 0x141414, 0xc9c9c9, 0xc9c9c9, 0x141414, 0x141414, 0xc9c9c9}},
{"Hardcore", [22]uint32{0x1b1d1e, 0xf92672, 0xa6e22e, 0xfd971f, 0x66d9ef, 0x9e6ffe, 0x5e7175, 0xccccc6, 0x505354, 0xff669d, 0xbeed5f, 0xe6db74, 0x66d9ef, 0x9e6ffe, 0xa3babf, 0xf8f8f2, 0x121212, 0xa0a0a0, 0xbbbbbb, 0xffffff, 0x453b39, 0xb6bbc0}},
{"Harper", [22]uint32{0x010101, 0xf8b63f, 0x7fb5e1, 0xd6da25, 0x489e48, 0xb296c6, 0xf5bfd7, 0xa8a49d, 0x726e6a, 0xf8b63f, 0x7fb5e1, 0xd6da25, 0x489e48, 0xb296c6, 0xf5bfd7, 0xfefbea, 0x010101, 0xa8a49d, 0xa8a49d, 0x010101, 0x5a5753, 0xa8a49d}},
{"Havn Daggry", [22]uint32{0x1f2842, 0x985248, 0x577159, 0xbe6b00, 0x3a577d, 0x7c5c97, 0x925780, 0xb0b5c5, 0x1f2842, 0xcc4a35, 0x719679, 0xf1a527, 0x6089c0, 0x7d7396, 0xaa869d, 0xd6dbeb, 0xf8f9fb, 0x3b4a7a, 0x226c4f, 0xd6dbeb, 0xcfe9dd, 0x313c64}},
{"Havn Skumring", [22]uint32{0x252c47, 0xea563e, 0x6ead7b, 0xf8b330, 0x596cf7, 0x7c719e, 0xd588c1, 0xdce0ee, 0x38425c, 0xd17264, 0x8c9e8f, 0xeac58c, 0x5186cb, 0x9b7cee, 0xd17ab6, 0xfff6e1, 0x111522, 0xd6dbeb, 0x277a6f, 0xe0e4f3, 0x2b514b, 0xdce0ef}},
{"Heeler", [22]uint32{0x000000, 0xe44c2e, 0xbdd100, 0xf4ce65, 0x5ba5f2, 0xff95c2, 0xff9763, 0xffffff, 0x4c4c4c, 0xe44c2e, 0xbdd100, 0xf4ce65, 0x0088ff, 0xff95c2, 0x8da6e4, 0xffffff, 0x211f46, 0xfdfdfd, 0xffffff, 0x000000, 0x2b2c41, 0x2eff58}},
{"Highway", [22]uint32{0x000000, 0xd00e18, 0x138034, 0xffcb3e, 0x006bb3, 0x783482, 0x455271, 0xededed, 0x5d504a, 0xf07e18, 0xb1d130, 0xfff120, 0x4fc2fd, 0xde0071, 0x5d504a, 0xffffff, 0x222225, 0xededed, 0xe0d9b9, 0x1f192a, 0x384564, 0xededed}},
{"Hipster Green", [22]uint32{0x000000, 0xb6214a, 0x00a600, 0xbfbf00, 0x246eb2, 0xb200b2, 0x00a6b2, 0xbfbfbf, 0x666666, 0xe50000, 0x86a93e, 0xe5e500, 0x0000ff, 0xe500e5, 0x00e5e5, 0xe5e5e5, 0x100b05, 0x84c138, 0x23ff18, 0xff0018, 0x083905, 0xffffff}},
{"Hivacruz", [22]uint32{0x202746, 0xc94922, 0xac9739, 0xc08b30, 0x3d8fd1, 0x6679cc, 0x22a2c9, 0x979db4, 0x6b7394, 0xc76b29, 0x73ad43, 0x5e6687, 0x898ea4, 0xdfe2f1, 0x9c637a, 0xf5f7ff, 0x132638, 0xede4e4, 0x979db4, 0x202746, 0x5e6687, 0x979db4}},
{"Homebrew", [22]uint32{0x000000, 0x990000, 0x00a600, 0x999900, 0x0d0dbf, 0xb200b2, 0x00a6b2, 0xbfbfbf, 0x666666, 0xe50000, 0x00d900, 0xe5e500, 0x0000ff, 0xe500e5, 0x00e5e5, 0xe5e5e5, 0x000000, 0x00ff00, 0x23ff18, 0xff0018, 0x083905, 0xffffff}},
{"Hopscotch", [22]uint32{0x322931, 0xdd464c, 0x8fc13e, 0xfdcc59, 0x1290bf, 0xc85e7c, 0x149b93, 0xb9b5b8, 0x797379, 0xfd8b19, 0x5c545c, 0x5c545b, 0x989498, 0xd5d3d5, 0xb33508, 0xffffff, 0x322931, 0xb9b5b8, 0xb9b5b8, 0x322931, 0x5c545b, 0xb9b5b8}},
{"Hopscotch.256", [22]uint32{0x322931, 0xdd464c, 0x8fc13e, 0xfdcc59, 0x1290bf, 0xc85e7c, 0x149b93, 0xb9b5b8, 0x797379, 0xdd464c, 0x8fc13e, 0xfdcc59, 0x1290bf, 0xc85e7c, 0x149b93, 0xffffff, 0x322931, 0xb9b5b8, 0xb9b5b8, 0x322931, 0x5c545b, 0xb9b5b8}},
{"Horizon", [22]uint32{0x000000, 0xe95678, 0x29d398, 0xfab795, 0x26bbd9, 0xee64ac, 0x59e1e3, 0xe5e5e5, 0x666666, 0xec6a88, 0x3fdaa4, 0xfbc3a7, 0x3fc4de, 0xf075b5, 0x6be4e6, 0xe5e5e5, 0x1c1e26, 0xd5d8da, 0x6c6f93, 0x9fa2c6, 0x6c6f93, 0x1c1e26}},
{"Horizon Bright", [22]uint32{0x16161d, 0xfc4777, 0x00ca86, 0xf2a682, 0x00bedd, 0xff58b1, 0x00cdcb, 0xbfafac, 0x1a1c24, 0xfe5f87, 0x00d193, 0xe5a688, 0x00c9e2, 0xff6cba, 0x00c3c2, 0xfff2ef, 0xfdf0ed, 0x16161d, 0xd3a89d, 0xffe8dc, 0xf9cec3, 0x16161d}},
{"Hot Dog Stand", [22]uint32{0x000000, 0xffff54, 0xffff54, 0xffff54, 0x000000, 0xffff54, 0xffffff, 0xc6c6c6, 0x000000, 0xffff54, 0xffff54, 0xffff54, 0x000000, 0xffff54, 0xffffff, 0xc6c6c6, 0xea3323, 0xffffff, 0xffff54, 0xea3323, 0xffff54, 0x000000}},
{"Hot Dog Stand (Mustard)", [22]uint32{0x000000, 0xea3323, 0xea3323, 0xea3323, 0x000000, 0xea3323, 0x000000, 0xb9b9b9, 0x000000, 0xea3323, 0xea3323, 0xea3323, 0x000000, 0xea3323, 0x000000, 0xc6c6c6, 0xffff54, 0x000000, 0xea3323, 0xffff54, 0xea3323, 0xffffff}},
{"Hurtado", [22]uint32{0x575757, 0xff1b00, 0xa5e055, 0xfbe74a, 0x496487, 0xfd5ff1, 0x86e9fe, 0xcbcccb, 0x404040, 0xd51d00, 0xa5df55, 0xfbe84a, 0x89beff, 0xc001c1, 0x86eafe, 0xdbdbdb, 0x000000, 0xdbdbdb, 0xbbbbbb, 0xffffff, 0xb5d5ff, 0x000000}},
{"Hybrid", [22]uint32{0x2a2e33, 0xb84d51, 0xb3bf5a, 0xe4b55e, 0x6e90b0, 0xa17eac, 0x7fbfb4, 0xb5b9b6, 0x434548, 0x8d2e32, 0x798431, 0xe58a50, 0x4b6b88, 0x6e5079, 0x4d7b74, 0x5a626a, 0x161719, 0xb7bcba, 0xb7bcba, 0x1e1f22, 0x1e1f22, 0xb7bcba}},
{"IBM 5153 CGA", [22]uint32{0x141414, 0xd03333, 0x1bd01b, 0xd08c1b, 0x1b1bd0, 0xd01bd0, 0x1bd0d0, 0xcecece, 0x4e4e4e, 0xdc4e4e, 0x4edc4e, 0xf3f34e, 0x4e4edc, 0xf34ef3, 0x4ef3f3, 0xffffff, 0x141414, 0xcecece, 0xcecece, 0x141414, 0xcecece, 0x141414}},
{"IBM 5153 CGA (Black)", [22]uint32{0x000000, 0xc40000, 0x00c400, 0xc47e00, 0x0000c4, 0xc400c4, 0x00c4c4, 0xc4c4c4, 0x4e4e4e, 0xdc4e4e, 0x4edc4e, 0xf3f34e, 0x4e4edc, 0xf34ef3, 0x4ef3f3, 0xffffff, 0x000000, 0xc4c4c4, 0xc4c4c4, 0x000000, 0xc4c4c4, 0x000000}},
{"IC Green PPL", [22]uint32{0x014401, 0xff2736, 0x41a638, 0x76a831, 0x2ec3b9, 0x50a096, 0x3ca078, 0xe6fef2, 0x106910, 0xb4fa5c, 0xaefb86, 0xdafa87, 0x2efaeb, 0x50fafa, 0x3cfac8, 0xe0f1dc, 0x2c2c2c, 0xe0f1dc, 0x47fa6b, 0x292929, 0x116b41, 0xe0f1dc}},
{"IC Orange PPL", [22]uint32{0x000000, 0xc13900, 0xa4a900, 0xcaaf00, 0xbd6d00, 0xfc5e00, 0xf79500, 0xffc88a, 0x6a4f2a, 0xff8c68, 0xf6ff40, 0xffe36e, 0xffbe55, 0xfc874f, 0xc69752, 0xfafaff, 0x262626, 0xffcb83, 0xfc531d, 0xffc88a, 0xc14020, 0xffc88a}},
{"IR Black", [22]uint32{0x4f4f4f, 0xfa6c60, 0xa8ff60, 0xfffeb7, 0x96cafe, 0xfa73fd, 0xc6c5fe, 0xefedef, 0x7b7b7b, 0xfcb6b0, 0xcfffab, 0xffffcc, 0xb5dcff, 0xfb9cfe, 0xe0e0fe, 0xffffff, 0x000000, 0xf1f1f1, 0x808080, 0xffffff, 0xb5d5ff, 0x000000}},
{"IRIX Console", [22]uint32{0x1a1919, 0xd42426, 0x37a327, 0xc29d28, 0x0739e2, 0x911f9c, 0x4497df, 0xcccccc, 0x767676, 0xf34f59, 0x45c731, 0xf9f2a7, 0x4079ff, 0xc31ba2, 0x6ed7d7, 0xf2f2f2, 0x0c0c0c, 0xf2f2f2, 0xc7c7c7, 0x8c8c8c, 0xc2deff, 0x000000}},
{"IRIX Terminal", [22]uint32{0x1a1919, 0xff2b1e, 0x57ff3d, 0xffff44, 0x0004ff, 0xff2cff, 0x56ffff, 0xffffff, 0xffff44, 0xffff44, 0xffff44, 0xfffc72, 0xffff44, 0xffff44, 0xffff44, 0xffff44, 0x000043, 0xf2f2f2, 0xc7c7c7, 0x8c8c8c, 0xc2deff, 0x000000}},
{"Iceberg Dark", [22]uint32{0x1e2132, 0xe27878, 0xb4be82, 0xe2a478, 0x84a0c6, 0xa093c7, 0x89b8c2, 0xc6c8d1, 0x6b7089, 0xe98989, 0xc0ca8e, 0xe9b189, 0x91acd1, 0xada0d3, 0x95c4ce, 0xd2d4de, 0x161821, 0xc6c8d1, 0xc6c8d1, 0x161821, 0xc6c8d1, 0x161821}},
{"Iceberg Light", [22]uint32{0xdcdfe7, 0xcc517a, 0x668e3d, 0xc57339, 0x2d539e, 0x7759b4, 0x3f83a6, 0x33374c, 0x8389a3, 0xcc3768, 0x598030, 0xb6662d, 0x22478e, 0x6845ad, 0x327698, 0x262a3f, 0xe8e9ec, 0x33374c, 0x33374c, 0xe8e9ec, 0x33374c, 0xe8e9ec}},
{"Idea", [22]uint32{0xadadad, 0xfc5256, 0x98b61c, 0xccb444, 0x437ee7, 0x9d74b0, 0x248887, 0x4b4b4b, 0xffffff, 0xfc7072, 0x98b61c, 0xffff0b, 0x6c9ced, 0xfc7eff, 0x248887, 0x181818, 0x202020, 0xadadad, 0xbbbbbb, 0xffffff, 0x44475a, 0xffffff}},
{"Idle Toes", [22]uint32{0x323232, 0xd25252, 0x7fe173, 0xffc66d, 0x4099ff, 0xf680ff, 0xbed6ff, 0xeeeeec, 0x606060, 0xf07070, 0x9dff91, 0xffe48b, 0x5eb7f7, 0xff9dff, 0xdcf4ff, 0xffffff, 0x323232, 0xffffff, 0xd6d6d6, 0x000000, 0x5b5b5b, 0x000000}},
{"Isocon Dark", [22]uint32{0x062329, 0xe34b87, 0x419658, 0xba783e, 0x408cbd, 0x976fe3, 0x3e8c7e, 0x868686, 0x565656, 0xf81486, 0x109b48, 0xc7700e, 0x0f8dcd, 0x9c61fc, 0x0f907f, 0x868686, 0x062329, 0x868686, 0x868686, 0x062329, 0x868686, 0x062329}},
{"Isocon Light", [22]uint32{0xeef3ea, 0xc33f3d, 0x347b47, 0x856b31, 0x2f6bcf, 0x9242d6, 0x306f72, 0x6e6e6e, 0x8c8c8c, 0xd0272f, 0x1f7d3f, 0x896a1c, 0x1a67e1, 0x982ae9, 0x1c7175, 0x6e6e6e, 0xeef3ea, 0x6e6e6e, 0x6e6e6e, 0xeef3ea, 0x6e6e6e, 0xeef3ea}},
{"Jackie Brown", [22]uint32{0x2c1d16, 0xef5734, 0x2baf2b, 0xbebf00, 0x246eb2, 0xd05ec1, 0x00acee, 0xbfbfbf, 0x666666, 0xe50000, 0x86a93e, 0xe5e500, 0x0000ff, 0xe500e5, 0x00e5e5, 0xe5e5e5, 0x2c1d16, 0xffcc2f, 0x23ff18, 0xff0018, 0xaf8d21, 0xffffff}},
{"Japanesque", [22]uint32{0x343935, 0xcf3f61, 0x7bb75b, 0xe9b32a, 0x4c9ad4, 0xa57fc4, 0x389aad, 0xfafaf6, 0x595b59, 0xd18fa6, 0x767f2c, 0x78592f, 0x135979, 0x604291, 0x76bbca, 0xb2b5ae, 0x1e1e1e, 0xf7f6ec, 0xedcf4f, 0x343935, 0x175877, 0xf7f6ec}},
{"Jellybeans", [22]uint32{0x929292, 0xe27373, 0x94b979, 0xffba7b, 0x97bedc, 0xe1c0fa, 0x00988e, 0xdedede, 0xbdbdbd, 0xffa1a1, 0xbddeab, 0xffdca0, 0xb1d8f6, 0xfbdaff, 0x1ab2a8, 0xffffff, 0x121212, 0xdedede, 0xffa560, 0xffffff, 0x474e91, 0xf4f4f4}},
{"JetBrains Darcula", [22]uint32{0x000000, 0xfa5355, 0x126e00, 0xc2c300, 0x4581eb, 0xfa54ff, 0x33c2c1, 0xadadad, 0x555555, 0xfb7172, 0x67ff4f, 0xffff00, 0x6d9df1, 0xfb82ff, 0x60d3d1, 0xeeeeee, 0x202020, 0xadadad, 0xffffff, 0x000000, 0x1a3272, 0xadadad}},
{"JetBrains Islands Dark", [22]uint32{0x191a1c, 0xf75464, 0x6aab73, 0xcf8e6d, 0x56a8f5, 0xc77dbb, 0x2aacb8, 0xbcbec4, 0x7a7e85, 0xf57e84, 0x6db083, 0xf0ac81, 0x548af7, 0xb189f5, 0x16baac, 0xffffff, 0x191a1c, 0xbcbec4, 0xced0d6, 0x191a1c, 0x2a4371, 0xd1d3d9}},
{"JetCalm Light", [22]uint32{0x383a42, 0xa52a2a, 0x556b2f, 0x5c3e00, 0x4682b4, 0xa626a4, 0x0997b3, 0x6b8e23, 0x4f525d, 0xdf6c75, 0x2e8b57, 0x808000, 0x008080, 0xc577dd, 0x008080, 0x7b8d9e, 0xededed, 0x1c2410, 0x082108, 0xededed, 0x3c444d, 0xededed}},
{"Jubi", [22]uint32{0x3b3750, 0xcf7b98, 0x90a94b, 0x6ebfc0, 0x576ea6, 0xbc4f68, 0x75a7d2, 0xc3d3de, 0xa874ce, 0xde90ab, 0xbcdd61, 0x87e9ea, 0x8c9fcd, 0xe16c87, 0xb7c9ef, 0xd5e5f1, 0x262b33, 0xc3d3de, 0xc3d3de, 0x1e1b2e, 0x5b5184, 0x1e1b2e}},
{"Kanagawa Dragon", [22]uint32{0x0d0c0c, 0xc4746e, 0x8a9a7b, 0xc4b28a, 0x8ba4b0, 0xa292a3, 0x8ea4a2, 0xc8c093, 0xa6a69c, 0xe46876, 0x87a987, 0xe6c384, 0x7fb4ca, 0x938aa9, 0x7aa89f, 0xc5c9c5, 0x181616, 0xc5c9c5, 0xc8c093, 0x181616, 0xc5c9c5, 0x181616}},
{"Kanagawa Lotus", [22]uint32{0x1f1f28, 0xc84053, 0x6f894e, 0x77713f, 0x4d699b, 0xb35b79, 0x597b75, 0x545464, 0x8a8980, 0xd7474b, 0x6e915f, 0x836f4a, 0x6693bf, 0x624c83, 0x5e857a, 0x43436c, 0xf2ecbc, 0x545464, 0x43436c, 0xf2ecbc, 0x545464, 0xf2ecbc}},
{"Kanagawa Wave", [22]uint32{0x090618, 0xc34043, 0x76946a, 0xc0a36e, 0x7e9cd8, 0x957fb8, 0x6a9589, 0xc8c093, 0x727169, 0xe82424, 0x98bb6c, 0xe6c384, 0x7fb4ca, 0x938aa9, 0x7aa89f, 0xdcd7ba, 0x1f1f28, 0xdcd7ba, 0xdcd7ba, 0x1f1f28, 0xdcd7ba, 0x1f1f28}},
{"Kanagawabones", [22]uint32{0x1f1f28, 0xe46a78, 0x98bc6d, 0xe5c283, 0x7eb3c9, 0x957fb8, 0x7eb3c9, 0xddd8bb, 0x49495e, 0xec818c, 0x9ec967, 0xf1c982, 0x7bc2df, 0xa98fd2, 0x7bc2df, 0xa8a48d, 0x1f1f28, 0xddd8bb, 0xe6e0c2, 0x1f1f28, 0x49473e, 0xddd8bb}},
{"Kanso Ink", [22]uint32{0x14171d, 0xc4746e, 0x8a9a7b, 0xc4b28a, 0x8ba4b0, 0xa292a3, 0x8ea4a2, 0xc8c093, 0xa4a7a4, 0xe46876, 0x87a987, 0xe6c384, 0x7fb4ca, 0x938aa9, 0x7aa89f, 0xc5c9c7, 0x14171d, 0xc5c9c7, 0xc5c9c7, 0x14171d, 0x22262d, 0xc5c9c7}},
{"Kanso Mist", [22]uint32{0x22262d, 0xc4746e, 0x8a9a7b, 0xc4b28a, 0x8ba4b0, 0xa292a3, 0x8ea4a2, 0xa4a7a4, 0x5c6066, 0xe46876, 0x87a987, 0xe6c384, 0x7fb4ca, 0x938aa9, 0x7aa89f, 0xc5c9c7, 0x22262d, 0xc5c9c7, 0xc5c9c7, 0x22262d, 0x43464e, 0xc5c9c7}},
{"Kanso Pearl", [22]uint32{0x22262d, 0xc84053, 0x6f894e, 0x77713f, 0x4d699b, 0xb35b79, 0x597b75, 0x545464, 0x6d6f6e, 0xd7474b, 0x6e915f, 0x836f4a, 0x6693bf, 0x624c83, 0x5e857a, 0x43436c, 0xf2f1ef, 0x22262d, 0x22262d, 0xf2f1ef, 0xe2e1df, 0x22262d}},
{"Kanso Zen", [22]uint32{0x0d0c0c, 0xc4746e, 0x8a9a7b, 0xc4b28a, 0x8ba4b0, 0xa292a3, 0x8ea4a2, 0xc8c093, 0xa4a7a4, 0xe46876, 0x87a987, 0xe6c384, 0x7fb4ca, 0x938aa9, 0x7aa89f, 0xc5c9c7, 0x090e13, 0xc5c9c7, 0xc5c9c7, 0x090e13, 0x393b44, 0xc5c9c7}},
{"Karasu Night", [22]uint32{0x0a0a0a, 0xe06c75, 0x8fbf7a, 0xd4b86a, 0x7aa2c8, 0xb4a1d8, 0x76b7b2, 0xf5f5f5, 0x44403c, 0xff5c5c, 0xa6d189, 0xe8d07d, 0x8cb4e2, 0xc7b3ee, 0x8ad4ce, 0xe7e5e4, 0x0a0a0a, 0xe7e5e4, 0xf5f5f5, 0x0a0a0a, 0x262626, 0xe7e5e4}},
{"Karasu Snow", [22]uint32{0x0a0a0a, 0xb84755, 0x3f7e4a, 0x8a6a1f, 0x2e5e9b, 0x6c4bb8, 0x2d7e7a, 0xb5b5b5, 0x404040, 0xd93c3c, 0x2f9150, 0x9a7a1d, 0x2b72c7, 0x7b59d6, 0x1f968f, 0xffffff, 0xfafafa, 0x292524, 0x0a0a0a, 0xfafafa, 0xe5e5e5, 0x292524}},
{"Karma Dark", [22]uint32{0x0a0e14, 0xfc618d, 0x7bd88f, 0xfce566, 0x5ad4e6, 0xaf98e6, 0x5ad4e6, 0xbab6c0, 0x69676c, 0xff7ba0, 0x9ce3ab, 0xfce566, 0x7fe0ee, 0xc3b0f0, 0x7fe0ee, 0xf7f1ff, 0x0a0e14, 0xf7f1ff, 0xfce566, 0x0a0e14, 0x3a384a, 0xf7f1ff}},
{"Karma Dark Dimmed", [22]uint32{0x14181f, 0xe87691, 0x82c891, 0xebd870, 0x6cc4d2, 0xa892d4, 0x6cc4d2, 0xa8a4ae, 0x5c5a5f, 0xe8869c, 0x98cea4, 0xebd870, 0x80c8d2, 0xb6a4d6, 0x80c8d2, 0xe2def0, 0x14181f, 0xe2def0, 0xebd870, 0x14181f, 0x2f2d3d, 0xe2def0}},
{"Karma Dark HC", [22]uint32{0x000000, 0xff5c87, 0x80e598, 0xfce566, 0x61dceb, 0xb9a3ee, 0x61dceb, 0xd6d2db, 0x69676c, 0xff8aab, 0xa3e9b1, 0xfff080, 0x87e5f1, 0xcab6f4, 0x87e5f1, 0xffffff, 0x000000, 0xffffff, 0xfce566, 0x000000, 0x4d4a5e, 0xffffff}},
{"Karma Light", [22]uint32{0x0a0e14, 0xfc618d, 0x2d972f, 0xeeae11, 0x5688c7, 0x6f42c1, 0x5688c7, 0x525053, 0x999999, 0xfc618d, 0x2d972f, 0xffaa33, 0x5688c7, 0xa86efd, 0x5688c7, 0x0a0e14, 0xffffff, 0x0a0e14, 0xa86efd, 0xffffff, 0xe5e3ea, 0x0a0e14}},
{"Karma Light Dimmed", [22]uint32{0x1c1f24, 0xe07a90, 0x4a9a4c, 0xd49a26, 0x6688b8, 0x7c5ab0, 0x6688b8, 0x5a5860, 0x999999, 0xe07a90, 0x4a9a4c, 0xe0a040, 0x6688b8, 0x9676d0, 0x6688b8, 0x1c1f24, 0xf5f3f7, 0x1c1f24, 0x9676d0, 0xf5f3f7, 0xddd8e2, 0x1c1f24}},
{"Karma Light HC", [22]uint32{0x000000, 0xc01650, 0x1a6e1c, 0x9c6800, 0x2f5e9e, 0x4d2d9a, 0x2f5e9e, 0x2e2c30, 0x999999, 0xc01650, 0x1a6e1c, 0x9c6800, 0x2f5e9e, 0x4d2d9a, 0x2f5e9e, 0x0a0e14, 0xffffff, 0x000000, 0x4d2d9a, 0xffffff, 0xcfcad8, 0x000000}},
{"Keys Ocean Sunset", [22]uint32{0x101927, 0xe85a52, 0x4a9a72, 0xe89a2e, 0x5288b8, 0xbc5090, 0x5ec8c8, 0xa5b5d5, 0x344658, 0xfc9077, 0x62c48e, 0xffcb9a, 0x5a8fd4, 0xfdbfde, 0x7ed4e0, 0xfff5be, 0x0a1018, 0xb8c8dc, 0xfc9077, 0x0a1018, 0x1a2430, 0xfff5be}},
{"Keys Ocean Sunset HC", [22]uint32{0x7a92a8, 0xff6361, 0x4ad68a, 0xffa600, 0x6aa8f0, 0xde72b0, 0x5edee8, 0xc8d8ec, 0x8aa0b8, 0xff8578, 0x72f0a8, 0xffd380, 0x88c4ff, 0xf0a8d8, 0x88f0f8, 0xfff5be, 0x060910, 0xf0f4fa, 0xff8531, 0x060910, 0x2c4875, 0xffffff}},
{"Kibble", [22]uint32{0x4d4d4d, 0xc70031, 0x29cf13, 0xd8e30e, 0x3449d1, 0x8400ff, 0x0798ab, 0xe2d1e3, 0x5a5a5a, 0xf01578, 0x6ce05c, 0xf3f79e, 0x97a4f7, 0xc495f0, 0x68f2e0, 0xffffff, 0x0e100a, 0xf7f7f7, 0x9fda9c, 0x000000, 0x9ba787, 0x000000}},
{"Kitty Default", [22]uint32{0x000000, 0xcc0403, 0x19cb00, 0xcecb00, 0x0d73cc, 0xcb1ed1, 0x0dcdcd, 0xdddddd, 0x767676, 0xf2201f, 0x23fd00, 0xfffd00, 0x1a8fff, 0xfd28ff, 0x14ffff, 0xffffff, 0x000000, 0xdddddd, 0xcccccc, 0x111111, 0xfffacd, 0x000000}},
{"Kitty Low Contrast", [22]uint32{0x000000, 0xcc0403, 0x19cb00, 0xcecb00, 0x0d73cc, 0xcb1ed1, 0x0dcdcd, 0xdddddd, 0x767676, 0xf2201f, 0x23fd00, 0xfffd00, 0x1a8fff, 0xfd28ff, 0x14ffff, 0xffffff, 0x333333, 0xffffff, 0xcccccc, 0x111111, 0xfffacd, 0x000000}},
{"Klein Void", [22]uint32{0x1a1c24, 0xf09890, 0xa6c080, 0xe8bc75, 0x002fa7, 0xd49bb5, 0x9fc0e5, 0xcdc7b8, 0x92907a, 0xd97757, 0xbcc89c, 0xf0c880, 0xa8bef0, 0xc8b4d4, 0xb0d0ed, 0xf5efde, 0x0b0d14, 0xede6d3, 0xede6d3, 0x0b0d14, 0x002fa7, 0xede6d3}},
{"Kolorit", [22]uint32{0x1d1a1e, 0xff5b82, 0x47d7a1, 0xe8e562, 0x5db4ee, 0xda6cda, 0x57e9eb, 0xededed, 0x504d51, 0xff5b82, 0x47d7a1, 0xe8e562, 0x5db4ee, 0xda6cda, 0x57e9eb, 0xededed, 0x1d1a1e, 0xefecec, 0xc7c7c7, 0x8c8c8c, 0xe1925c, 0x1d1a1e}},
{"Konsolas", [22]uint32{0x000000, 0xaa1717, 0x18b218, 0xebae1f, 0x2323a5, 0xad1edc, 0x42b0c8, 0xc8c1c1, 0x7b716e, 0xff4141, 0x5fff5f, 0xffff55, 0x4b4bff, 0xff54ff, 0x69ffff, 0xffffff, 0x060606, 0xc8c1c1, 0xc8c1c1, 0x060606, 0x060606, 0xc8c1c1}},
{"Kurokula", [22]uint32{0x333333, 0xc35a52, 0x78b3a9, 0xe1b917, 0x5c91dd, 0x8b79a6, 0x867268, 0xe0cfc2, 0x515151, 0xffc34c, 0xafffa5, 0xfff700, 0x90dbff, 0xad93ff, 0xffcdb6, 0xffffff, 0x141515, 0xe0cfc2, 0x7a1c1c, 0xfffbf2, 0x515151, 0xffc34c}},
{"Lab Fox", [22]uint32{0x2e2e2e, 0xfc6d26, 0x3eb383, 0xfca121, 0xdb3b21, 0x6b40a8, 0x6e49cb, 0xffffff, 0x535353, 0xff6517, 0x53eaa8, 0xfca013, 0xdb501f, 0x6a36b6, 0x7d53e7, 0xffffff, 0x2e2e2e, 0xffffff, 0x7f7f7f, 0xb2b2b2, 0xcb392e, 0xffffff}},
{"Laser", [22]uint32{0x626262, 0xff8373, 0xb4fb73, 0x09b4bd, 0xfed300, 0xff90fe, 0xd1d1fe, 0xf1f1f1, 0x8f8f8f, 0xffc4be, 0xd6fcba, 0xfffed5, 0xf92883, 0xffb2fe, 0xe6e7fe, 0xffffff, 0x030d18, 0xf106e3, 0x00ff9c, 0xa6a6a6, 0x2e206a, 0xf4f4f4}},
{"Later This Evening", [22]uint32{0x2b2b2b, 0xd45a60, 0xafba67, 0xe5d289, 0xa0bad6, 0xc092d6, 0x91bfb7, 0x494a4a, 0x525454, 0xd3232f, 0xaabb39, 0xe5be39, 0x6699d6, 0xab53d6, 0x5fc0ae, 0xc1c2c2, 0x222222, 0x959595, 0x4f4f4f, 0x959595, 0x424242, 0x959595}},
{"Lavandula", [22]uint32{0x230046, 0x7d1625, 0x337e6f, 0x7f6f49, 0x4f4a7f, 0x5a3f7f, 0x58777f, 0x736e7d, 0x443a53, 0xe05167, 0x52e0c4, 0xe0c386, 0x8e87e0, 0xa776e0, 0x9ad4e0, 0x8c91fa, 0x050014, 0x736e7d, 0x8c91fa, 0x050014, 0x37323c, 0x8c91fa}},
{"Lemon Graphite", [22]uint32{0x0b0f14, 0xff6b6b, 0x7bd88f, 0xf2c14e, 0x5cc8ff, 0xc792ea, 0x57d3c8, 0xdce3ea, 0x59636e, 0xff8a80, 0xa7e8b5, 0xffd978, 0x8ad8ff, 0xdab1f4, 0x86e6de, 0xf7fafc, 0x0b0f14, 0xdce3ea, 0xf2c14e, 0x0b0f14, 0xdce3ea, 0x0b0f14}},
{"Letterpress", [22]uint32{0x3a352c, 0xb0202a, 0x506b24, 0x8a5e0a, 0x2a5c8a, 0x6e4b2e, 0x176b5f, 0xaeaba4, 0x8e886f, 0xb0202a, 0x506b24, 0x8a4fa0, 0x2a5c8a, 0x176b5f, 0x176b5f, 0x3a352c, 0xf3ecdf, 0x3a352c, 0x2a5c8a, 0xf3ecdf, 0xe3d8c4, 0xa69f92}},
{"Light Owl", [22]uint32{0x403f53, 0xde3d3b, 0x08916a, 0xe0af02, 0x288ed7, 0xd6438a, 0x2aa298, 0xbdbdbd, 0x989fb1, 0xde3d3b, 0x08916a, 0xdaaa01, 0x288ed7, 0xd6438a, 0x2aa298, 0xf0f0f0, 0xfbfbfb, 0x403f53, 0x403f53, 0xf6f6f6, 0xe0e0e0, 0x403f53}},
{"Liquid Carbon", [22]uint32{0x000000, 0xff3030, 0x559a70, 0xccac00, 0x0099cc, 0xcc69c8, 0x7ac4cc, 0xbccccc, 0x595959, 0xff3030, 0x559a70, 0xccac00, 0x0099cc, 0xcc69c8, 0x7ac4cc, 0xbccccc, 0x303030, 0xafc2c2, 0xffffff, 0x000000, 0x7dbeff, 0x000000}},
{"Liquid Carbon Transparent", [22]uint32{0x000000, 0xff3030, 0x559a70, 0xccac00, 0x0099cc, 0xcc69c8, 0x7ac4cc, 0xbccccc, 0x404040, 0xff3030, 0x559a70, 0xccac00, 0x0099cc, 0xcc69c8, 0x7ac4cc, 0xbccccc, 0x000000, 0xafc2c2, 0xffffff, 0x000000, 0x7dbeff, 0x000000}},
{"London Bonfire Night", [22]uint32{0x1a1418, 0xd65a3a, 0x6a8a4a, 0xe8b048, 0x5a7ab8, 0xd76aa8, 0x88a8c8, 0xe8e0c8, 0x44403c, 0xec7654, 0x88a868, 0xf5c25c, 0x7a96d0, 0xed85bc, 0xa0bcd6, 0xfdf6df, 0x0e0c0e, 0xe8e0c8, 0xe85aa8, 0x0e0c0e, 0x2a2228, 0xe8e0c8}},
{"London Columbia Road", [22]uint32{0x2a2520, 0xc14a4a, 0x5a8a3a, 0xd4a82c, 0x3a7a8a, 0xc45f8a, 0x5fa89a, 0x1f3a2f, 0x756a55, 0xd96a6a, 0x6ea050, 0xd8af33, 0x5598ab, 0xd97aa3, 0x7ac0b0, 0x142217, 0xf8f5ec, 0x1f3a2f, 0xd4708e, 0xf8f5ec, 0xece5d0, 0x1f3a2f}},
{"London Embankment Dusk", [22]uint32{0x1c2533, 0xc5573f, 0x6a8e85, 0xe2bd5c, 0x5e87b3, 0x9b86a8, 0x82a8b8, 0xe8eef2, 0x4a566a, 0xe07050, 0x88aaa3, 0xf0cd6c, 0x82a4cc, 0xb09bc0, 0xa0c2d0, 0xfafbfc, 0x161f2c, 0xe8eef2, 0xf2c455, 0x161f2c, 0x2c3a52, 0xe8eef2}},
{"London Soho Night", [22]uint32{0x2a221a, 0xd4574a, 0x8fae5e, 0xe8b04a, 0x6a8fb5, 0xd96aa5, 0x9ab8a8, 0xebe0c8, 0x6b5a48, 0xe87765, 0xaac874, 0xf4c560, 0x88a8c8, 0xed85b8, 0xb8cebd, 0xf8eed2, 0x1a1612, 0xebe0c8, 0xff5db1, 0x1a1612, 0x3a2f24, 0xebe0c8}},
{"Lovelace", [22]uint32{0x282a36, 0xf37f97, 0x5adecd, 0xf2a272, 0x8897f4, 0xc574dd, 0x79e6f3, 0xfdfdfd, 0x4e5165, 0xff4971, 0x18e3c8, 0xff8037, 0x556fff, 0xb043d1, 0x3fdcee, 0xbebec1, 0x1d1f28, 0xfdfdfd, 0xc574dd, 0xffffff, 0xc1deff, 0x000000}},
{"Man Page", [22]uint32{0x000000, 0xcc0000, 0x00a600, 0x999900, 0x0000b2, 0xb200b2, 0x00a6b2, 0xb2b2b2, 0x666666, 0xe50000, 0x00cc00, 0xbfbf00, 0x0000ff, 0xe500e5, 0x00cbcb, 0xe5e5e5, 0xfef49c, 0x000000, 0x7f7f7f, 0x000000, 0xa4c9cd, 0x000000}},
{"Mariana", [22]uint32{0x000000, 0xec5f66, 0x99c794, 0xf9ae58, 0x6699cc, 0xc695c6, 0x5fb4b4, 0xf7f7f7, 0x666666, 0xf97b58, 0xacd1a8, 0xfac761, 0x85add6, 0xd8b6d8, 0x82c4c4, 0xffffff, 0x343d46, 0xd8dee9, 0xfcbb6a, 0x8c8c8c, 0x4e5a65, 0xd8dee9}},
{"Matcha Zen", [22]uint32{0x354029, 0xc2452a, 0x4e8c2e, 0x927000, 0x2e7c78, 0x7e5ba6, 0x2a8585, 0x56664a, 0x97a887, 0xc2452a, 0x4e8c2e, 0xb05a1e, 0x2e7c78, 0x7e5ba6, 0x2a8585, 0x354029, 0xf5f7ea, 0x354029, 0x4e8c2e, 0xf5f7ea, 0xdde7cc, 0xa8aa9d}},
{"Material", [22]uint32{0x212121, 0xb7141f, 0x457b24, 0xf6981e, 0x134eb2, 0x560088, 0x0e717c, 0xafafaf, 0x424242, 0xe83b3f, 0x7aba3a, 0xbfaa00, 0x54a4f3, 0xaa4dbc, 0x26bbd1, 0xd9d9d9, 0xeaeaea, 0x232322, 0x16afca, 0x2e2e2d, 0xc2c2c2, 0x4e4e4e}},
{"Material Dark", [22]uint32{0x212121, 0xb7141f, 0x457b24, 0xf6981e, 0x134eb2, 0x701aa2, 0x0e717c, 0xefefef, 0x4f4f4f, 0xe83b3f, 0x7aba3a, 0xffea2e, 0x54a4f3, 0xaa4dbc, 0x26bbd1, 0xd9d9d9, 0x232322, 0xe5e5e5, 0x16afca, 0xdfdfdf, 0xdfdfdf, 0x3d3d3d}},
{"Material Darker", [22]uint32{0x000000, 0xff5370, 0xc3e88d, 0xffcb6b, 0x82aaff, 0xc792ea, 0x89ddff, 0xffffff, 0x545454, 0xff5370, 0xc3e88d, 0xffcb6b, 0x82aaff, 0xc792ea, 0x89ddff, 0xffffff, 0x212121, 0xeeffff, 0xffffff, 0xbfbfbf, 0xeeffff, 0x545454}},
{"Material Design Colors", [22]uint32{0x435b67, 0xfc3841, 0x5cf19e, 0xfed032, 0x37b6ff, 0xfc226e, 0x59ffd1, 0xffffff, 0xa1b0b8, 0xfc746d, 0xadf7be, 0xfee16c, 0x70cfff, 0xfc669b, 0x9affe6, 0xffffff, 0x1d262a, 0xe7ebed, 0xeaeaea, 0x000000, 0x4e6a78, 0xe7ebed}},
{"Material Ocean", [22]uint32{0x546e7a, 0xff5370, 0xc3e88d, 0xffcb6b, 0x82aaff, 0xc792ea, 0x89ddff, 0xffffff, 0x546e7a, 0xff5370, 0xc3e88d, 0xffcb6b, 0x82aaff, 0xc792ea, 0x89ddff, 0xffffff, 0x0f111a, 0x8f93a2, 0xffcc00, 0x0f111a, 0x1f2233, 0x8f93a2}},
{"Mathias", [22]uint32{0x000000, 0xe52222, 0xa6e32d, 0xfc951e, 0xc48dff, 0xfa2573, 0x67d9f0, 0xf2f2f2, 0x555555, 0xff5555, 0x55ff55, 0xffff55, 0x5555ff, 0xff55ff, 0x55ffff, 0xffffff, 0x000000, 0xbbbbbb, 0xbbbbbb, 0xffffff, 0x555555, 0xf2f2f2}},
{"Matrix", [22]uint32{0x0f191c, 0x23755a, 0x82d967, 0xffd700, 0x3f5242, 0x409931, 0x50b45a, 0x507350, 0x688060, 0x2fc079, 0x90d762, 0xfaff00, 0x4f7e7e, 0x11ff25, 0xc1ff8a, 0x678c61, 0x0f191c, 0x426644, 0x384545, 0x00ff00, 0x18282e, 0x00ff87}},
{"Matte Black", [22]uint32{0x333333, 0xd35f5f, 0xffc107, 0xb91c1c, 0xe68e0d, 0xd35f5f, 0xbebebe, 0xbebebe, 0x8a8a8d, 0x891c1c, 0xffc107, 0xb90a0a, 0xf59e0b, 0xb91c1c, 0xeaeaea, 0xffffff, 0x121212, 0xbebebe, 0xeaeaea, 0x121212, 0x333333, 0xeaeaea}},
{"Medallion", [22]uint32{0x000000, 0xb64c00, 0x7c8b16, 0xd3bd26, 0x616bb0, 0x8c5a90, 0x916c25, 0xcac29a, 0x5e5219, 0xff9149, 0xb2ca3b, 0xffe54a, 0xacb8ff, 0xffa0ff, 0xffbc51, 0xfed698, 0x1d1908, 0xcac296, 0xd3ba30, 0xfffc7d, 0x626dac, 0xcac29a}},
{"Melange Dark", [22]uint32{0x34302c, 0xbd8183, 0x78997a, 0xe49b5d, 0x7f91b2, 0xb380b0, 0x7b9695, 0xc1a78e, 0x867462, 0xd47766, 0x85b695, 0xebc06d, 0xa3a9ce, 0xcf9bc2, 0x89b3b6, 0xece1d7, 0x292522, 0xece1d7, 0xece1d7, 0x292522, 0xece1d7, 0x403a36}},
{"Melange Light", [22]uint32{0xe9e1db, 0xc77b8b, 0x6e9b72, 0xbc5c00, 0x7892bd, 0xbe79bb, 0x739797, 0x7d6658, 0xa98a78, 0xbf0021, 0x3a684a, 0xa06d00, 0x465aa4, 0x904180, 0x3d6568, 0x54433a, 0xf1f1f1, 0x54433a, 0x54433a, 0xf1f1f1, 0x54433a, 0xd9d3ce}},
{"Mellifluous", [22]uint32{0x1a1a1a, 0xd29393, 0xb3b393, 0xcbaa89, 0xa8a1be, 0xb39fb0, 0xc0af8c, 0xdadada, 0x5b5b5b, 0xc95954, 0x828040, 0xa6794c, 0x5a6599, 0x9c6995, 0x74a39e, 0xffffff, 0x1a1a1a, 0xdadada, 0xbfad9e, 0x1a1a1a, 0x2d2d2d, 0xc0af8c}},
{"Mellow", [22]uint32{0x27272a, 0xf5a191, 0x90b99f, 0xe6b99d, 0xaca1cf, 0xe29eca, 0xea83a5, 0xc1c0d4, 0x424246, 0xffae9f, 0x9dc6ac, 0xf0c5a9, 0xb9aeda, 0xecaad6, 0xf591b2, 0xcac9dd, 0x161617, 0xc9c7cd, 0xcac9dd, 0x161617, 0x2a2a2d, 0xc1c0d4}},
{"Mesila One", [22]uint32{0x101418, 0x93867f, 0x5cc8ff, 0xebb3a9, 0xdec1ff, 0x7d70ba, 0x5cc8ff, 0xe9fae3, 0x7d70ba, 0x93867f, 0x5cc8ff, 0xebb3a9, 0xdec1ff, 0x7d70ba, 0x5cc8ff, 0xe9fae3, 0x1b1f23, 0xe9fae3, 0x5cc8ff, 0x1b1f23, 0x334155, 0x676b6f}},
{"Miami Heat", [22]uint32{0x2a1a4a, 0xff3d7f, 0x2ee6b6, 0xffcb52, 0x29b6ff, 0xb86bff, 0x18e0ff, 0xe6d4ff, 0x5e5388, 0xff2e97, 0x2ee6b6, 0xff7847, 0x29b6ff, 0xb86bff, 0x18e0ff, 0xfce7ff, 0x120b2e, 0xfce7ff, 0xff2e97, 0x120b2e, 0x34215c, 0x5e577a}},
{"Miasma", [22]uint32{0x000000, 0x685742, 0x5f875f, 0xb36d43, 0x78824b, 0xbb7744, 0xc9a554, 0xd7c483, 0x666666, 0x685742, 0x5f875f, 0xb36d43, 0x78824b, 0xbb7744, 0xc9a554, 0xd7c483, 0x222222, 0xc2c2b0, 0xc7c7c7, 0x959595, 0xe5c47b, 0x000000}},
{"Midnight Arcade", [22]uint32{0x3f4550, 0xfb7185, 0x22c55e, 0xfbbf24, 0x60a5fa, 0xe879f9, 0x22d3ee, 0xb6c2d5, 0x3d4452, 0xfc8d9d, 0x4ed17e, 0xfccb4b, 0x80b7fb, 0xed94fa, 0x4edcf1, 0xf8fafc, 0x0b1220, 0xf8fafc, 0xf8fafc, 0x0b1220, 0xf8fafc, 0x0b1220}},
{"Midnight In Mojave", [22]uint32{0x1e1e1e, 0xff453a, 0x32d74b, 0xffd60a, 0x0a84ff, 0xbf5af2, 0x5ac8fa, 0xffffff, 0x515151, 0xff453a, 0x32d74b, 0xffd60a, 0x0a84ff, 0xbf5af2, 0x5ac8fa, 0xffffff, 0x1e1e1e, 0xffffff, 0x32d74b, 0x1c1c1c, 0x4a504d, 0xffffff}},
{"Mirage", [22]uint32{0x011627, 0xff9999, 0x85cc95, 0xffd700, 0x7fb5ff, 0xddb3ff, 0x21c7a8, 0xffffff, 0x575656, 0xff9999, 0x85cc95, 0xffd700, 0x7fb5ff, 0xddb3ff, 0x85cc95, 0xffffff, 0x1b2738, 0xa6b2c0, 0xddb3ff, 0xffffff, 0x273951, 0xd3dbe5}},
{"Misterioso", [22]uint32{0x000000, 0xff4242, 0x74af68, 0xffad29, 0x338f86, 0x9414e6, 0x23d7d7, 0xe1e1e0, 0x626262, 0xff3242, 0x74cd68, 0xffb929, 0x23d7d7, 0xff37ff, 0x00ede1, 0xffffff, 0x2d3743, 0xe1e1e0, 0x666666, 0xffffff, 0x2d37ff, 0x000000}},
{"Modus Operandi", [22]uint32{0x000000, 0xa60000, 0x006800, 0x6f5500, 0x0031a9, 0x721045, 0x005e8b, 0xa6a6a6, 0x595959, 0x972500, 0x00663f, 0x884900, 0x3548cf, 0x531ab6, 0x005f5f, 0x595959, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xbdbdbd, 0x000000}},
{"Modus Operandi Deuteranopia", [22]uint32{0x000000, 0xa60000, 0x006800, 0x695500, 0x0031a9, 0x721045, 0x005e8b, 0xa6a6a6, 0x595959, 0x972500, 0x00663f, 0x973300, 0x3548cf, 0x531ab6, 0x005f5f, 0x595959, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xbdbdbd, 0x000000}},
{"Modus Operandi Tinted", [22]uint32{0x000000, 0xa60000, 0x006800, 0x6f5500, 0x0031a9, 0x721045, 0x005e8b, 0xa6a6a6, 0x595959, 0x972500, 0x00663f, 0x884900, 0x3548cf, 0x531ab6, 0x005f5f, 0x595959, 0xfbf7f0, 0x000000, 0xd00000, 0xfbf7f0, 0xc2bcb5, 0x000000}},
{"Modus Operandi Tritanopia", [22]uint32{0x000000, 0xa60000, 0x006800, 0x695500, 0x0031a9, 0x721045, 0x005e8b, 0xa6a6a6, 0x595959, 0xb21100, 0x00663f, 0x973300, 0x3548cf, 0x531ab6, 0x005f5f, 0x595959, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xbdbdbd, 0x000000}},
{"Modus Vivendi", [22]uint32{0x000000, 0xff5f59, 0x44bc44, 0xd0bc00, 0x2fafff, 0xfeacd0, 0x00d3d0, 0xa6a6a6, 0x595959, 0xff7f9f, 0x00c06f, 0xfec43f, 0x79a8ff, 0xb6a0ff, 0x6ae4b9, 0xffffff, 0x000000, 0xffffff, 0xffffff, 0x000000, 0x5a5a5a, 0xffffff}},
{"Modus Vivendi Deuteranopia", [22]uint32{0x000000, 0xff5f59, 0x44bc44, 0xcabf00, 0x2fafff, 0xfeacd0, 0x00d3d0, 0xa6a6a6, 0x595959, 0xff7f9f, 0x00c06f, 0xffa00f, 0x79a8ff, 0xb6a0ff, 0x6ae4b9, 0xffffff, 0x000000, 0xffffff, 0xffffff, 0x000000, 0x5a5a5a, 0xffffff}},
{"Modus Vivendi Tinted", [22]uint32{0x0d0e1c, 0xff5f59, 0x44bc44, 0xd0bc00, 0x2fafff, 0xfeacd0, 0x00d3d0, 0xa6a6a6, 0x595959, 0xff6b55, 0x00c06f, 0xfec43f, 0x79a8ff, 0xb6a0ff, 0x6ae4b9, 0xffffff, 0x0d0e1c, 0xffffff, 0xff66ff, 0x0d0e1c, 0x555a66, 0xffffff}},
{"Modus Vivendi Tritanopia", [22]uint32{0x000000, 0xff5f59, 0x44bc44, 0xcabf00, 0x2fafff, 0xfeacd0, 0x00d3d0, 0xa6a6a6, 0x595959, 0xff6740, 0x00c06f, 0xffa00f, 0x79a8ff, 0xb6a0ff, 0x6ae4b9, 0xffffff, 0x000000, 0xffffff, 0xffffff, 0x000000, 0x5a5a5a, 0xffffff}},
{"Molokai", [22]uint32{0x121212, 0xfa2573, 0x98e123, 0xdfd460, 0x1080d0, 0x8700ff, 0x43a8d0, 0xbbbbbb, 0x555555, 0xf6669d, 0xb1e05f, 0xfff26d, 0x00afff, 0xaf87ff, 0x51ceff, 0xffffff, 0x121212, 0xbbbbbb, 0xbbbbbb, 0xffffff, 0xb5d5ff, 0x000000}},
{"Mona Lisa", [22]uint32{0x351b0e, 0x9b291c, 0x636232, 0xc36e28, 0x515c5d, 0x9b1d29, 0x588056, 0xf7d75c, 0x874228, 0xff4331, 0xb4b264, 0xff9566, 0x9eb2b4, 0xff5b6a, 0x8acd8f, 0xffe598, 0x120b0d, 0xf7d66a, 0xc46c32, 0x120b0d, 0xf7d66a, 0x120b0d}},
{"Monokai Classic", [22]uint32{0x272822, 0xf92672, 0xa6e22e, 0xe6db74, 0xfd971f, 0xae81ff, 0x66d9ef, 0xfdfff1, 0x6e7066, 0xf92672, 0xa6e22e, 0xe6db74, 0xfd971f, 0xae81ff, 0x66d9ef, 0xfdfff1, 0x272822, 0xfdfff1, 0xc0c1b5, 0x8d8e82, 0x57584f, 0xfdfff1}},
{"Monokai Pro", [22]uint32{0x2d2a2e, 0xff6188, 0xa9dc76, 0xffd866, 0xfc9867, 0xab9df2, 0x78dce8, 0xfcfcfa, 0x727072, 0xff6188, 0xa9dc76, 0xffd866, 0xfc9867, 0xab9df2, 0x78dce8, 0xfcfcfa, 0x2d2a2e, 0xfcfcfa, 0xc1c0c0, 0x8e8d8d, 0x5b595c, 0xfcfcfa}},
{"Monokai Pro Light", [22]uint32{0xfaf4f2, 0xe14775, 0x269d69, 0xcc7a0a, 0xe16032, 0x7058be, 0x1c8ca8, 0x29242a, 0xa59fa0, 0xe14775, 0x269d69, 0xcc7a0a, 0xe16032, 0x7058be, 0x1c8ca8, 0x29242a, 0xfaf4f2, 0x29242a, 0x706b6e, 0xa39ea1, 0xbfb9ba, 0x29242a}},
{"Monokai Pro Light Sun", [22]uint32{0xf8efe7, 0xce4770, 0x218871, 0xb16803, 0xd4572b, 0x6851a2, 0x2473b6, 0x2c232e, 0xa59c9c, 0xce4770, 0x218871, 0xb16803, 0xd4572b, 0x6851a2, 0x2473b6, 0x2c232e, 0xf8efe7, 0x2c232e, 0x72696d, 0xa59ca0, 0xbeb5b3, 0x2c232e}},
{"Monokai Pro Machine", [22]uint32{0x273136, 0xff6d7e, 0xa2e57b, 0xffed72, 0xffb270, 0xbaa0f8, 0x7cd5f1, 0xf2fffc, 0x6b7678, 0xff6d7e, 0xa2e57b, 0xffed72, 0xffb270, 0xbaa0f8, 0x7cd5f1, 0xf2fffc, 0x273136, 0xf2fffc, 0xb8c4c3, 0x859190, 0x545f62, 0xf2fffc}},
{"Monokai Pro Octagon", [22]uint32{0x282a3a, 0xff657a, 0xbad761, 0xffd76d, 0xff9b5e, 0xc39ac9, 0x9cd1bb, 0xeaf2f1, 0x696d77, 0xff657a, 0xbad761, 0xffd76d, 0xff9b5e, 0xc39ac9, 0x9cd1bb, 0xeaf2f1, 0x282a3a, 0xeaf2f1, 0xb2b9bd, 0xf2f9fd, 0x535763, 0xeaf2f1}},
{"Monokai Pro Ristretto", [22]uint32{0x2c2525, 0xfd6883, 0xadda78, 0xf9cc6c, 0xf38d70, 0xa8a9eb, 0x85dacc, 0xfff1f3, 0x72696a, 0xfd6883, 0xadda78, 0xf9cc6c, 0xf38d70, 0xa8a9eb, 0x85dacc, 0xfff1f3, 0x2c2525, 0xfff1f3, 0xc3b7b8, 0xfff7f8, 0x5b5353, 0xfff1f3}},
{"Monokai Pro Spectrum", [22]uint32{0x222222, 0xfc618d, 0x7bd88f, 0xfce566, 0xfd9353, 0x948ae3, 0x5ad4e6, 0xf7f1ff, 0x69676c, 0xfc618d, 0x7bd88f, 0xfce566, 0xfd9353, 0x948ae3, 0x5ad4e6, 0xf7f1ff, 0x222222, 0xf7f1ff, 0xbab6c0, 0xfaf6ff, 0x525053, 0xf7f1ff}},
{"Monokai Remastered", [22]uint32{0x1a1a1a, 0xf4005f, 0x98e024, 0xfd971f, 0x9d65ff, 0xf4005f, 0x58d1eb, 0xc4c5b5, 0x625e4c, 0xf4005f, 0x98e024, 0xe0d561, 0x9d65ff, 0xf4005f, 0x58d1eb, 0xf6f6ef, 0x0c0c0c, 0xd9d9d9, 0xfc971f, 0x000000, 0x343434, 0xffffff}},
{"Monokai Soda", [22]uint32{0x1a1a1a, 0xf4005f, 0x98e024, 0xfa8419, 0x9d65ff, 0xf4005f, 0x58d1eb, 0xc4c5b5, 0x625e4c, 0xf4005f, 0x98e024, 0xe0d561, 0x9d65ff, 0xf4005f, 0x58d1eb, 0xf6f6ef, 0x1a1a1a, 0xc4c5b5, 0xf6f7ec, 0xb7b8a8, 0x343434, 0xc4c5b5}},
{"Monokai SublimeText", [22]uint32{0x333333, 0xc4265e, 0x86b42b, 0xb3b42b, 0x6a7ec8, 0x8c6bc8, 0x56adbc, 0xe3e3dd, 0x666666, 0xf92672, 0xa6e22e, 0xe2e22e, 0x819aff, 0xae81ff, 0x66d9ef, 0xf8f8f2, 0x272822, 0xf8f8f2, 0xf8f8f0, 0x272822, 0x49483e, 0xf8f8f2}},
{"Monokai Vivid", [22]uint32{0x121212, 0xfa2934, 0x98e123, 0xfff30a, 0x0443ff, 0xf800f8, 0x01b6ed, 0xffffff, 0x838383, 0xf6669d, 0xb1e05f, 0xfff26d, 0x0443ff, 0xf200f6, 0x51ceff, 0xffffff, 0x121212, 0xf9f9f9, 0xfb0007, 0xff8c95, 0xffffff, 0x000000}},
{"Monospace Dark", [22]uint32{0x738295, 0xf76769, 0x17b877, 0xffa23e, 0x708fff, 0xa87ffb, 0x25a6e9, 0xa4afbd, 0x8b98a9, 0xfc8f8e, 0x66ce98, 0xffc26e, 0xa2b6ff, 0xc8aaff, 0x71c2ee, 0xfafbfe, 0x10151d, 0xa4afbd, 0xc8aaff, 0x10151d, 0x264dcb, 0xd9dfe7}},
{"Monospace Light", [22]uint32{0x333e4f, 0xd03941, 0x007b49, 0xa65921, 0x3c60dd, 0x6f4cde, 0x0075a2, 0x5d6a7d, 0x000000, 0xa52430, 0x00522f, 0x904b1a, 0x002487, 0x4d21bb, 0x00607e, 0x475365, 0xf4f7fd, 0x475365, 0x6f4cde, 0xf4f7fd, 0xc7d3ff, 0x1f2939}},
{"Moonfly", [22]uint32{0x323437, 0xff5454, 0x8cc85f, 0xe3c78a, 0x80a0ff, 0xcf87e8, 0x79dac8, 0xc6c6c6, 0x949494, 0xff5189, 0x36c692, 0xc6c684, 0x74b2ff, 0xae81ff, 0x85dc85, 0xe4e4e4, 0x080808, 0xbdbdbd, 0x9e9e9e, 0x080808, 0xb2ceee, 0x080808}},
{"Moonwalk", [22]uint32{0x080808, 0x7a0047, 0x145b0e, 0x733a11, 0x002fa7, 0x5400a8, 0x00566b, 0x9c958d, 0x494440, 0xaf1608, 0x4c6129, 0x7a5000, 0x0d50c5, 0x952197, 0x006092, 0xffffff, 0xe4e2e0, 0x061f4a, 0x061f4a, 0xe4e2e0, 0xb8d2e5, 0x061f4a}},
{"N0Tch2K", [22]uint32{0x383838, 0xa95551, 0x666666, 0xa98051, 0x657d3e, 0x767676, 0xc9c9c9, 0xd0b8a3, 0x545454, 0xa97775, 0x8c8c8c, 0xa99175, 0x98bd5e, 0xa3a3a3, 0xdcdcdc, 0xd8c8bb, 0x222222, 0xa0a0a0, 0xaa9175, 0x000000, 0x4d4d4d, 0xffffff}},
{"Nachtschicht", [22]uint32{0x0e1012, 0xe5484d, 0x33d17a, 0xe3b341, 0x4d7cfe, 0xc86ad8, 0x3fc8b0, 0xc9cfd6, 0x9da4af, 0xef8f92, 0x76e0a5, 0xedcf88, 0x9eb8fe, 0xe0abe9, 0x7edaca, 0xe8eaed, 0x17191d, 0xe8eaed, 0xe3b341, 0x17191d, 0x36393c, 0xe8eaed}},
{"Nebula Drift", [22]uint32{0x1a0e38, 0xff5c8d, 0x66e6a8, 0xffcb6b, 0x7c9bff, 0xc77dff, 0x57e6f0, 0xc8c6e8, 0x5c5a88, 0xff5c8d, 0x66e6a8, 0xff9e64, 0x7c9bff, 0xc77dff, 0x57e6f0, 0xe2e0fa, 0x0a0420, 0xe2e0fa, 0xd58bff, 0x0a0420, 0x221645, 0x4a4460}},
{"Neobones Dark", [22]uint32{0x0f191f, 0xde6e7c, 0x90ff6b, 0xb77e64, 0x8190d4, 0xb279a7, 0x66a5ad, 0xc6d5cf, 0x334652, 0xe8838f, 0xa0ff85, 0xd68c67, 0x92a0e2, 0xcf86c1, 0x65b8c1, 0x98a39e, 0x0f191f, 0xc6d5cf, 0xceddd7, 0x0f191f, 0x3a3e3d, 0xc6d5cf}},
{"Neobones Light", [22]uint32{0xe5ede6, 0xa8334c, 0x567a30, 0x944927, 0x286486, 0x88507d, 0x3b8992, 0x202e18, 0x99ac9c, 0x94253e, 0x3f5a22, 0x803d1c, 0x1d5573, 0x7b3b70, 0x2b747c, 0x415934, 0xe5ede6, 0x202e18, 0x202e18, 0xe5ede6, 0xade48c, 0x202e18}},
{"Neon", [22]uint32{0x000000, 0xff3045, 0x5ffa74, 0xfffc7e, 0x0f15d8, 0xf924e7, 0x00fffc, 0xc7c7c7, 0x686868, 0xff5a5a, 0x75ff88, 0xfffd96, 0x3c40cb, 0xf15be5, 0x88fffe, 0xffffff, 0x14161a, 0x00fffc, 0xc7c7c7, 0x8c8c8c, 0x0013ff, 0x08d2cf}},
{"Neon Purple", [22]uint32{0x000000, 0xcd0d76, 0x03eba5, 0xfffa6a, 0x00bfff, 0xff00e0, 0x9aa5ed, 0xffffff, 0xa8fcff, 0xff0da5, 0x00ffb6, 0xfff787, 0x1bccfd, 0xff00f8, 0xa6b6ff, 0xffffff, 0x291b47, 0xe5e5e5, 0x21f6bc, 0x999999, 0xc1deff, 0x000000}},
{"Neopolitan", [22]uint32{0x000000, 0x9a1a1a, 0x61ce3c, 0xfbde2d, 0x324883, 0xff0080, 0x8da6ce, 0xf8f8f8, 0x4c4c4c, 0x9a1a1a, 0x61ce3c, 0xfbde2d, 0x324883, 0xff0080, 0x8da6ce, 0xf8f8f8, 0x271f19, 0xffffff, 0xffffff, 0xbfbfbf, 0x253b76, 0xffffff}},
{"Neutron", [22]uint32{0x23252b, 0xb54036, 0x5ab977, 0xdeb566, 0x6a7c93, 0xa4799d, 0x3f94a8, 0xe6e8ef, 0x494b51, 0xb54036, 0x5ab977, 0xdeb566, 0x6a7c93, 0xa4799d, 0x3f94a8, 0xebedf2, 0x1c1e22, 0xe6e8ef, 0xf6f7ec, 0xb7b8a8, 0x2f363e, 0x7d8fa4}},
{"Night Lion V1", [22]uint32{0x4c4c4c, 0xbb0000, 0x5fde8f, 0xf3f167, 0x276bd8, 0xbb00bb, 0x00dadf, 0xbbbbbb, 0x555555, 0xff5555, 0x55ff55, 0xffff55, 0x5555ff, 0xff55ff, 0x55ffff, 0xffffff, 0x000000, 0xbbbbbb, 0xbbbbbb, 0xffffff, 0xb5d5ff, 0x000000}},
{"Night Lion V2", [22]uint32{0x4c4c4c, 0xbb0000, 0x04f623, 0xf3f167, 0x64d0f0, 0xce6fdb, 0x00dadf, 0xbbbbbb, 0x555555, 0xff5555, 0x7df71d, 0xffff55, 0x62cbe8, 0xff9bf5, 0x00ccd8, 0xffffff, 0x171717, 0xbbbbbb, 0xbbbbbb, 0xffffff, 0xb5d5ff, 0x000000}},
{"Night Owl", [22]uint32{0x011627, 0xef5350, 0x22da6e, 0xaddb67, 0x82aaff, 0xc792ea, 0x21c7a8, 0xffffff, 0x575656, 0xef5350, 0x22da6e, 0xffeb95, 0x82aaff, 0xc792ea, 0x7fdbca, 0xffffff, 0x011627, 0xd6deeb, 0x7e57c2, 0xffffff, 0x5f7e97, 0xdfe5ee}},
{"Night Owlish Light", [22]uint32{0x011627, 0xd3423e, 0x2aa298, 0xdaaa01, 0x4876d6, 0x403f53, 0x08916a, 0x7a8181, 0x7a8181, 0xf76e6e, 0x49d0c5, 0xdac26b, 0x5ca7e4, 0x697098, 0x00c990, 0x989fb1, 0xffffff, 0x403f53, 0x403f53, 0xfbfbfb, 0xf2f2f2, 0x403f53}},
{"Nightfox", [22]uint32{0x393b44, 0xc94f6d, 0x81b29a, 0xdbc074, 0x719cd6, 0x9d79d6, 0x63cdcf, 0xdfdfe0, 0x575860, 0xd16983, 0x8ebaa4, 0xe0c989, 0x86abdc, 0xbaa1e2, 0x7ad5d6, 0xe4e4e5, 0x192330, 0xcdcecf, 0xcdcecf, 0x192330, 0x2b3b51, 0xcdcecf}},
{"Niji", [22]uint32{0x333333, 0xd23e08, 0x54ca74, 0xfff700, 0x2ab9ff, 0xff50da, 0x1ef9f5, 0xddd0c4, 0x515151, 0xffb7b7, 0xc1ffae, 0xfcffb8, 0x8efff3, 0xffa2ed, 0xbcffc7, 0xffffff, 0x141515, 0xffffff, 0xffc663, 0x141515, 0x515151, 0xffc663}},
{"No Clown Fiesta", [22]uint32{0x151515, 0xb46958, 0x90a959, 0xf4bf75, 0xbad7ff, 0xaa759f, 0x88afa2, 0xe1e1e1, 0x727272, 0x7e97ab, 0x90a959, 0xf4bf75, 0xbad7ff, 0xaa759f, 0x88afa2, 0xafafaf, 0x101010, 0xe0e1e4, 0xe0e1e4, 0x18191b, 0x696d79, 0xe0e1e4}},
{"No Clown Fiesta Light", [22]uint32{0xd6d6d6, 0x874e42, 0x677940, 0xb89058, 0x8ba1bf, 0xaa759f, 0x3e5f66, 0x151515, 0x2b2b2b, 0x637786, 0x677940, 0xb89058, 0x93a2ab, 0xaa759f, 0x99ab93, 0x373737, 0xe1e1e1, 0x151515, 0x151515, 0xd0d0d0, 0xc6d5de, 0x151515}},
{"Noctis", [22]uint32{0x324a4d, 0xe66533, 0x49e9a6, 0xe4b781, 0x49ace9, 0xdf769b, 0x49d6e9, 0xb2cacd, 0x47686c, 0xe97749, 0x60ebb1, 0xe69533, 0x60b6eb, 0xe798b3, 0x60dbeb, 0xc1d4d7, 0x052529, 0xb2cacd, 0xb2cacd, 0x052529, 0x0f3a3f, 0xb2cacd}},
{"Noctis Azureus", [22]uint32{0x28353e, 0xe66533, 0x49e9a6, 0xe4b781, 0x49ace9, 0xdf769b, 0x49d6e9, 0xaec3d0, 0x475e6c, 0xe97749, 0x60ebb1, 0xe69533, 0x60b6eb, 0xe798b3, 0x60dbeb, 0xbecfda, 0x07273b, 0xbecfda, 0xbecfda, 0x07273b, 0x103850, 0xbecfda}},
{"Noctis Bordo", [22]uint32{0x47393e, 0xe66533, 0x49e9a6, 0xe4b781, 0x49ace9, 0xdf769b, 0x49d6e9, 0xb9acb0, 0x69545b, 0xe97749, 0x60ebb1, 0xe69533, 0x60b6eb, 0xe798b3, 0x60dbeb, 0xcbbec2, 0x322a2d, 0xcbbec2, 0xcbbec2, 0x322a2d, 0x4a3339, 0xcbbec2}},
{"Noctis Hibernus", [22]uint32{0x003b42, 0xe34e1c, 0x00b368, 0xf49725, 0x0094f0, 0xff5792, 0x00bdd6, 0x8ca6a6, 0x004d57, 0xff4000, 0x00d17a, 0xff8c00, 0x0fa3ff, 0xff6b9f, 0x00cbe6, 0xbbc3c4, 0xf4f6f6, 0x005661, 0x005661, 0xf4f6f6, 0xd9e0e0, 0x005661}},
{"Noctis Lilac", [22]uint32{0x0c006b, 0xe34e1c, 0x00b368, 0xf49725, 0x0094f0, 0xff5792, 0x00bdd6, 0x8ca6a6, 0x0f0080, 0xff4000, 0x00d17a, 0xff8c00, 0x0fa3ff, 0xff6b9f, 0x00cbe6, 0xbbc3c4, 0xf2f1f8, 0x0c006b, 0x0c006b, 0xf2f1f8, 0xd5d3e5, 0x0c006b}},
{"Noctis Lux", [22]uint32{0x003b42, 0xe34e1c, 0x00b368, 0xf49725, 0x0094f0, 0xff5792, 0x00bdd6, 0x8ca6a6, 0x004d57, 0xff4000, 0x00d17a, 0xff8c00, 0x0fa3ff, 0xff6b9f, 0x00cbe6, 0xbbc3c4, 0xfef8ec, 0x005661, 0x005661, 0xfef8ec, 0xf4e2b8, 0x005661}},
{"Noctis Minimus", [22]uint32{0x182a35, 0xc08872, 0x72c09f, 0xc8a984, 0x6196b8, 0xc28097, 0x72b7c0, 0xc5cdd3, 0x425866, 0xca8468, 0x84c8ab, 0xd1aa7b, 0x68a4ca, 0xc88da2, 0x84c0c8, 0xc5d1d3, 0x1b2932, 0xc5cdd3, 0xc5cdd3, 0x1b2932, 0x263c4a, 0xc5cdd3}},
{"Noctis Obscuro", [22]uint32{0x324a4d, 0xe66533, 0x49e9a6, 0xe4b781, 0x49ace9, 0xdf769b, 0x49d6e9, 0xb2cacd, 0x47686c, 0xe97749, 0x60ebb1, 0xe69533, 0x60b6eb, 0xe798b3, 0x60dbeb, 0xc1d4d7, 0x031417, 0xb2cacd, 0xb2cacd, 0x031417, 0x0d2a2f, 0xb2cacd}},
{"Noctis Sereno", [22]uint32{0x324a4d, 0xe66533, 0x49e9a6, 0xe4b781, 0x49ace9, 0xdf769b, 0x49d6e9, 0xb2cacd, 0x47686c, 0xe97749, 0x60ebb1, 0xe69533, 0x60b6eb, 0xe798b3, 0x60dbeb, 0xc1d4d7, 0x062e32, 0xb2cacd, 0xb2cacd, 0x062e32, 0x0f4045, 0xb2cacd}},
{"Noctis Uva", [22]uint32{0x302f3d, 0xe66533, 0x49e9a6, 0xe4b781, 0x49ace9, 0xdf769b, 0x49d6e9, 0xb6b3cc, 0x504e65, 0xe97749, 0x60ebb1, 0xe69533, 0x60b6eb, 0xe798b3, 0x60dbeb, 0xc5c2d6, 0x292640, 0xc5c2d6, 0xc5c2d6, 0x292640, 0x35325a, 0xc5c2d6}},
{"Noctis Viola", [22]uint32{0x362f3d, 0xe66533, 0x49e9a6, 0xe4b781, 0x49ace9, 0xdf769b, 0x49d6e9, 0xbfafcf, 0x594e65, 0xe97749, 0x60ebb1, 0xe69533, 0x60b6eb, 0xe798b3, 0x60dbeb, 0xccbfd9, 0x30243d, 0xccbfd9, 0xccbfd9, 0x30243d, 0x3e3352, 0xccbfd9}},
{"Nocturnal Winter", [22]uint32{0x4d4d4d, 0xf12d52, 0x09cd7e, 0xf5f17a, 0x3182e0, 0xff2b6d, 0x09c87a, 0xfcfcfc, 0x808080, 0xf16d86, 0x0ae78d, 0xfffc67, 0x6096ff, 0xff78a2, 0x0ae78d, 0xffffff, 0x0d0d17, 0xe6e5e5, 0xe6e5e5, 0xa6a6a6, 0xadbdd0, 0x000000}},
{"Nord", [22]uint32{0x3b4252, 0xbf616a, 0xa3be8c, 0xebcb8b, 0x81a1c1, 0xb48ead, 0x88c0d0, 0xe5e9f0, 0x596377, 0xbf616a, 0xa3be8c, 0xebcb8b, 0x81a1c1, 0xb48ead, 0x8fbcbb, 0xeceff4, 0x2e3440, 0xd8dee9, 0xeceff4, 0x282828, 0xeceff4, 0x4c566a}},
{"Nord Light", [22]uint32{0x3b4252, 0xbf616a, 0x96b17f, 0xc5a565, 0x81a1c1, 0xb48ead, 0x7bb3c3, 0xa5abb6, 0x4c566a, 0xbf616a, 0x96b17f, 0xc5a565, 0x81a1c1, 0xb48ead, 0x82afae, 0xeceff4, 0xe5e9f0, 0x414858, 0x7bb3c3, 0x3b4252, 0xd8dee9, 0x4c556a}},
{"Nord Wave", [22]uint32{0x3b4252, 0xbf616a, 0xa3be8c, 0xebcb8b, 0x81a1c1, 0xb48ead, 0x88c0d0, 0xe5e9f0, 0x4c566a, 0xbf616a, 0xa3be8c, 0xebcb8b, 0x81a1c1, 0xb48ead, 0x8fbcbb, 0xeceff4, 0x212121, 0xd8dee9, 0xebcb8b, 0xb89858, 0xd8dee9, 0x212121}},
{"Nordfox", [22]uint32{0x3b4252, 0xbf616a, 0xa3be8c, 0xebcb8b, 0x81a1c1, 0xb48ead, 0x88c0d0, 0xe5e9f0, 0x53648d, 0xd06f79, 0xb1d196, 0xf0d399, 0x8cafd2, 0xc895bf, 0x93ccdc, 0xe7ecf4, 0x2e3440, 0xcdcecf, 0xcdcecf, 0x2e3440, 0x3e4a5b, 0xcdcecf}},
{"Novel", [22]uint32{0x000000, 0xcc0000, 0x009600, 0xd06b00, 0x0000cc, 0xcc00cc, 0x0087cc, 0xa6a6a6, 0x808080, 0xcc0000, 0x009600, 0xd06b00, 0x0000cc, 0xcc00cc, 0x0087cc, 0xffffff, 0xdfdbc3, 0x3b2322, 0x73635a, 0x000000, 0xa4a390, 0x000000}},
{"Nvim Dark", [22]uint32{0x07080d, 0xffc0b9, 0xb3f6c0, 0xfce094, 0xa6dbff, 0xffcaff, 0x8cf8f7, 0xeef1f8, 0x4f5258, 0xffc0b9, 0xb3f6c0, 0xfce094, 0xa6dbff, 0xffcaff, 0x8cf8f7, 0xeef1f8, 0x14161b, 0xe0e2ea, 0x9b9ea4, 0xe0e2ea, 0x4f5258, 0xe0e2ea}},
{"Nvim Light", [22]uint32{0x07080d, 0x590008, 0x005523, 0x6b5300, 0x004c73, 0x470045, 0x007373, 0xa1a4ab, 0x4f5258, 0x590008, 0x005523, 0x6b5300, 0x004c73, 0x470045, 0x007373, 0xeef1f8, 0xe0e2ea, 0x14161b, 0x9b9ea4, 0x14161b, 0x9b9ea4, 0x14161b}},
{"Obsidian", [22]uint32{0x000000, 0xb30d0e, 0x00bb00, 0xfecd22, 0x3a9bdb, 0xbb00bb, 0x00bbbb, 0xbbbbbb, 0x555555, 0xff0003, 0x93c863, 0xfef874, 0xa1d7ff, 0xff55ff, 0x55ffff, 0xffffff, 0x283033, 0xcdcdcd, 0xc0cad0, 0x8d8d8d, 0x3e4c4f, 0xdfe1e2}},
{"Ocean", [22]uint32{0x000000, 0xe64c4c, 0x00a600, 0x999900, 0x0000b2, 0xd826d8, 0x00a6b2, 0xbfbfbf, 0x808080, 0xff1a1a, 0x00d900, 0xe5e500, 0x7373ff, 0xe500e5, 0x00e5e5, 0xe5e5e5, 0x224fbc, 0xffffff, 0x7f7f7f, 0xffffff, 0x216dff, 0xffffff}},
{"Oceanic Material", [22]uint32{0x000000, 0xee2b2a, 0x40a33f, 0xffea2e, 0x1e80f0, 0x8800a0, 0x16afca, 0xa4a4a4, 0x777777, 0xdc5c60, 0x70be71, 0xfff163, 0x54a4f3, 0xaa4dbc, 0x42c7da, 0xffffff, 0x1c262b, 0xc2c8d7, 0xb3b8c3, 0xffffff, 0x6dc2b8, 0xe8eefd}},
{"Oceanic Next", [22]uint32{0x162c35, 0xec5f67, 0x99c794, 0xfac863, 0x6699cc, 0xc594c5, 0x5fb3b3, 0xffffff, 0x65737e, 0xec5f67, 0x99c794, 0xfac863, 0x6699cc, 0xc594c5, 0x5fb3b3, 0xffffff, 0x162c35, 0xc0c5ce, 0xc0c5ce, 0x1b2b34, 0x4f5b66, 0xc0c5ce}},
{"Ollie", [22]uint32{0x000000, 0xac2e31, 0x31ac61, 0xac4300, 0x2d57ac, 0xb08528, 0x1fa6ac, 0x8a8eac, 0x684432, 0xff3d48, 0x3bff99, 0xff5e1e, 0x4488ff, 0xffc21d, 0x1ffaff, 0x5b6ea7, 0x222125, 0x8a8dae, 0x5b6ea7, 0x2a292d, 0x1e3a66, 0x8a8eac}},
{"One Dark Two", [22]uint32{0x1d1f23, 0xe27881, 0x98c379, 0xeac786, 0x71b9f4, 0xc88bda, 0x62bac6, 0xc9ccd3, 0x4a505a, 0xe68991, 0xa8cc8e, 0xedcf97, 0x8dc7f6, 0xd3a2e2, 0x78c4ce, 0xe6e6e6, 0x21252b, 0xe6e6e6, 0xe6e6e6, 0x1d1f23, 0x393e47, 0xe6e6e6}},
{"One Double Dark", [22]uint32{0x3d4452, 0xf16372, 0x8cc570, 0xecbe70, 0x3fb1f5, 0xd373e3, 0x17b9c4, 0xdbdfe5, 0x525d6f, 0xff777b, 0x82d882, 0xf5c065, 0x6dcaff, 0xff7bf4, 0x00e5fb, 0xf7f9fc, 0x282c34, 0xdbdfe5, 0xf5e0dc, 0x9aa3c1, 0x585b70, 0xcdd6f4}},
{"One Double Light", [22]uint32{0x454b58, 0xf74840, 0x25a343, 0xcc8100, 0x0087c1, 0xb50da9, 0x009ab7, 0xc5b2b3, 0x0e131f, 0xff3711, 0x00b90e, 0xec9900, 0x1065de, 0xe500d8, 0x00b4dd, 0xffffff, 0xfafafa, 0x383a43, 0x1a1919, 0xdbdfe5, 0x454e5e, 0x1a1919}},
{"One Half Dark", [22]uint32{0x282c34, 0xe06c75, 0x98c379, 0xe5c07b, 0x61afef, 0xc678dd, 0x56b6c2, 0xdcdfe4, 0x5d677a, 0xe06c75, 0x98c379, 0xe5c07b, 0x61afef, 0xc678dd, 0x56b6c2, 0xdcdfe4, 0x282c34, 0xdcdfe4, 0xa3b3cc, 0xe9ecf1, 0x474e5d, 0xdcdfe4}},
{"One Half Light", [22]uint32{0x383a42, 0xe45649, 0x50a14f, 0xc18401, 0x0184bc, 0xa626a4, 0x0997b3, 0xbababa, 0x4f525e, 0xe06c75, 0x98c379, 0xd8b36e, 0x61afef, 0xc678dd, 0x56b6c2, 0xffffff, 0xfafafa, 0x383a42, 0xa5b4e5, 0x383a42, 0xbfceff, 0x383a42}},
{"Onenord", [22]uint32{0x3b4252, 0xe06c75, 0x9ec183, 0xebcb8b, 0x81a1c1, 0xb988b0, 0x88c0d0, 0xe5e9f0, 0x596377, 0xe06c75, 0x9ec183, 0xebcb8b, 0x81a1c1, 0xb988b0, 0x8fbcbb, 0xeceff4, 0x2e3440, 0xe5e9f0, 0x81a1c1, 0x3b4252, 0x434c5e, 0xd8dee9}},
{"Onenord Light", [22]uint32{0x2e3440, 0xcb4f53, 0x48a53d, 0xee5e25, 0x3879c5, 0x9f4aca, 0x3ea1ad, 0xb2b6bd, 0x646a76, 0xd16366, 0x5f9e9d, 0xba793e, 0x1b40a6, 0x9665af, 0x8fbcbb, 0xeceff4, 0xf7f8fa, 0x2e3440, 0x3879c5, 0xf7f8fa, 0xeaebed, 0x000000}},
{"Opaline", [22]uint32{0x201b33, 0xff6b92, 0x86e6b4, 0xffc2ae, 0x8fb4ff, 0xbe9bff, 0x5fe3d8, 0xece9f7, 0x6b678f, 0xff81a2, 0x95e9bd, 0xf4d27e, 0xb79bff, 0xff9ed2, 0x72e6dd, 0xffffff, 0x131121, 0xece9f7, 0xffb3d6, 0x131121, 0x2c2748, 0x535161}},
{"Operator Mono Dark", [22]uint32{0x5a5a5a, 0xca372d, 0x4d7b3a, 0xd4d697, 0x4387cf, 0xb86cb4, 0x72d5c6, 0xced4cd, 0x9a9b99, 0xc37d62, 0x83d0a2, 0xfdfdc5, 0x89d3f6, 0xff2c7a, 0x82eada, 0xfdfdf6, 0x191919, 0xc3cac2, 0xfcdc08, 0x161616, 0x19273b, 0xdde5dc}},
{"Outrun Electric", [22]uint32{0x131033, 0xe61f44, 0xa7da1e, 0xffd400, 0x1ea8fc, 0xff2afc, 0x42c6ff, 0xf2f3f7, 0x546a90, 0xef6d85, 0xc6e76d, 0xffe359, 0x6dc6fd, 0xdf85ff, 0x84daff, 0xffffff, 0x0c0a20, 0xf2f3f7, 0xff2afc, 0x0c0a20, 0xba45a3, 0xf2f3f7}},
{"Overnight Slumber", [22]uint32{0x0a1222, 0xffa7c4, 0x85cc95, 0xffcb8b, 0x8dabe1, 0xc792eb, 0x78ccf0, 0xffffff, 0x575656, 0xffa7c4, 0x85cc95, 0xffcb8b, 0x8dabe1, 0xc792eb, 0xffa7c4, 0xffffff, 0x0e1729, 0xced2d6, 0xffa7c4, 0xffffff, 0x1f2b41, 0xced2d6}},
{"Oxblood", [22]uint32{0x231417, 0xff4d54, 0xc9a24a, 0xe0b24a, 0xd9743f, 0xe0556b, 0xe0a36a, 0xe8d2d4, 0x7a5458, 0xff686e, 0xcfad60, 0xd9743f, 0xe86b72, 0xc8324b, 0xe4ae7c, 0xffffff, 0x140b0d, 0xe8d2d4, 0xe0483a, 0x140b0d, 0x3a2227, 0x60575a}},
{"Oxide", [22]uint32{0x262626, 0xed756e, 0x5bb661, 0xc39900, 0x3ba6f5, 0x968ff7, 0x00baaa, 0xcecece, 0x8f8f8f, 0xff9890, 0x7bd77f, 0xe3b831, 0x6fc6ff, 0xb5b2ff, 0x00dcca, 0xdedede, 0x161616, 0xcecece, 0xcecece, 0x161616, 0x262626, 0xcecece}},
{"Oxocarbon", [22]uint32{0x161616, 0x00dfdb, 0x00b4ff, 0xff4297, 0x00c15a, 0xc693ff, 0xff74b8, 0xf2f4f8, 0x585858, 0x00dfdb, 0x00b4ff, 0xff4297, 0x00c15a, 0xc693ff, 0xff74b8, 0xf2f4f8, 0x161616, 0xf2f4f8, 0xffffff, 0x000000, 0x393939, 0x626262}},
{"Pale Night Hc", [22]uint32{0x000000, 0xf07178, 0xc3e88d, 0xffcb6b, 0x82aaff, 0xc792ea, 0x89ddff, 0xffffff, 0x737373, 0xf6a9ae, 0xdbf1ba, 0xffdfa6, 0xb4ccff, 0xddbdf2, 0xb8eaff, 0x999999, 0x3e4251, 0xcccccc, 0xffcb6b, 0x323232, 0x717cb4, 0x80cbc4}},
{"Pandora", [22]uint32{0x000000, 0xff4242, 0x74af68, 0xffad29, 0x338f86, 0x9414e6, 0x23d7d7, 0xe2e2e2, 0x3f5648, 0xff3242, 0x74cd68, 0xffb929, 0x23d7d7, 0xff37ff, 0x00ede1, 0xffffff, 0x141e43, 0xe1e1e1, 0x43d58e, 0xffffff, 0x2d37ff, 0x82e0ff}},
{"Paraiso Dark", [22]uint32{0x2f1e2e, 0xef6155, 0x48b685, 0xfec418, 0x06b6ef, 0x815ba4, 0x5bc4bf, 0xa39e9b, 0x776e71, 0xef6155, 0x48b685, 0xfec418, 0x06b6ef, 0x815ba4, 0x5bc4bf, 0xe7e9db, 0x2f1e2e, 0xa39e9b, 0xa39e9b, 0x2f1e2e, 0x4f424c, 0xa39e9b}},
{"Patina", [22]uint32{0x16201c, 0xd9603f, 0x9fc08c, 0xc8a24a, 0x5fc9b0, 0xd7b45a, 0x7fd0c0, 0xdce5de, 0x5c7068, 0xdf785c, 0xabc89a, 0xd98e5a, 0x5fc9b0, 0xe0c36a, 0x8ed6c8, 0xffffff, 0x0e1613, 0xdce5de, 0xe0c36a, 0x0e1613, 0x23302b, 0x4e5653}},
{"Patina Dark", [22]uint32{0x2e2e2e, 0xcb7676, 0x4d9375, 0xe6cc77, 0x6db3c2, 0xc98a7d, 0x5da9a7, 0xdbd7ca, 0x585858, 0xcb7676, 0x4d9375, 0xe6cc77, 0x6db3c2, 0xc98a7d, 0x5da9a7, 0xdbd7ca, 0x121212, 0xdbd7ca, 0xdbd7ca, 0x121212, 0x42403d, 0xdbd7ca}},
{"Patina Dark Soft", [22]uint32{0x2e2e2e, 0xcb7676, 0x549c7d, 0xe6cc77, 0x6db3c2, 0xc98a7d, 0x5da9a7, 0xdbd7ca, 0x585858, 0xcb7676, 0x549c7d, 0xe6cc77, 0x6db3c2, 0xc98a7d, 0x5da9a7, 0xdbd7ca, 0x1a1a1a, 0xdbd7ca, 0xdbd7ca, 0x1a1a1a, 0x3a3835, 0xdbd7ca}},
{"Patina Lichen", [22]uint32{0x393a34, 0x8b4646, 0x33644d, 0x7f5031, 0x35616d, 0x854b3f, 0x2a6361, 0x5a5248, 0x5b5b54, 0x8b4646, 0x426338, 0x7f5031, 0x35616d, 0x854b3f, 0x2a6361, 0x393a34, 0xcdd1c6, 0x393a34, 0x393a34, 0xcdd1c6, 0xaab0a3, 0x393a34}},
{"Patina Light", [22]uint32{0x2e2a24, 0x9b3b3b, 0x34644c, 0x6e5817, 0x2f626f, 0x7a4f47, 0x2e6260, 0x5a5248, 0x625a51, 0x833333, 0x2d5839, 0x634e14, 0x2c5660, 0x6d463e, 0x285654, 0x393a34, 0xddd7c4, 0x2e2a24, 0x2e2a24, 0xddd7c4, 0xbfb8a3, 0x2e2a24}},
{"Patina Moss", [22]uint32{0x33362e, 0xc07878, 0x5ba886, 0xd4bf6e, 0x65a8b5, 0xc08a7d, 0x63a8a6, 0xdbd7ca, 0x585b51, 0xc07878, 0x5ba886, 0xd4bf6e, 0x65a8b5, 0xc08a7d, 0x63a8a6, 0xdbd7ca, 0x20231f, 0xdbd7ca, 0xdbd7ca, 0x20231f, 0x383b31, 0xdbd7ca}},
{"Patina Stellar", [22]uint32{0x2e2a24, 0xa84040, 0x3a7055, 0x6e5817, 0x2f626f, 0x8a5a50, 0x387775, 0x5a5248, 0x6a6258, 0xbf3c3c, 0x3e7a5e, 0x826743, 0x3f7381, 0x9d594b, 0x337675, 0x393a34, 0xf5f2ed, 0x2e2a24, 0x2e2a24, 0xf5f2ed, 0xdbd5c5, 0x2e2a24}},
{"Paul Millr", [22]uint32{0x2a2a2a, 0xff0000, 0x79ff0f, 0xe7bf00, 0x396bd7, 0xb449be, 0x66ccff, 0xbbbbbb, 0x666666, 0xff0080, 0x66ff66, 0xf3d64e, 0x709aed, 0xdb67e6, 0x7adff2, 0xffffff, 0x000000, 0xf2f2f2, 0x4d4d4d, 0xffffff, 0x414141, 0xffffff}},
{"Pencil Dark", [22]uint32{0x212121, 0xc30771, 0x10a778, 0xa89c14, 0x008ec4, 0x5f4986, 0x20a5ba, 0xd9d9d9, 0x4f4f4f, 0xfb007a, 0x5fd7af, 0xf3e430, 0x20bbfc, 0x6855de, 0x4fb8cc, 0xf1f1f1, 0x212121, 0xf1f1f1, 0x20bbfc, 0xf1f1f1, 0xb6d6fd, 0x989898}},
{"Pencil Light", [22]uint32{0x212121, 0xc30771, 0x10a778, 0xa89c14, 0x008ec4, 0x523c79, 0x20a5ba, 0xb3b3b3, 0x424242, 0xfb007a, 0x52caa2, 0xc0b100, 0x20bbfc, 0x6855de, 0x4fb8cc, 0xf1f1f1, 0xf1f1f1, 0x424242, 0x20bbfc, 0x424242, 0xb6d6fd, 0x424242}},
{"Peppermint", [22]uint32{0x353535, 0xe74669, 0x89d287, 0xdab853, 0x449fd0, 0xda62dc, 0x65aaaf, 0xb4b4b4, 0x535353, 0xe4859b, 0xa3cca2, 0xe1e487, 0x6fbce2, 0xe586e7, 0x96dcdb, 0xdfdfdf, 0x000000, 0xc8c8c8, 0xbbbbbb, 0xffffff, 0xe6e6e6, 0x000000}},
{"Phala Green Dark", [22]uint32{0x000000, 0xab1500, 0x00b100, 0xa9a700, 0x0223c0, 0xc22ec0, 0x00b4c0, 0xcbcbcb, 0x797979, 0xed2200, 0x00db00, 0xeae700, 0x0433ff, 0xed3aea, 0x00e8ea, 0xeaeaea, 0x000000, 0xc1fc03, 0xc1fc03, 0xff271d, 0x014804, 0xffffff}},
{"Piatto Light", [22]uint32{0x414141, 0xb23771, 0x66781e, 0xcd6f34, 0x3c5ea8, 0xa454b2, 0x66781e, 0xbfbfbf, 0x3f3f3f, 0xdb3365, 0x829429, 0xcd6f34, 0x3c5ea8, 0xa454b2, 0x829429, 0xf2f2f2, 0xffffff, 0x414141, 0x5e77c8, 0xabbee5, 0x706b4e, 0xacbcdc}},
{"Pierre Dark", [22]uint32{0x141415, 0xff2e3f, 0x0dbe4e, 0xffca00, 0x009fff, 0xc635e4, 0x08c0ef, 0xc6c6c8, 0x6c6c71, 0xff6762, 0x5ecc71, 0xffd452, 0x69b1ff, 0xd568ea, 0x68cdf2, 0xfbfbfb, 0x070707, 0xfbfbfb, 0x009fff, 0x070707, 0x19283c, 0xfbfbfb}},
{"Pierre Light", [22]uint32{0x1f1f21, 0xd52c36, 0x1d8138, 0xac8816, 0x216cab, 0xa631be, 0x2182a1, 0x79797f, 0x8e8e95, 0xff2e3f, 0x0dbe4e, 0xd5a910, 0x009fff, 0xc635e4, 0x08c0ef, 0xdbdbdd, 0xffffff, 0x070707, 0x009fff, 0xffffff, 0xdfebff, 0x070707}},
{"Pnevma", [22]uint32{0x2f2e2d, 0xa36666, 0x90a57d, 0xd7af87, 0x7fa5bd, 0xc79ec4, 0x8adbb4, 0xd0d0d0, 0x4a4845, 0xd78787, 0xafbea2, 0xe4c9af, 0xa1bdce, 0xd7beda, 0xb1e7dd, 0xefefef, 0x1c1c1c, 0xd0d0d0, 0xe4c9af, 0x000000, 0x4d4d4d, 0xffffff}},
{"Poimandres", [22]uint32{0x1a1e28, 0xd0679d, 0x5de4c7, 0xfffac2, 0x89ddff, 0xfcc5e9, 0xadd7ff, 0xffffff, 0xa6accd, 0xd0679d, 0x5de4c7, 0xfffac2, 0xadd7ff, 0xfae4fc, 0x89ddff, 0xffffff, 0x1a1e28, 0xa6accd, 0xffffff, 0x1a1e29, 0xa6accd, 0xffffff}},
{"Poimandres Darker", [22]uint32{0x16161e, 0xd0679d, 0x5de4c7, 0xfffac2, 0x89ddff, 0xfcc5e9, 0xadd7ff, 0xffffff, 0xa6accd, 0xd0679d, 0x5de4c7, 0xfffac2, 0xadd7ff, 0xfae4fc, 0x89ddff, 0xffffff, 0x16161e, 0xa6accd, 0xffffff, 0x16161e, 0xa6accd, 0xffffff}},
{"Poimandres Storm", [22]uint32{0x252b37, 0xd0679d, 0x5de4c7, 0xfffac2, 0x89ddff, 0xf087bd, 0x89ddff, 0xffffff, 0xa6accd, 0xd0679d, 0x5de4c7, 0xfffac2, 0xadd7ff, 0xf087bd, 0xadd7ff, 0xffffff, 0x252b37, 0xa6accd, 0xffffff, 0x252b37, 0xa6accd, 0xffffff}},
{"Poimandres White", [22]uint32{0xfefeff, 0xff2090, 0x01dab2, 0xe5ba4e, 0x8abacd, 0xeb8394, 0x8abacd, 0x000000, 0x969cbd, 0xff2090, 0x01dab2, 0xe5ba4e, 0x0ebfff, 0xeb8394, 0x0ebfff, 0x000000, 0xfefeff, 0x969cbd, 0x969cbd, 0xfefeff, 0x969cbd, 0x3b3e48}},
{"Popping And Locking", [22]uint32{0x1d2021, 0xcc241d, 0x98971a, 0xd79921, 0x458588, 0xb16286, 0x689d6a, 0xa89984, 0x928374, 0xf42c3e, 0xb8bb26, 0xfabd2f, 0x99c6ca, 0xd3869b, 0x7ec16e, 0xebdbb2, 0x181921, 0xebdbb2, 0xc7c7c7, 0x8c8c8c, 0xebdbb2, 0x928374}},
{"Porcelain", [22]uint32{0x2a2e37, 0xc60018, 0x157424, 0x855700, 0x004cc8, 0x761bc3, 0x006873, 0x5a6170, 0x828896, 0xd60027, 0x1b842d, 0xaf2700, 0x005bdb, 0x862ad2, 0x007f8f, 0x1b1e25, 0xfbfbfd, 0x2a2e37, 0x0054d1, 0xfbfbfd, 0xdce6f7, 0xaeaeb0}},
{"Powershell", [22]uint32{0x000000, 0x981a22, 0x098003, 0xc4a000, 0x4140c3, 0xd33682, 0x0e807f, 0x7f7c7f, 0x808080, 0xef2929, 0x1cfe3c, 0xfefe45, 0x268ad2, 0xfe13fa, 0x29fffe, 0xc2c1c3, 0x052454, 0xf6f6f7, 0xf6f6f7, 0x052454, 0xf6f6f7, 0x052454}},
{"Primary", [22]uint32{0x000000, 0xdb4437, 0x0f9d58, 0xf4b400, 0x4285f4, 0xdb4437, 0x4285f4, 0xbfbfbf, 0x000000, 0xdb4437, 0x0f9d58, 0xf4b400, 0x4285f4, 0x4285f4, 0x0f9d58, 0xffffff, 0xffffff, 0x000000, 0x000000, 0xffffff, 0x656565, 0xeeeeee}},
{"Prism", [22]uint32{0x060c18, 0xff7192, 0x71e0b0, 0xfad77c, 0x47b3ff, 0x9da9ff, 0x31dcf2, 0xb6c4dc, 0x5e6f90, 0xff96ad, 0x93ecc7, 0xfca76d, 0x77caff, 0xb8c1ff, 0x6ceafb, 0xeaf1fb, 0x0b1326, 0xd7e3f4, 0x56d5ff, 0x0b1326, 0x1e2c49, 0x4b5366}},
{"Pro", [22]uint32{0x000000, 0x990000, 0x00a600, 0x999900, 0x2009db, 0xb200b2, 0x00a6b2, 0xbfbfbf, 0x666666, 0xe50000, 0x00d900, 0xe5e500, 0x0000ff, 0xe500e5, 0x00e5e5, 0xe5e5e5, 0x000000, 0xf2f2f2, 0x4d4d4d, 0xffffff, 0x414141, 0x000000}},
{"Pro Light", [22]uint32{0x000000, 0xe5492b, 0x50d148, 0xc6c440, 0x3b75ff, 0xed66e8, 0x4ed2de, 0xc2c2c2, 0x9f9f9f, 0xff6640, 0x48d53e, 0xbfbe23, 0x0082ff, 0xff7eff, 0x3bd1d2, 0xf2f2f2, 0xffffff, 0x191919, 0x4d4d4d, 0xf2f2f2, 0xc1ddff, 0x191919}},
{"Purple Portal", [22]uint32{0x483a57, 0xfb7185, 0x34d399, 0xf472b6, 0xfacc15, 0x38bdf8, 0x580ff0, 0xd8b4fe, 0x503872, 0xfc8d9d, 0x5ddcad, 0xf68bc3, 0xfbd644, 0x60caf9, 0x793ff3, 0xfaf5ff, 0x160528, 0xfaf5ff, 0xfaf5ff, 0x160528, 0xfaf5ff, 0x160528}},
{"Purple Rain", [22]uint32{0x000000, 0xff260e, 0x9be205, 0xffc400, 0x00a2fa, 0x815bb5, 0x00deef, 0xffffff, 0x565656, 0xff4250, 0xb8e36e, 0xffd852, 0x00a6ff, 0xac7bf0, 0x74fdf3, 0xffffff, 0x21084a, 0xfffbf6, 0xff271d, 0xff9a90, 0x287691, 0xffffff}},
{"Purplepeter", [22]uint32{0x0a0520, 0xff796d, 0x99b481, 0xefdfac, 0x66d9ef, 0xe78fcd, 0xba8cff, 0xffba81, 0x504b63, 0xf99f92, 0xb4be8f, 0xf2e9bf, 0x79daed, 0xba91d4, 0xa0a0d6, 0xb9aed3, 0x2a1a4a, 0xece7fa, 0xc7c7c7, 0x8c8c8c, 0x8689c2, 0x271c50}},
{"Pyrokai", [22]uint32{0x242120, 0xec6785, 0x75ad2f, 0xbb9500, 0x2aa0f9, 0xe76899, 0x00aebd, 0xb4afad, 0x807c7a, 0xfa8099, 0x8bbf53, 0xd0a70e, 0x5bb3ff, 0xf681ac, 0x00c3d3, 0xfaf6f5, 0x151312, 0xfaf6f5, 0xea7332, 0x151312, 0x312d2b, 0xfaf6f5}},
{"Pyrokai Light", [22]uint32{0x242120, 0xb84963, 0x568413, 0x8e7100, 0x0979c4, 0xb44a74, 0x008490, 0xb4afad, 0x807c7a, 0x943c50, 0x456a13, 0x735a00, 0x0f619d, 0x913c5d, 0x006a74, 0xfaf6f5, 0xfaf6f5, 0x242120, 0xb65318, 0xfaf6f5, 0xe4e0de, 0x242120}},
{"Rapture", [22]uint32{0x000000, 0xfc644d, 0x7afde1, 0xfff09b, 0x6c9bf5, 0xff4fa1, 0x64e0ff, 0xc0c9e5, 0x304b66, 0xfc644d, 0x7afde1, 0xfff09b, 0x6c9bf5, 0xff4fa1, 0x64e0ff, 0xffffff, 0x111e2a, 0xc0c9e5, 0xffffff, 0x111e2a, 0x304b66, 0xffffff}},
{"Raycast Dark", [22]uint32{0x000000, 0xff5360, 0x59d499, 0xffc531, 0x56c2ff, 0xcf2f98, 0x52eee5, 0xffffff, 0x4c4c4c, 0xff6363, 0x59d499, 0xffc531, 0x56c2ff, 0xcf2f98, 0x52eee5, 0xffffff, 0x1a1a1a, 0xffffff, 0xcccccc, 0x999999, 0x333333, 0x595959}},
{"Raycast Light", [22]uint32{0x000000, 0xb12424, 0x006b4f, 0xf8a300, 0x138af2, 0x9a1b6e, 0x3eb8bf, 0xbfbfbf, 0x000000, 0xb12424, 0x006b4f, 0xf8a300, 0x138af2, 0x9a1b6e, 0x3eb8bf, 0xffffff, 0xffffff, 0x000000, 0x000000, 0x404040, 0xe5e5e5, 0x000000}},
{"Rebecca", [22]uint32{0x12131e, 0xdd7755, 0x04dbb5, 0xf2e7b7, 0x7aa5ff, 0xbf9cf9, 0x56d3c2, 0xe4e3e9, 0x666699, 0xff92cd, 0x01eac0, 0xfffca8, 0x69c0fa, 0xc17ff8, 0x8bfde1, 0xf4f2f9, 0x292a44, 0xe8e6ed, 0xb89bf9, 0x292a44, 0x663399, 0xf4f2f9}},
{"Red Alert", [22]uint32{0x000000, 0xd62e4e, 0x71be6b, 0xbeb86b, 0x489bee, 0xe979d7, 0x6bbeb8, 0xd6d6d6, 0x666666, 0xe02553, 0xaff08c, 0xdfddb7, 0x65aaf1, 0xddb7df, 0xb7dfdd, 0xffffff, 0x762423, 0xffffff, 0xffffff, 0x762423, 0x073642, 0xffffff}},
{"Red Planet", [22]uint32{0x202020, 0x8c3432, 0x728271, 0xe8bf6a, 0x69819e, 0x896492, 0x5b8390, 0xb9aa99, 0x676767, 0xb55242, 0x869985, 0xebeb91, 0x60827e, 0xde4974, 0x38add8, 0xd6bfb8, 0x222222, 0xc2b790, 0xc2b790, 0x202020, 0x1b324a, 0xbcb291}},
{"Red Sands", [22]uint32{0x000000, 0xff3f00, 0x00bb00, 0xe7b000, 0x0072ff, 0xbb00bb, 0x00bbbb, 0xbbbbbb, 0x6e6e6e, 0xd41a1a, 0x00bb00, 0xe7b000, 0x0072ae, 0xff55ff, 0x55ffff, 0xffffff, 0x7a251e, 0xd7c9a7, 0xffffff, 0x000000, 0xa4a390, 0x000000}},
{"Relaxed", [22]uint32{0x151515, 0xbc5653, 0x909d63, 0xebc17a, 0x6a8799, 0xb06698, 0xc9dfff, 0xd9d9d9, 0x636363, 0xbc5653, 0xa0ac77, 0xebc17a, 0x7eaac7, 0xb06698, 0xacbbd0, 0xf7f7f7, 0x353a44, 0xd9d9d9, 0xd9d9d9, 0x1b1b1b, 0x6a7985, 0xd9d9d9}},
{"Retro", [22]uint32{0x13a10e, 0x13a10e, 0x13a10e, 0x13a10e, 0x13a10e, 0x13a10e, 0x13a10e, 0x13a10e, 0x16ba10, 0x16ba10, 0x16ba10, 0x16ba10, 0x16ba10, 0x16ba10, 0x16ba10, 0x16ba10, 0x000000, 0x13a10e, 0x13a10e, 0x000000, 0xffffff, 0x000000}},
{"Retro Legends", [22]uint32{0x262626, 0xde5454, 0x45eb45, 0xf7bf2b, 0x4066f2, 0xbf4cf2, 0x40d9e6, 0xbfe6bf, 0x4c594c, 0xff6666, 0x59ff59, 0xffd933, 0x4c80ff, 0xe666ff, 0x59e6ff, 0xf2fff2, 0x0d0d0d, 0x45eb45, 0x45eb45, 0x0d0d0d, 0x336633, 0xf2fff2}},
{"Rippedcasts", [22]uint32{0x000000, 0xcdaf95, 0xa8ff60, 0xbfbb1f, 0x75a5b0, 0xff73fd, 0x5a647e, 0xbfbfbf, 0x666666, 0xeecbad, 0xbcee68, 0xe5e500, 0x86bdc9, 0xe500e5, 0x8c9bc4, 0xe5e5e5, 0x2b2b2b, 0xffffff, 0x7f7f7f, 0xffffff, 0x5a647e, 0xf2f2f2}},
{"Rose Pine", [22]uint32{0x26233a, 0xeb6f92, 0x31748f, 0xf6c177, 0x9ccfd8, 0xc4a7e7, 0xebbcba, 0xe0def4, 0x6e6a86, 0xeb6f92, 0x31748f, 0xf6c177, 0x9ccfd8, 0xc4a7e7, 0xebbcba, 0xe0def4, 0x191724, 0xe0def4, 0xe0def4, 0x191724, 0x403d52, 0xe0def4}},
{"Rose Pine Dawn", [22]uint32{0xf2e9e1, 0xb4637a, 0x286983, 0xea9d34, 0x56949f, 0x907aa9, 0xd7827e, 0x575279, 0x9893a5, 0xb4637a, 0x286983, 0xea9d34, 0x56949f, 0x907aa9, 0xd7827e, 0x575279, 0xfaf4ed, 0x575279, 0x575279, 0xfaf4ed, 0xdfdad9, 0x575279}},
{"Rose Pine Moon", [22]uint32{0x393552, 0xeb6f92, 0x3e8fb0, 0xf6c177, 0x9ccfd8, 0xc4a7e7, 0xea9a97, 0xe0def4, 0x6e6a86, 0xeb6f92, 0x3e8fb0, 0xf6c177, 0x9ccfd8, 0xc4a7e7, 0xea9a97, 0xe0def4, 0x232136, 0xe0def4, 0xe0def4, 0x232136, 0x44415a, 0xe0def4}},
{"Rouge 2", [22]uint32{0x5d5d6b, 0xc6797e, 0x969e92, 0xdbcdab, 0x6e94b9, 0x4c4e78, 0x8ab6c1, 0xe8e8ea, 0x616274, 0xc6797e, 0xe6dcc4, 0xe6dcc4, 0x98b3cd, 0x8283a1, 0xabcbd3, 0xe8e8ea, 0x17182b, 0xa2a3aa, 0x969e92, 0xffffff, 0x5d5d6b, 0xdfe5ee}},
{"Royal", [22]uint32{0x241f2b, 0x91284c, 0x23801c, 0xb49d27, 0x6580b0, 0x674d96, 0x8aaabe, 0x524966, 0x3e3a4a, 0xd5356c, 0x2cd946, 0xfde83b, 0x90baf9, 0xa479e3, 0xacd4eb, 0x9e8cbd, 0x100815, 0x514968, 0x524966, 0x100613, 0x1f1d2b, 0xa593cd}},
{"Ryuuko", [22]uint32{0x2c3941, 0x865f5b, 0x66907d, 0xb1a990, 0x6a8e95, 0xb18a73, 0x88b2ac, 0xececec, 0x5d7079, 0x865f5b, 0x66907d, 0xb1a990, 0x6a8e95, 0xb18a73, 0x88b2ac, 0xececec, 0x2c3941, 0xececec, 0xececec, 0x002831, 0x002831, 0x819090}},
{"Sakura", [22]uint32{0x000000, 0xd52370, 0x41af1a, 0xbc7053, 0x6964ab, 0xc71fbf, 0x939393, 0x998eac, 0x786d69, 0xf41d99, 0x22e529, 0xf59574, 0x9892f1, 0xe90cdd, 0xeeeeee, 0xcbb6ff, 0x18131e, 0xdd7bdc, 0xff65fd, 0x24242e, 0xc05cbf, 0x24242e}},
{"Sandstone Classic", [22]uint32{0x073642, 0xcf2522, 0x5d7b00, 0x865e00, 0x0d6eb2, 0xc42a78, 0x037a71, 0x6e6855, 0x3d5259, 0xc04010, 0x5e7171, 0x5b7070, 0x5c6f6f, 0x5f64b7, 0x5f6e6e, 0xfdf6e3, 0xfdf6e3, 0x3d5259, 0x3d5259, 0xfdf6e3, 0xe4dcc8, 0xa49d8a}},
{"Sandstone Ink", [22]uint32{0x002b36, 0xcf2522, 0x4b7000, 0x906800, 0x0d6fa8, 0xb5006e, 0x00756d, 0x6e6855, 0x2b3d45, 0xb33000, 0x536868, 0x566c6c, 0x5c6f6f, 0x5f64b7, 0x5f6e6e, 0xfdf6e3, 0xfdf6e3, 0x2b3d45, 0x2b3d45, 0xfdf6e3, 0xddd8c0, 0xa49d8a}},
{"Sandstone Warm", [22]uint32{0x2e2010, 0xcf2522, 0x5d7b00, 0x865e00, 0x0d6eb2, 0xb52d6e, 0x037a71, 0x756c51, 0x5c4a2a, 0xc04010, 0x7f6648, 0x7d6646, 0x5c6f6f, 0x5f64b7, 0x5f6e6e, 0xfdf6e3, 0xfdf6e3, 0x3e3220, 0x3e3220, 0xfdf6e3, 0xe8dfc4, 0xb0a996}},
{"Sauber", [22]uint32{0x14191e, 0xb43c2a, 0x00c200, 0xc7c400, 0x2744c7, 0xc040be, 0x00c5c7, 0xbababa, 0x686868, 0xdd7975, 0x3fcd76, 0xc6bb00, 0xa7abf2, 0xe17ee1, 0x048b8f, 0xa4801c, 0xecffe5, 0x1345f6, 0x000000, 0xffffff, 0xb3d7ff, 0x000000}},
{"Scarlet Protocol", [22]uint32{0x101116, 0xff0051, 0x00dc84, 0xfaf945, 0x0271b6, 0xca30c7, 0x00c5c7, 0xc7c7c7, 0x686868, 0xff6e67, 0x5ffa68, 0xfffc67, 0x6871ff, 0xbd35ec, 0x60fdff, 0xffffff, 0x1c153d, 0xe41951, 0x76ff9f, 0xa6a6a6, 0xc1deff, 0x000000}},
{"Sea Shells", [22]uint32{0x17384c, 0xd15123, 0x027c9b, 0xfca02f, 0x1e4950, 0x68d4f1, 0x50a3b5, 0xdeb88d, 0x434b53, 0xd48678, 0x628d98, 0xfdd39f, 0x1bbcdd, 0xbbe3ee, 0x87acb4, 0xfee4ce, 0x09141b, 0xdeb88d, 0xfca02f, 0x08131a, 0x1e4962, 0xfee4ce}},
{"Seafoam Pastel", [22]uint32{0x757575, 0x825d4d, 0x728c62, 0xada16d, 0x4d7b82, 0x8a7267, 0x729494, 0xe0e0e0, 0x8a8a8a, 0xcf937a, 0x98d9aa, 0xfae79d, 0x7ac3cf, 0xd6b2a1, 0xade0e0, 0xe0e0e0, 0x243435, 0xd4e7d4, 0x57647a, 0x323232, 0xffffff, 0x9e8b13}},
{"SeedFlip Abyss", [22]uint32{0x030308, 0xd26060, 0x60d286, 0xd2bf60, 0x6090d2, 0xd260d2, 0x60d2d2, 0xf1f1f8, 0x3d3d70, 0xe39c9c, 0x9ce3b3, 0xe3d79c, 0x9cb9e3, 0xe39ce3, 0x9ce3e3, 0xffffff, 0x050510, 0xe0e0f0, 0x6e56cf, 0x050510, 0x0c0c1e, 0xe0e0f0}},
{"SeedFlip Amethyst", [22]uint32{0xd7d1cb, 0xbd0f0f, 0x0fbd49, 0xbda00f, 0x0f58bd, 0xbd0fbd, 0x0fbdbd, 0x0e0519, 0xb5aba0, 0xee2b2b, 0x12d452, 0xd4b312, 0x2b7cee, 0xee2bee, 0x05c8c8, 0x1a0a2e, 0xf8f7f6, 0x1a0a2e, 0x635bff, 0x1a0a2e, 0xffffff, 0x1a0a2e}},
{"SeedFlip Canopy", [22]uint32{0x0b110f, 0xd65c5c, 0x5cd685, 0xd6c25c, 0x5c8fd6, 0xd65cd6, 0x5cd6d6, 0xfafafa, 0x2d453c, 0xe69999, 0x99e6b2, 0xe6d999, 0x99b9e6, 0xe699e6, 0x99e6e6, 0xffffff, 0x0f1714, 0xededed, 0x3ecf8e, 0x0f1714, 0x171f1b, 0xededed}},
{"SeedFlip Carbon", [22]uint32{0xd4d4d4, 0x993333, 0x339955, 0x998833, 0x335d99, 0x993399, 0x339999, 0x000000, 0xaeaeae, 0xc65353, 0x53c679, 0xc6b353, 0x5383c6, 0xc653c6, 0x53c6c6, 0x000000, 0xfafafa, 0x000000, 0x000000, 0x404040, 0xffffff, 0x000000}},
{"SeedFlip Coral", [22]uint32{0xd9d9d9, 0xbd0f0f, 0x0fbd49, 0xbda00f, 0x0f58bd, 0xbd0fbd, 0x0fbdbd, 0x101010, 0xb3b3b3, 0xee2b2b, 0x12d452, 0xe1c01e, 0x2b7cee, 0xee2bee, 0x12d4d4, 0x1d1d1d, 0xffffff, 0x1d1d1d, 0xf24e1e, 0x1d1d1d, 0xf5f5f5, 0x1d1d1d}},
{"SeedFlip Ember", [22]uint32{0x050505, 0xf04242, 0x42f07c, 0xf0d342, 0x428bf0, 0xf042f0, 0x42f0f0, 0xfafafa, 0x3d3d3d, 0xf58989, 0x89f5ad, 0xf5e389, 0x89b6f5, 0xf589f5, 0x89f5f5, 0xffffff, 0x0a0a0a, 0xededed, 0xff6b3d, 0x0a0a0a, 0x141414, 0xededed}},
{"SeedFlip Glacier", [22]uint32{0xc2d4e5, 0xbd0f0f, 0x0fbd49, 0xbda00f, 0x0f58bd, 0xbd0fbd, 0x0fbdbd, 0x080d17, 0x8dadce, 0xee2b2b, 0x12d452, 0xd4b312, 0x2b7cee, 0xee2bee, 0x12d4d4, 0x0f172a, 0xf8fafc, 0x0f172a, 0x0ea5e9, 0x0f172a, 0xffffff, 0x0f172a}},
{"SeedFlip Inkwell", [22]uint32{0x050505, 0xcc6666, 0x66cc88, 0xccbb66, 0x6690cc, 0xcc66cc, 0x66cccc, 0xf3f1ee, 0x3d3d3d, 0xdf9f9f, 0x9fdfb5, 0xdfd49f, 0x9fbadf, 0xdf9fdf, 0x9fdfdf, 0xffffff, 0x0a0a0a, 0xe8e4df, 0xc8b8a0, 0x0a0a0a, 0x141414, 0xe8e4df}},
{"SeedFlip Ivory", [22]uint32{0xd9d9d9, 0xbd0f0f, 0x0fbd49, 0xbda00f, 0x0f58bd, 0xbd0fbd, 0x0fbdbd, 0x07182a, 0xb3b3b3, 0xee2b2b, 0x12d452, 0xe1c01e, 0x2b7cee, 0xee2bee, 0x12d4d4, 0x0a2540, 0xffffff, 0x0a2540, 0x635bff, 0x0a2540, 0xf6f9fc, 0x0a2540}},
{"SeedFlip Nightfall", [22]uint32{0x060609, 0xf04242, 0x42f07c, 0xf0d342, 0x428bf0, 0xf042f0, 0x42f0f0, 0xf2f2f3, 0x424256, 0xf58989, 0x89f5ad, 0xf5e389, 0x89b6f5, 0xf589f5, 0x89f5f5, 0xffffff, 0x0a0a0f, 0xe4e4e7, 0x818cf8, 0x0a0a0f, 0x12121a, 0xe4e4e7}},
{"SeedFlip Phosphor", [22]uint32{0x070707, 0xf04242, 0x42f07c, 0xf0d342, 0x428bf0, 0xf042f0, 0x42f0f0, 0xcdffcd, 0x3f3f3f, 0xf58989, 0x89f5ad, 0xf5e389, 0x89b6f5, 0xf589f5, 0x89f5f5, 0xffffff, 0x0c0c0c, 0xb3ffb3, 0x00ff88, 0x0c0c0c, 0x141414, 0xb3ffb3}},
{"SeedFlip Pulse", [22]uint32{0x0d0d0d, 0xe34f4f, 0x4fe380, 0xe3cb4f, 0x4f8de3, 0xe34fe3, 0x4fe3e3, 0xffffff, 0x454545, 0xee9191, 0x91eeb0, 0xeede91, 0x91b8ee, 0xee91ee, 0x91eeee, 0xffffff, 0x121212, 0xffffff, 0x1db954, 0x121212, 0x1a1a1a, 0xffffff}},
{"SeedFlip Ultraviolet", [22]uint32{0x05000a, 0xf04242, 0x42f07c, 0xf0d342, 0x428bf0, 0xf042f0, 0x42f0f0, 0xf6f3fb, 0x5b2687, 0xf58989, 0x89f5ad, 0xf5e389, 0x89b6f5, 0xf589f5, 0x89f5f5, 0xffffff, 0x0b0014, 0xe8e0f5, 0xc77dff, 0x0b0014, 0x13082a, 0xe8e0f5}},
{"SeedFlip Voltage", [22]uint32{0x050505, 0xf04242, 0x42f07c, 0xf0d342, 0x428bf0, 0xf042f0, 0x42f0f0, 0xfdfdfd, 0x3d3d3d, 0xf58989, 0x89f5ad, 0xf5e389, 0x89b6f5, 0xf589f5, 0x89f5f5, 0xffffff, 0x0a0a0a, 0xf0f0f0, 0xa6ff00, 0x0a0a0a, 0x141414, 0xf0f0f0}},
{"SeedFlip Wavelength", [22]uint32{0x090c10, 0xd55d5d, 0x5dd585, 0xd5c15d, 0x5d8fd5, 0xd55dd5, 0x5dd5d5, 0xf7f9fb, 0x364255, 0xe59a9a, 0x9ae5b3, 0xe5d89a, 0x9ab9e5, 0xe59ae5, 0x9ae5e5, 0xffffff, 0x0d1117, 0xe6edf3, 0x238636, 0x0d1117, 0x161b22, 0xe6edf3}},
{"Selenized Black", [22]uint32{0x252525, 0xed4a46, 0x70b433, 0xdbb32d, 0x368aeb, 0xeb6eb7, 0x3fc5b7, 0xb9b9b9, 0x777777, 0xff5e56, 0x83c746, 0xefc541, 0x4f9cfe, 0xff81ca, 0x56d8c9, 0xdedede, 0x181818, 0xb9b9b9, 0x777777, 0x181818, 0x3b3b3b, 0x646464}},
{"Selenized Dark", [22]uint32{0x184956, 0xfa5750, 0x75b938, 0xdbb32d, 0x4695f7, 0xf275be, 0x41c7b9, 0xadbcbc, 0x72898f, 0xff665c, 0x84c747, 0xebc13d, 0x58a3ff, 0xff84cd, 0x53d6c7, 0xcad8d9, 0x103c48, 0xadbcbc, 0xadbcbc, 0x103c48, 0x184956, 0x53d6c7}},
{"Selenized Light", [22]uint32{0xece3cc, 0xd2212d, 0x489100, 0xad8900, 0x0072d4, 0xca4898, 0x009c8f, 0x53676d, 0x909995, 0xcc1729, 0x428b00, 0xa78300, 0x006dce, 0xc44392, 0x00978a, 0x3a4d53, 0xfbf3db, 0x53676d, 0x53676d, 0xfbf3db, 0xece3cc, 0x00978a}},
{"Seoulbones Dark", [22]uint32{0x4b4b4b, 0xe388a3, 0x98bd99, 0xffdf9b, 0x97bdde, 0xa5a6c5, 0x6fbdbe, 0xdddddd, 0x797172, 0xeb99b1, 0x8fcd92, 0xffe5b3, 0xa2c8e9, 0xb2b3da, 0x6bcacb, 0xa8a8a8, 0x4b4b4b, 0xdddddd, 0xe2e2e2, 0x4b4b4b, 0x777777, 0xdddddd}},
{"Seoulbones Light", [22]uint32{0xe2e2e2, 0xdc5284, 0x628562, 0xc48562, 0x0084a3, 0x896788, 0x008586, 0x555555, 0xa5a0a1, 0xbe3c6d, 0x487249, 0xa76b48, 0x006f89, 0x7f4c7e, 0x006f70, 0x777777, 0xe2e2e2, 0x555555, 0x555555, 0xe2e2e2, 0xcccccc, 0x555555}},
{"Sequoia Monochrome Dark", [22]uint32{0x131317, 0x999eb2, 0x626983, 0xd3d5de, 0x7c829d, 0xe2e4ed, 0xb6bac8, 0x868690, 0x575861, 0x999eb2, 0x626983, 0xd3d5de, 0x7c829d, 0xe2e4ed, 0xb6bac8, 0x868690, 0x0f1014, 0x868690, 0x43444d, 0x868690, 0x817c9c, 0xacacb6}},
{"Sequoia Monochrome Light", [22]uint32{0xd4d5dc, 0x525666, 0x2e3038, 0x50535e, 0x5f6370, 0x25262d, 0x454752, 0x282930, 0x42434e, 0x525666, 0x2e3038, 0x50535e, 0x5f6370, 0x25262d, 0x454752, 0x282930, 0xedeef2, 0x282930, 0x565760, 0x282930, 0x817c9c, 0x282930}},
{"Sequoia Moonlight Dark", [22]uint32{0x131317, 0xf58ee0, 0x8eb6f5, 0x9898a6, 0xc58fff, 0xfdfdfe, 0xffbb88, 0x868690, 0x575861, 0xf58ee0, 0x8eb6f5, 0x9898a6, 0xc58fff, 0xfdfdfe, 0xffbb88, 0x868690, 0x0f1014, 0x868690, 0x43444d, 0x868690, 0x817c9c, 0xacacb6}},
{"Sequoia Moonlight Light", [22]uint32{0xd4d5dc, 0xc94da8, 0x4a85d4, 0x6a6a78, 0x9a5fd9, 0x282930, 0xd9884a, 0x282930, 0x42434e, 0xc94da8, 0x4a85d4, 0x6a6a78, 0x9a5fd9, 0x282930, 0xd9884a, 0x282930, 0xedeef2, 0x282930, 0x565760, 0x282930, 0x817c9c, 0x282930}},
{"Sequoia Retro Dark", [22]uint32{0x131317, 0x829fa7, 0x648f68, 0xda674b, 0x5c87a4, 0xe8b246, 0xa27e57, 0x868690, 0x575861, 0xe8b246, 0x648f68, 0xda674b, 0x5c87a4, 0x829fa7, 0xa27e57, 0x868690, 0x0f1014, 0x868690, 0x43444d, 0x868690, 0x817c9c, 0xacacb6}},
{"Sequoia Retro Light", [22]uint32{0xd4d5dc, 0x5f7982, 0x4a704e, 0xbf5238, 0x456a82, 0xc99730, 0x8a6539, 0x282930, 0x42434e, 0xc99730, 0x4a704e, 0xbf5238, 0x456a82, 0x5f7982, 0x8a6539, 0x282930, 0xedeef2, 0x282930, 0x565760, 0x282930, 0x817c9c, 0x282930}},
{"Serendipity Midnight", [22]uint32{0x232534, 0xee8679, 0x5ba2d0, 0xa78bfa, 0x94b8ff, 0x9ccfd8, 0xf8d2c9, 0xdee0ef, 0x8d8f9e, 0xee8679, 0x5ba2d0, 0xa78bfa, 0x94b8ff, 0x9ccfd8, 0xf8d2c9, 0xdee0ef, 0x151726, 0xdee0ef, 0x6b6d7c, 0xdee0ef, 0x6b6d7c, 0xdee0ef}},
{"Serendipity Morning", [22]uint32{0xccd0dc, 0xc25a4d, 0x2f7aab, 0x785fd0, 0x6288d8, 0x629aa5, 0xe58678, 0x3f4363, 0x505575, 0xc25a4d, 0x2f7aab, 0x785fd0, 0x6288d8, 0x629aa5, 0xe58678, 0x3f4363, 0xf6f7fb, 0x3f4363, 0x6d7296, 0x3f4363, 0x5a5670, 0x7f83a3}},
{"Serendipity Sunset", [22]uint32{0x363847, 0xd1918f, 0x709bbd, 0xa392dc, 0xa0b6e8, 0xaac9d4, 0xd6b4b4, 0xdee0ef, 0x6b6d7c, 0xd1918f, 0x709bbd, 0xa392dc, 0xa0b6e8, 0xaac9d4, 0xd6b4b4, 0xdee0ef, 0x202231, 0xdee0ef, 0x8d8f9e, 0xdee0ef, 0x6b6d7c, 0xdee0ef}},
{"Seti", [22]uint32{0x323232, 0xc22832, 0x8ec43d, 0xe0c64f, 0x43a5d5, 0x8b57b5, 0x8ec43d, 0xeeeeee, 0x3f3f3f, 0xc22832, 0x8ec43d, 0xe0c64f, 0x43a5d5, 0x8b57b5, 0x8ec43d, 0xffffff, 0x111213, 0xcacecd, 0xe3bf21, 0xad8b00, 0x303233, 0xcacecd}},
{"Shades Of Purple", [22]uint32{0x000000, 0xd90429, 0x3ad900, 0xffe700, 0x6943ff, 0xff2c70, 0x00c5c7, 0xc7c7c7, 0x686868, 0xf92a1c, 0x43d426, 0xf1d000, 0x6871ff, 0xff77ff, 0x79e8fb, 0xffffff, 0x1e1d40, 0xffffff, 0xfad000, 0x98998e, 0xb362ff, 0xc2c2c2}},
{"Shaman", [22]uint32{0x012026, 0xb2302d, 0x00a941, 0x5e8baa, 0x449a86, 0x00599d, 0x5d7e19, 0x405555, 0x384451, 0xff4242, 0x2aea5e, 0x8ed4fd, 0x61d5ba, 0x1298ff, 0x98d028, 0x58fbd6, 0x001015, 0x405555, 0x4afcd6, 0x031413, 0x415555, 0x5afad6}},
{"Shokunin", [22]uint32{0x303841, 0xc84053, 0x157a5b, 0x9a6000, 0x006fae, 0x8f4155, 0x006c7f, 0xc2beb4, 0x777269, 0xd95a66, 0x1b8e6a, 0xb67608, 0x0084c7, 0xa75b73, 0x008396, 0xffffff, 0xfcfaf2, 0x303841, 0x3a3e44, 0xfcfaf2, 0xd7eaf2, 0x303841}},
{"SilkCircuit Dawn", [22]uint32{0x2b2540, 0xc1272d, 0x1d6e46, 0x796100, 0x1454dc, 0xb40077, 0x006e72, 0xbab8bf, 0x5a4d6e, 0xdc2626, 0x288855, 0x7f5f00, 0x2572ef, 0xd92a99, 0x048397, 0xffffff, 0xfaf8ff, 0x2b2540, 0x006e72, 0xfaf8ff, 0xd4c8f0, 0x2b2540}},
{"SilkCircuit Glow", [22]uint32{0x000000, 0xff2244, 0x00ff00, 0xffff00, 0x0099ff, 0xff00ff, 0x00ffff, 0xffffff, 0x818181, 0xff6666, 0x66ff66, 0xffff66, 0x66ccff, 0xff66ff, 0x66ffff, 0xffffff, 0x0a0816, 0xffffff, 0x00ffff, 0x0a0816, 0x4b0654, 0xffffff}},
{"SilkCircuit Neon", [22]uint32{0x12101a, 0xff6363, 0x50fa7b, 0xf1fa8c, 0x82aaff, 0xff00ff, 0x80ffea, 0xf8f8f2, 0x768d8d, 0xff8787, 0x86fba8, 0xffffa5, 0x82b1ff, 0xff69ff, 0x5fffff, 0xffffff, 0x12101a, 0xf8f8f2, 0x80ffea, 0x12101a, 0x44475a, 0xf8f8f2}},
{"SilkCircuit Soft", [22]uint32{0x141220, 0xff6677, 0x66ff99, 0xffe699, 0x92aaff, 0xff99ff, 0x99ffee, 0xf8f8f2, 0x6272a4, 0xff7788, 0x80ffb3, 0xffffa5, 0xa2bbff, 0xffb3ff, 0xb3ffea, 0xffffff, 0x1a1626, 0xf8f8f2, 0x99ffee, 0x1a1626, 0x44475a, 0xf8f8f2}},
{"SilkCircuit Vibrant", [22]uint32{0x0f0c1a, 0xff3366, 0x00ff66, 0xffcc00, 0x6699ff, 0xff00cc, 0x00ffcc, 0xf8f8f2, 0x728989, 0xff6677, 0x66ff99, 0xffff66, 0x88aaff, 0xff66ff, 0x00ffff, 0xffffff, 0x0f0c1a, 0xf8f8f2, 0x00ffcc, 0x0f0c1a, 0x3a2e5a, 0xf8f8f2}},
{"Slate", [22]uint32{0x222222, 0xe2a8bf, 0x81d778, 0xc4c9c0, 0x335856, 0xa481d3, 0x15ab9c, 0x02c5e0, 0xffffff, 0xffcdd9, 0xbeffa8, 0xd0ccca, 0x7ab0d2, 0xc5a7d9, 0x8cdfe0, 0xe0e0e0, 0x222222, 0x35b1d2, 0x87d3c4, 0x323232, 0x0f3754, 0x2dffc0}},
{"Sleepy Hollow", [22]uint32{0x572100, 0xba3934, 0x91773f, 0xb55600, 0x5f63b4, 0xa17c7b, 0x8faea9, 0xaf9a91, 0x4e4b61, 0xd9443f, 0xd6b04e, 0xf66813, 0x8086ef, 0xe2c2bb, 0xa4dce7, 0xd2c7a9, 0x121214, 0xaf9a91, 0xaf9a91, 0x391a02, 0x575256, 0xd2c7a9}},
{"Smyck", [22]uint32{0x000000, 0xb84131, 0x7da900, 0xc4a500, 0x62a3c4, 0xba8acc, 0x207383, 0xa1a1a1, 0x7a7a7a, 0xd6837c, 0xc4f137, 0xfee14d, 0x8dcff0, 0xf79aff, 0x6ad9cf, 0xf7f7f7, 0x1b1b1b, 0xf7f7f7, 0xbbbbbb, 0xffffff, 0x207483, 0xf7f7f7}},
{"Snazzy", [22]uint32{0x000000, 0xfc4346, 0x50fb7c, 0xf0fb8c, 0x49baff, 0xfc4cb4, 0x8be9fe, 0xededec, 0x555555, 0xfc4346, 0x50fb7c, 0xf0fb8c, 0x49baff, 0xfc4cb4, 0x8be9fe, 0xededec, 0x1e1f29, 0xebece6, 0xe4e4e4, 0xa9a9a9, 0x81aec6, 0x000000}},
{"Snazzy Soft", [22]uint32{0x000000, 0xff5c57, 0x5af78e, 0xf3f99d, 0x57c7ff, 0xff6ac1, 0x9aedfe, 0xf1f1f0, 0x686868, 0xff5c57, 0x5af78e, 0xf3f99d, 0x57c7ff, 0xff6ac1, 0x9aedfe, 0xf1f1f0, 0x282a36, 0xeff0eb, 0xeaeaea, 0x282a36, 0x92bcd0, 0x000000}},
{"Soft Server", [22]uint32{0x000000, 0xa2686a, 0x9aa56a, 0xa3906a, 0x6b8fa3, 0x6a71a3, 0x6ba58f, 0x99a3a2, 0x666c6c, 0xdd5c60, 0xbfdf55, 0xdeb360, 0x62b1df, 0x606edf, 0x64e39c, 0xd2e0de, 0x242626, 0x99a3a2, 0xd2e0de, 0x000000, 0x7f8786, 0xeffffe}},
{"Solarized Darcula", [22]uint32{0x25292a, 0xf24840, 0x629655, 0xb68800, 0x2075c7, 0x797fd4, 0x15968d, 0xd2d8d9, 0x65696a, 0xf24840, 0x629655, 0xb68800, 0x2075c7, 0x797fd4, 0x15968d, 0xd2d8d9, 0x3d3f41, 0xd2d8d9, 0x708284, 0x002831, 0x214283, 0xd2d8d9}},
{"Solarized Dark Higher Contrast", [22]uint32{0x002831, 0xd11c24, 0x6cbe6c, 0xa57706, 0x2176c7, 0xc61c6f, 0x259286, 0xeae3cb, 0x006488, 0xf5163b, 0x51ef84, 0xb27e28, 0x178ec8, 0xe24d8e, 0x00b39e, 0xfcf4dc, 0x001e27, 0x9cc2c3, 0xf34b00, 0x002831, 0x003748, 0x7a8f8e}},
{"Solarized Dark Patched", [22]uint32{0x002831, 0xd11c24, 0x738a05, 0xa57706, 0x2176c7, 0xc61c6f, 0x259286, 0xeae3cb, 0x475b62, 0xbd3613, 0x475b62, 0x536870, 0x708284, 0x5956ba, 0x819090, 0xfcf4dc, 0x001e27, 0x708284, 0x708284, 0x002831, 0x002831, 0x819090}},
{"Solarized Osaka Night", [22]uint32{0x15161e, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xa9b1d6, 0x414868, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xc0caf5, 0x1a1b26, 0xc0caf5, 0xc0caf5, 0x1a1b26, 0x283457, 0xc0caf5}},
{"Sonokai", [22]uint32{0x181819, 0xfc5d7c, 0x9ed072, 0xe7c664, 0x76cce0, 0xb39df3, 0xf39660, 0xe2e2e3, 0x7f8490, 0xfc5d7c, 0x9ed072, 0xe7c664, 0x76cce0, 0xb39df3, 0xf39660, 0xe2e2e3, 0x2c2e34, 0xe2e2e3, 0xe2e2e3, 0x2c2e34, 0x414550, 0xe2e2e3}},
{"Spacedust", [22]uint32{0x6e5346, 0xe35b00, 0x5cab96, 0xe3cd7b, 0x0f548b, 0xe35b00, 0x06afc7, 0xf0f1ce, 0x684c31, 0xff8a3a, 0xaecab8, 0xffc878, 0x67a0ce, 0xff8a3a, 0x83a7b4, 0xfefff1, 0x0a1e24, 0xecf0c1, 0x708284, 0x002831, 0x0a385c, 0xffffff}},
{"Spacegray", [22]uint32{0x000000, 0xb04b57, 0x87b379, 0xe5c179, 0x7d8fa4, 0xa47996, 0x85a7a5, 0xb3b8c3, 0x4c4c4c, 0xb04b57, 0x87b379, 0xe5c179, 0x7d8fa4, 0xa47996, 0x85a7a5, 0xffffff, 0x20242d, 0xb3b8c3, 0xb3b8c3, 0x1d1f21, 0x16181e, 0xb3b8c3}},
{"Spacegray Bright", [22]uint32{0x080808, 0xbc5553, 0xa0b56c, 0xf6c987, 0x7baec1, 0xb98aae, 0x85c9b8, 0xd8d8d8, 0x626262, 0xbc5553, 0xa0b56c, 0xf6c987, 0x7baec1, 0xb98aae, 0x85c9b8, 0xf7f7f7, 0x2a2e3a, 0xf3f3f3, 0xc6c6c6, 0x8c8c8c, 0xcacaca, 0x000000}},
{"Spacegray Eighties", [22]uint32{0x15171c, 0xec5f67, 0x81a764, 0xfec254, 0x5486c0, 0xbf83c1, 0x57c2c1, 0xefece7, 0x555555, 0xff6973, 0x93d493, 0xffd256, 0x4d84d1, 0xff55ff, 0x83e9e4, 0xffffff, 0x222222, 0xbdbaae, 0xbbbbbb, 0xffffff, 0x272e35, 0xffffff}},
{"Spacegray Eighties Dull", [22]uint32{0x15171c, 0xb24a56, 0x92b477, 0xc6735a, 0x7c8fa5, 0xa5789e, 0x80cdcb, 0xb3b8c3, 0x555555, 0xec5f67, 0x89e986, 0xfec254, 0x5486c0, 0xbf83c1, 0x58c2c1, 0xffffff, 0x222222, 0xc9c6bc, 0xbbbbbb, 0xffffff, 0x272e36, 0xffffff}},
{"Spiderman", [22]uint32{0x1b1d1e, 0xe60813, 0xe22928, 0xe24756, 0x2c3fff, 0x2435db, 0x3256ff, 0xfffef6, 0x505354, 0xff0325, 0xff3338, 0xfe3a35, 0x1d50ff, 0x747cff, 0x6184ff, 0xfffff9, 0x1b1d1e, 0xe3e3e3, 0x2c3fff, 0x000000, 0x070e50, 0xf0272d}},
{"Spring", [22]uint32{0x000000, 0xff4d83, 0x1f8c3b, 0x1fc95b, 0x1dd3ee, 0x8959a8, 0x3e999f, 0xbfbfbf, 0x000000, 0xff0021, 0x1fc231, 0xd5b807, 0x15a9fd, 0x8959a8, 0x3e999f, 0xffffff, 0xffffff, 0x4d4d4c, 0x4d4d4c, 0xffffff, 0xd6d6d6, 0x4d4d4c}},
{"Square", [22]uint32{0x050505, 0xe9897c, 0xb6377d, 0xecebbe, 0xa9cdeb, 0x75507b, 0xc9caec, 0xf2f2f2, 0x474747, 0xf99286, 0xc3f786, 0xfcfbcc, 0xb6defb, 0xad7fa8, 0xd7d9fc, 0xe2e2e2, 0x1a1a1a, 0xacacab, 0xfcfbcc, 0x000000, 0x4d4d4d, 0xffffff}},
{"Squintless", [22]uint32{0xf2e5bc, 0x9d0006, 0x79740e, 0xb57614, 0x076678, 0x8f3f71, 0x427b58, 0x7c6f64, 0x928374, 0x9d0006, 0x79740e, 0xb57614, 0x076678, 0x8f3f71, 0x427b58, 0x3c3836, 0xf2e5bc, 0x3c3836, 0x282828, 0xf2e5bc, 0xd5c4a1, 0x3c3836}},
{"Squirrelsong Dark", [22]uint32{0x372920, 0xba4138, 0x468336, 0xd4b139, 0x4395c6, 0x855fb8, 0x2f9794, 0xd3b9a2, 0x704f39, 0xdf4d43, 0x659a4c, 0xe8c23f, 0x4ca4db, 0x9d70da, 0x60aca9, 0xf2d4bb, 0x372920, 0xb19b89, 0xb19b89, 0x372920, 0x5b402e, 0xb19b89}},
{"Srcery", [22]uint32{0x1c1b19, 0xef2f27, 0x519f50, 0xfbb829, 0x2c78bf, 0xe02c6d, 0x0aaeb3, 0xbaa67f, 0x918175, 0xf75341, 0x98bc37, 0xfed06e, 0x68a8e4, 0xff5c8f, 0x2be4d0, 0xfce8c3, 0x1c1b19, 0xfce8c3, 0xfbb829, 0x1c1b19, 0xfce8c3, 0x1c1b19}},
{"Starlight", [22]uint32{0x242424, 0xf62b5a, 0x47b413, 0xe3c401, 0x24acd4, 0xf2affd, 0x13c299, 0xe6e6e6, 0x616161, 0xff4d51, 0x35d450, 0xe9e836, 0x5dc5f8, 0xfeabf2, 0x24dfc4, 0xffffff, 0x242424, 0xffffff, 0xffffff, 0x242424, 0xffffff, 0x242424}},
{"Sublette", [22]uint32{0x253045, 0xee5577, 0x55ee77, 0xffdd88, 0x5588ff, 0xff77cc, 0x44eeee, 0xf5f5da, 0x405570, 0xee6655, 0x99ee77, 0xffff77, 0x77bbff, 0xaa88ff, 0x55ffbb, 0xffffee, 0x202535, 0xccced0, 0xccced0, 0x202535, 0xccced0, 0x202535}},
{"Subliminal", [22]uint32{0x7f7f7f, 0xe15a60, 0xa9cfa4, 0xffe2a9, 0x6699cc, 0xf1a5ab, 0x5fb3b3, 0xd4d4d4, 0x7f7f7f, 0xe15a60, 0xa9cfa4, 0xffe2a9, 0x6699cc, 0xf1a5ab, 0x5fb3b3, 0xd4d4d4, 0x282c35, 0xd4d4d4, 0xc7c7c7, 0x8c8c8c, 0x484e5b, 0xffffff}},
{"Sugarplum", [22]uint32{0x111147, 0x5ca8dc, 0x53b397, 0x249a84, 0xdb7ddd, 0xd0beee, 0xf9f3f9, 0xa175d4, 0x44447a, 0x5cb5dc, 0x52deb5, 0x01f5c7, 0xfa5dfd, 0xc6a5fd, 0xffffff, 0xb577fd, 0x111147, 0xdb7ddd, 0x53b397, 0x93f3d7, 0x5ca8dc, 0xead8ff}},
{"Sumi Linen", [22]uint32{0x3a342c, 0xb83830, 0x2e8050, 0xa87820, 0x3060a0, 0x704890, 0x18786c, 0x5a5448, 0x6a6458, 0xc84840, 0x3a9868, 0xc09030, 0x4080c0, 0x8858a8, 0x28a090, 0x14100c, 0xe6dfd0, 0x1c1814, 0x18786c, 0xe6dfd0, 0x9ec4ba, 0x14100c}},
{"Sumi Phosphor", [22]uint32{0x1e1a16, 0xd45848, 0x5ca868, 0xd4a03c, 0x5a82b8, 0x9870b0, 0x2ec4b6, 0x8a8478, 0x474139, 0xe87060, 0x72c078, 0xe8b84c, 0x70a0d8, 0xb088c8, 0x48d8c8, 0xe0dcd4, 0x12100e, 0xbab4a8, 0x2ec4b6, 0x12100e, 0x3a3834, 0xe8e4dc}},
{"Sundried", [22]uint32{0x302b2a, 0xa7463d, 0x587744, 0x9d602a, 0x485b98, 0x864651, 0x9c814f, 0xc9c9c9, 0x4d4e48, 0xaa000c, 0x128c21, 0xfc6a21, 0x7999f7, 0xfd8aa1, 0xfad484, 0xffffff, 0x1a1818, 0xc9c9c9, 0xffffff, 0x191717, 0x302b2a, 0xc9c9c9}},
{"Sunset Drive", [22]uint32{0x0a0a13, 0xff0063, 0x00f992, 0xffe900, 0x00a4ff, 0xff57fd, 0x00ffed, 0xededff, 0x3e3e4b, 0xff948b, 0x00fcb9, 0xffff68, 0x3ea0ff, 0xff93ff, 0x38ffff, 0xf8f8ff, 0x0f0f1a, 0xededfe, 0xededfe, 0x0f0f1a, 0x202036, 0xededff}},
{"Symfonic", [22]uint32{0x000000, 0xdc322f, 0x56db3a, 0xff8400, 0x0084d4, 0xb729d9, 0xccccff, 0xffffff, 0x414347, 0xdc322f, 0x56db3a, 0xff8400, 0x0084d4, 0xb729d9, 0xccccff, 0xffffff, 0x000000, 0xffffff, 0xdc322f, 0xffffff, 0x073642, 0xffffff}},
{"Synthwave", [22]uint32{0x000000, 0xf6188f, 0x1ebb2b, 0xfdf834, 0x2186ec, 0xf85a21, 0x12c3e2, 0xffffff, 0x7f7094, 0xf841a0, 0x25c141, 0xfdf454, 0x2f9ded, 0xf97137, 0x19cde6, 0xffffff, 0x000000, 0xdad9c7, 0x19cde6, 0xffffed, 0x19cde6, 0x000000}},
{"Synthwave Alpha", [22]uint32{0x241b30, 0xe60a70, 0x00986c, 0xadad3e, 0x6e29ad, 0xb300ad, 0x00b0b1, 0xb9b1bc, 0x7f7094, 0xe60a70, 0x0ae4a4, 0xf9f972, 0xaa54f9, 0xff00f6, 0x00fbfd, 0xf2f2e3, 0x241b30, 0xf2f2e3, 0xf2f2e3, 0x241b30, 0x6e29ad, 0xf2f2e3}},
{"Synthwave Everything", [22]uint32{0xfefefe, 0xf97e72, 0x72f1b8, 0xfede5d, 0x6d77b3, 0xc792ea, 0xf772e0, 0xfefefe, 0xfefefe, 0xf88414, 0x72f1b8, 0xfff951, 0x36f9f6, 0xe1acff, 0xf92aad, 0xfefefe, 0x2a2139, 0xf0eff1, 0x72f1b8, 0x1a1a1a, 0x181521, 0xf0eff1}},
{"Tango Adapted", [22]uint32{0x000000, 0xff0000, 0x59d600, 0xe3be00, 0x00a2ff, 0xc17ecc, 0x00d0d6, 0xc0c5bb, 0x8f928b, 0xff0013, 0x6dd900, 0xccbe00, 0x88c9ff, 0xe9a7e1, 0x00d8d9, 0xf6f6f4, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xc1deff, 0x000000}},
{"Tango Half Adapted", [22]uint32{0x000000, 0xff0000, 0x4cc300, 0xe2c000, 0x008ef6, 0xa96cb3, 0x00bdc3, 0xbabfb5, 0x797d76, 0xff0013, 0x70dc00, 0xd9c600, 0x76bfff, 0xd898d1, 0x00d0d4, 0xf4f4f2, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xc1deff, 0x000000}},
{"Tearout", [22]uint32{0x685742, 0xcc967b, 0x97976d, 0x6c9861, 0xb5955e, 0xc9a554, 0xd7c483, 0xb5955e, 0x75644f, 0xcc967b, 0x97976d, 0x6c9861, 0xb5955e, 0xc9a554, 0xd7c483, 0xb5955e, 0x34392d, 0xf4d2ae, 0xd7c483, 0x141415, 0xe4c47a, 0x000000}},
{"Teerb", [22]uint32{0x1c1c1c, 0xd68686, 0xaed686, 0xd7af87, 0x86aed6, 0xd6aed6, 0x8adbb4, 0xd0d0d0, 0x4f4f4f, 0xd68686, 0xaed686, 0xe4c9af, 0x86aed6, 0xd6aed6, 0xb1e7dd, 0xefefef, 0x262626, 0xd0d0d0, 0xe4c9af, 0x000000, 0x4d4d4d, 0xffffff}},
{"Terafox", [22]uint32{0x2f3239, 0xe85c51, 0x7aa4a1, 0xfda47f, 0x5a93aa, 0xad5c7c, 0xa1cdd8, 0xebebeb, 0x4e5157, 0xeb746b, 0x8eb2af, 0xfdb292, 0x73a3b7, 0xb97490, 0xafd4de, 0xeeeeee, 0x152528, 0xe6eaea, 0xe6eaea, 0x152528, 0x293e40, 0xe6eaea}},
{"Terminal Basic", [22]uint32{0x000000, 0x990000, 0x00a600, 0x999900, 0x0000b2, 0xb200b2, 0x00a6b2, 0xbfbfbf, 0x666666, 0xe50000, 0x00d900, 0xbfbf00, 0x0000ff, 0xe500e5, 0x00d8d8, 0xe5e5e5, 0xffffff, 0x000000, 0x7f7f7f, 0x000000, 0xa4c9ff, 0x000000}},
{"Terminal Basic Dark", [22]uint32{0x000000, 0xc65339, 0x6ac44b, 0xb8b74a, 0x6444ed, 0xd357db, 0x69c1cf, 0xd1d1d1, 0x909090, 0xeb5a3a, 0x77ea51, 0xefef53, 0xd09af9, 0xeb5af7, 0x78f1f2, 0xededed, 0x1d1e1d, 0xffffff, 0x9d9d9d, 0x1d1e1d, 0x3f638a, 0xffffff}},
{"Terminal Green 1999", [22]uint32{0x32463a, 0xff5c7a, 0x22c55e, 0x00d26a, 0x7dd3fc, 0x9dff57, 0x39ff88, 0x8fd6a9, 0x274335, 0xff7d95, 0x4ed17e, 0x2eda85, 0x97dcfd, 0xb1ff79, 0x61ffa0, 0xd8ffe6, 0x03120a, 0xd8ffe6, 0xd8ffe6, 0x03120a, 0xd8ffe6, 0x03120a}},
{"Thayer Bright", [22]uint32{0x1b1d1e, 0xf92672, 0x4df840, 0xf4fd22, 0x2757d6, 0x8c54fe, 0x38c8b5, 0xccccc6, 0x505354, 0xff5995, 0xb6e354, 0xfeed6c, 0x3f78ff, 0x9e6ffe, 0x23cfd5, 0xf8f8f2, 0x1b1d1e, 0xf8f8f8, 0xfc971f, 0x000000, 0x4d4d4d, 0xffffff}},
{"The Hulk", [22]uint32{0x1b1d1e, 0x269d1b, 0x13ce30, 0x63e457, 0x2525f5, 0x712c81, 0x378ca9, 0xd9d8d1, 0x505354, 0x8dff2a, 0x48ff77, 0x3afe16, 0x506b95, 0x72589d, 0x4085a6, 0xe5e6e1, 0x1b1d1e, 0xb5b5b5, 0x16b61b, 0x000000, 0x4d504c, 0x31892f}},
{"Tinacious Design Dark", [22]uint32{0x1d1d26, 0xff3399, 0x00d364, 0xffcc66, 0x00cbff, 0xcc66ff, 0x00ceca, 0xcbcbf0, 0x636667, 0xff2f92, 0x00d364, 0xffd479, 0x00cbff, 0xd783ff, 0x00d5d4, 0xd5d6f3, 0x1d1d26, 0xcbcbf0, 0xcbcbf0, 0x999999, 0xff3399, 0xffffff}},
{"Tinacious Design Light", [22]uint32{0x1d1d26, 0xff3399, 0x00d364, 0xe5b24d, 0x00cbff, 0xcc66ff, 0x00ceca, 0xb1b1d6, 0x636667, 0xff2f92, 0x00d364, 0xd9ae53, 0x00cbff, 0xd783ff, 0x00c8c7, 0xd5d6f3, 0xf8f8ff, 0x1d1d26, 0xb1b1d6, 0xffffff, 0xff3399, 0xffffff}},
{"Token Dark", [22]uint32{0x1d1d1c, 0xc67777, 0x7da47a, 0xc4a855, 0x7b9ebd, 0xa68bbf, 0x6ba8a8, 0xd4cfc6, 0x5a5955, 0xd97757, 0x98bf95, 0xc4956a, 0x96b8d3, 0xbea5d4, 0x88c0c0, 0xe8e4dc, 0x262624, 0xe8e4dc, 0xe8e4dc, 0x262624, 0x3a3a37, 0xe8e4dc}},
{"Token Light", [22]uint32{0x2a2920, 0xb05555, 0x3f643c, 0x6e5c20, 0x527594, 0x7c619a, 0x2d6c6c, 0xb5b2ab, 0x6c675f, 0x9a4929, 0x3a5e37, 0x876032, 0x486a88, 0x6f578c, 0x286363, 0xfaf9f5, 0xfaf9f5, 0x2a2920, 0x2a2920, 0xfaf9f5, 0xdddcd6, 0x2a2920}},
{"TokyoNight", [22]uint32{0x15161e, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xa9b1d6, 0x414868, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xc0caf5, 0x1a1b26, 0xc0caf5, 0xc0caf5, 0x15161e, 0x33467c, 0xc0caf5}},
{"TokyoNight Day", [22]uint32{0xe9e9ed, 0xf52a65, 0x587539, 0x8c6c3e, 0x2e7de9, 0x9854f1, 0x007197, 0x6172b0, 0xa1a6c5, 0xf52a65, 0x587539, 0x8c6c3e, 0x2e7de9, 0x9854f1, 0x007197, 0x3760bf, 0xe1e2e7, 0x3760bf, 0x3760bf, 0xe1e2e7, 0x99a7df, 0x3760bf}},
{"TokyoNight Moon", [22]uint32{0x1b1d2b, 0xff757f, 0xc3e88d, 0xffc777, 0x82aaff, 0xc099ff, 0x86e1fc, 0x828bb8, 0x444a73, 0xff757f, 0xc3e88d, 0xffc777, 0x82aaff, 0xc099ff, 0x86e1fc, 0xc8d3f5, 0x222436, 0xc8d3f5, 0xc8d3f5, 0x222436, 0x2d3f76, 0xc8d3f5}},
{"TokyoNight Night", [22]uint32{0x15161e, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xa9b1d6, 0x414868, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xc0caf5, 0x1a1b26, 0xc0caf5, 0xc0caf5, 0x1a1b26, 0x283457, 0xc0caf5}},
{"TokyoNight Storm", [22]uint32{0x1d202f, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xa9b1d6, 0x4e5575, 0xf7768e, 0x9ece6a, 0xe0af68, 0x7aa2f7, 0xbb9af7, 0x7dcfff, 0xc0caf5, 0x24283b, 0xc0caf5, 0xc0caf5, 0x1d202f, 0x364a82, 0xc0caf5}},
{"Tomorrow", [22]uint32{0x000000, 0xc82829, 0x718c00, 0xeab700, 0x4271ae, 0x8959a8, 0x3e999f, 0xbfbfbf, 0x000000, 0xc82829, 0x718c00, 0xeab700, 0x4271ae, 0x8959a8, 0x3e999f, 0xffffff, 0xffffff, 0x4d4d4c, 0x4d4d4c, 0xffffff, 0xd6d6d6, 0x4d4d4c}},
{"Tomorrow Night", [22]uint32{0x000000, 0xcc6666, 0xb5bd68, 0xf0c674, 0x81a2be, 0xb294bb, 0x8abeb7, 0xffffff, 0x4c4c4c, 0xcc6666, 0xb5bd68, 0xf0c674, 0x81a2be, 0xb294bb, 0x8abeb7, 0xffffff, 0x1d1f21, 0xc5c8c6, 0xc5c8c6, 0x1d1f21, 0x373b41, 0xc5c8c6}},
{"Tomorrow Night Blue", [22]uint32{0x000000, 0xff9da4, 0xd1f1a9, 0xffeead, 0xbbdaff, 0xebbbff, 0x99ffff, 0xffffff, 0x4c4c4c, 0xff9da4, 0xd1f1a9, 0xffeead, 0xbbdaff, 0xebbbff, 0x99ffff, 0xffffff, 0x002451, 0xffffff, 0xffffff, 0x003f8e, 0x003f8e, 0xffffff}},
{"Tomorrow Night Bright", [22]uint32{0x000000, 0xd54e53, 0xb9ca4a, 0xe7c547, 0x7aa6da, 0xc397d8, 0x70c0b1, 0xffffff, 0x404040, 0xd54e53, 0xb9ca4a, 0xe7c547, 0x7aa6da, 0xc397d8, 0x70c0b1, 0xffffff, 0x000000, 0xeaeaea, 0xeaeaea, 0x000000, 0x424242, 0xeaeaea}},
{"Tomorrow Night Burns", [22]uint32{0x252525, 0x832e31, 0xa63c40, 0xd3494e, 0xfc595f, 0xdf9395, 0xba8586, 0xf5f5f5, 0x5d6f71, 0x832e31, 0xa63c40, 0xd2494e, 0xfc595f, 0xdf9395, 0xba8586, 0xf5f5f5, 0x151515, 0xa1b0b8, 0xff443e, 0xb0c2c4, 0xb0bec5, 0x2a2d32}},
{"Tomorrow Night Eighties", [22]uint32{0x000000, 0xf2777a, 0x99cc99, 0xffcc66, 0x6699cc, 0xcc99cc, 0x66cccc, 0xffffff, 0x595959, 0xf2777a, 0x99cc99, 0xffcc66, 0x6699cc, 0xcc99cc, 0x66cccc, 0xffffff, 0x2d2d2d, 0xcccccc, 0xcccccc, 0x2d2d2d, 0x515151, 0xcccccc}},
{"Toy Chest", [22]uint32{0x2c3f58, 0xbe2d26, 0x1a9172, 0xdb8e27, 0x325d96, 0x8a5edc, 0x35a08f, 0x23d183, 0x336889, 0xdd5944, 0x31d07b, 0xe7d84b, 0x34a6da, 0xae6bdc, 0x42c3ae, 0xd5d5d5, 0x24364b, 0x31d07b, 0xd5d5d5, 0x141c25, 0x5f217a, 0xd5d5d5}},
{"Trapped in Amber", [22]uint32{0x4a3220, 0xe05c1c, 0x7a9c4a, 0xf0a020, 0x4a7ec9, 0xc95a8c, 0x7a9ea8, 0xffd9a0, 0x5a4a3a, 0xff7832, 0xa8c46b, 0xffd700, 0x6b9fff, 0xff7fa8, 0xa5c2cc, 0xfff5e0, 0x0a1017, 0xf0a020, 0xffc940, 0x0a1017, 0x4a3416, 0xffd9a0}},
{"Treehouse", [22]uint32{0x321300, 0xb2270e, 0x44a900, 0xaa820c, 0x58859a, 0x97363d, 0xb25a1e, 0x786b53, 0x504333, 0xed5d20, 0x55f238, 0xf2b732, 0x85cfed, 0xe14c5a, 0xf07d14, 0xffc800, 0x191919, 0x786b53, 0xfac814, 0x191919, 0x786b53, 0xfac800}},
{"Twilight", [22]uint32{0x141414, 0xc06d44, 0xafb97a, 0xc2a86c, 0x44474a, 0xb4be7c, 0x778385, 0xffffd4, 0x404040, 0xde7c4c, 0xccd88c, 0xe2c47e, 0x5a5e62, 0xd0dc8e, 0x8a989b, 0xffffd4, 0x141414, 0xffffd4, 0xffffff, 0x000000, 0x313131, 0xffffd4}},
{"Ubuntu", [22]uint32{0x2e3436, 0xcc0000, 0x4e9a06, 0xc4a000, 0x3465a4, 0x75507b, 0x06989a, 0xd3d7cf, 0x555753, 0xef2929, 0x8ae234, 0xfce94f, 0x729fcf, 0xad7fa8, 0x34e2e2, 0xeeeeec, 0x300a24, 0xeeeeec, 0xbbbbbb, 0xffffff, 0xb5d5ff, 0x000000}},
{"Ultra Dark", [22]uint32{0x000000, 0xf07178, 0xc3e88d, 0xffcb6b, 0x82aaff, 0xc792ea, 0x89ddff, 0xcccccc, 0x404040, 0xf6a9ae, 0xdbf1ba, 0xffdfa6, 0xb4ccff, 0xddbdf2, 0xb8eaff, 0xffffff, 0x000000, 0xffffff, 0xfefefe, 0x000000, 0x222222, 0xcccccc}},
{"Ultra Violent", [22]uint32{0x242728, 0xff0090, 0xb6ff00, 0xfff727, 0x47e0fb, 0xd731ff, 0x0effbb, 0xe1e1e1, 0x636667, 0xfb58b4, 0xdeff8c, 0xebe087, 0x7fecff, 0xe681ff, 0x69fcd3, 0xf9f9f5, 0x242728, 0xc1c1c1, 0xc1c1c1, 0xffffff, 0x574c49, 0xc3c7cb}},
{"Under The Sea", [22]uint32{0x022026, 0xb2302d, 0x00a941, 0x59819c, 0x459a86, 0x00599d, 0x5d7e19, 0x405555, 0x384451, 0xff4242, 0x2aea5e, 0x8ed4fd, 0x61d5ba, 0x1298ff, 0x98d028, 0x58fbd6, 0x011116, 0xffffff, 0x4afcd6, 0x031413, 0x415555, 0x4dffda}},
{"Unikitty", [22]uint32{0x0c0c0c, 0xa80f20, 0xc7ff98, 0xfff964, 0x145fcd, 0xffe9ff, 0x9effef, 0xfcf1fb, 0x434343, 0xd91329, 0xd3ffaf, 0xffef50, 0x0075ea, 0xffefff, 0x93ffef, 0xfff3fe, 0xff8cd9, 0x0b0b0b, 0xc7ff98, 0x202020, 0x3ea9fe, 0xffffff}},
{"Urple", [22]uint32{0x000000, 0xb0425b, 0x37a415, 0xad5c42, 0x564d9b, 0x6c3ca1, 0x808080, 0x87799c, 0x6a3f32, 0xff6388, 0x29e620, 0xf08161, 0x867aed, 0xa05eee, 0xeaeaea, 0xbfa3ff, 0x1b1b23, 0x877a9b, 0xa063eb, 0x1b1b22, 0xa063eb, 0x1b1b22}},
{"Vague", [22]uint32{0x252530, 0xd8647e, 0x7fa563, 0xf3be7c, 0x6e94b2, 0xbb9dbd, 0xaeaed1, 0xcdcdcd, 0x606079, 0xe08398, 0x99b782, 0xf5cb96, 0x8ba9c1, 0xc9b1ca, 0xbebeda, 0xd7d7d7, 0x141415, 0xcdcdcd, 0xcdcdcd, 0x141415, 0x252530, 0xcdcdcd}},
{"Vaporwave Sunset", [22]uint32{0x4b3d53, 0xfb7185, 0x2dd4bf, 0xfb923c, 0xa78bfa, 0x22d3ee, 0xff4fd8, 0xf0abfc, 0x563f6e, 0xfc8d9d, 0x57ddcc, 0xfca65f, 0xb9a2fb, 0x4edcf1, 0xff72e0, 0xfff7ed, 0x180827, 0xfff7ed, 0xfff7ed, 0x180827, 0xfff7ed, 0x180827}},
{"Vaughn", [22]uint32{0x25234f, 0x705050, 0x60b48a, 0xdfaf8f, 0x5555ff, 0xf08cc3, 0x8cd0d3, 0x709080, 0x709080, 0xdca3a3, 0x60b48a, 0xf0dfaf, 0x5555ff, 0xec93d3, 0x93e0e3, 0xffffff, 0x25234f, 0xdcdccc, 0xff5555, 0xffffff, 0xb5d5ff, 0x000000}},
{"Velvet Court", [22]uint32{0x2f1629, 0xee5c82, 0x9ad08a, 0xf0c44e, 0xb392e8, 0xd087e0, 0x6fd0c8, 0xe2c8d8, 0x836075, 0xee5c82, 0x9ad08a, 0xe8964f, 0xb392e8, 0xd087e0, 0x6fd0c8, 0xf2dcea, 0x1f0e1c, 0xf2dcea, 0xf0c44e, 0x1f0e1c, 0x3e2138, 0x5f4e5c}},
{"Vercel", [22]uint32{0x000000, 0xfc0036, 0x29a948, 0xffae00, 0x006aff, 0xf32882, 0x00ac96, 0xfeffff, 0xa8a8a8, 0xff8080, 0x4be15d, 0xffae00, 0x49aeff, 0xf97ea8, 0x00e4c4, 0xfefefe, 0x101010, 0xfafafa, 0xf32882, 0xfafafa, 0x005be7, 0xfafafa}},
{"Verdigris", [22]uint32{0x221c12, 0xd9604f, 0xa8b86a, 0xd9a441, 0x5fbfb0, 0xb98fb0, 0x8fd6b0, 0xbfb29a, 0x6e6450, 0xd9604f, 0xa8b86a, 0xc97a45, 0x5fbfb0, 0xb98fb0, 0x8fd6b0, 0xe8dcc6, 0x14110b, 0xe8dcc6, 0xce8b45, 0x14110b, 0x2a2417, 0x54514b}},
{"Vesper", [22]uint32{0x101010, 0xf5a191, 0x90b99f, 0xe6b99d, 0xaca1cf, 0xe29eca, 0xea83a5, 0xa0a0a0, 0x7e7e7e, 0xff8080, 0x99ffe4, 0xffc799, 0xb9aeda, 0xecaad6, 0xf591b2, 0xffffff, 0x101010, 0xffffff, 0xacb1ab, 0xffffff, 0x988049, 0xb9beb8}},
{"Vibrant Ink", [22]uint32{0x878787, 0xff6600, 0xccff04, 0xffcc00, 0x44b4cc, 0x9933cc, 0x44b4cc, 0xf5f5f5, 0x555555, 0xff0000, 0x00ff00, 0xffff00, 0x0000ff, 0xff00ff, 0x00ffff, 0xe5e5e5, 0x000000, 0xffffff, 0xffffff, 0x000000, 0xb5d5ff, 0x000000}},
{"Vimbones", [22]uint32{0xf0f0ca, 0xa8334c, 0x4f6c31, 0x944927, 0x286486, 0x88507d, 0x3b8992, 0x353535, 0xacac89, 0x94253e, 0x3f5a22, 0x803d1c, 0x1d5573, 0x7b3b70, 0x2b747c, 0x5c5c5c, 0xf0f0ca, 0x353535, 0x353535, 0xf0f0ca, 0xd7d7d7, 0x353535}},
{"Violet Dark", [22]uint32{0x56595c, 0xc94c22, 0x85981c, 0xb4881d, 0x2e8bce, 0xd13a82, 0x32a198, 0xc9c6bd, 0x45484b, 0xbd3613, 0x738a04, 0xa57705, 0x2176c7, 0xc61c6f, 0x259286, 0xc9c6bd, 0x1c1d1f, 0x708284, 0x708284, 0x1c1d1f, 0x595ab7, 0x1c1d1f}},
{"Violet Light", [22]uint32{0x56595c, 0xc94c22, 0x85981c, 0xb4881d, 0x2e8bce, 0xd13a82, 0x32a198, 0xb9b6af, 0x45484b, 0xbd3613, 0x738a04, 0xa57705, 0x2176c7, 0xc61c6f, 0x259286, 0xc9c6bd, 0xfcf4dc, 0x536870, 0x536870, 0xfcf4dc, 0x595ab7, 0xfcf4dc}},
{"Violite", [22]uint32{0x241c36, 0xec7979, 0x79ecb3, 0xece279, 0xa979ec, 0xec79ec, 0x79ecec, 0xeef4f6, 0x56447a, 0xef8f8f, 0x9fefbf, 0xefe78f, 0xb78fef, 0xef8fcf, 0x9fefef, 0xf8fafc, 0x241c36, 0xeef4f6, 0xeef4f6, 0x241c36, 0x49376d, 0xeef4f6}},
{"Warm Burnout Dark", [22]uint32{0x23211b, 0xf06b73, 0x70bf56, 0xfdb04c, 0x4fbfff, 0xd0a1ff, 0x93e2c8, 0xc7c7c7, 0x686868, 0xf07178, 0xaad94c, 0xffb454, 0x59c2ff, 0xd2a6ff, 0x95e6cb, 0xffffff, 0x1a1510, 0xbfbdb6, 0xf5c56e, 0x1a1510, 0x33393a, 0xbfbdb6}},
{"Warm Burnout Light", [22]uint32{0x3a3630, 0xb82820, 0x2d6a14, 0x8a6000, 0x2060a0, 0x8a3090, 0x146858, 0xb3ab9d, 0x686868, 0xc83028, 0x3a7a20, 0x9a7008, 0x2870b0, 0x9a38a0, 0x208870, 0xfaf6f0, 0xf5ede0, 0x3a3630, 0x8a6600, 0xf5ede0, 0xe5e8e2, 0x3a3630}},
{"Warm Neon", [22]uint32{0x000000, 0xe24346, 0x39b13a, 0xdae145, 0x4261c5, 0xf920fb, 0x2abbd4, 0xd0b8a3, 0xfefcfc, 0xe97071, 0x9cc090, 0xddda7a, 0x7b91d6, 0xf674ba, 0x5ed1e5, 0xd8c8bb, 0x404040, 0xafdab6, 0x30ff24, 0x0bbc04, 0xb0ad21, 0xffffff}},
{"Wez", [22]uint32{0x000000, 0xcc5555, 0x55cc55, 0xcdcd55, 0x5555cc, 0xcc55cc, 0x7acaca, 0xcccccc, 0x555555, 0xff5555, 0x55ff55, 0xffff55, 0x5555ff, 0xff55ff, 0x55ffff, 0xffffff, 0x000000, 0xb3b3b3, 0x53ae71, 0x000000, 0x4d52f8, 0x000000}},
{"Whimsy", [22]uint32{0x535178, 0xef6487, 0x5eca89, 0xfdd877, 0x65aef7, 0xaa7ff0, 0x43c1be, 0xffffff, 0x535178, 0xef6487, 0x5eca89, 0xfdd877, 0x65aef7, 0xaa7ff0, 0x43c1be, 0xffffff, 0x29283b, 0xb3b0d6, 0xb3b0d6, 0x535178, 0x3d3c58, 0xffffff}},
{"Wild Cherry", [22]uint32{0x000507, 0xd94085, 0x2ab250, 0xffd16f, 0x883cdc, 0xececec, 0xc1b8b7, 0xfff8de, 0x009cc9, 0xda6bac, 0xf4dca5, 0xeac066, 0x308cba, 0xae636b, 0xff919d, 0xe4838d, 0x1f1726, 0xdafaff, 0xdd00ff, 0xff7fff, 0x002831, 0xe4ffff}},
{"Wilmersdorf", [22]uint32{0x34373e, 0xe06383, 0x7ebebd, 0xcccccc, 0xa6c1e0, 0xe1c1ee, 0x5b94ab, 0xababab, 0x50545d, 0xfa7193, 0x8fd7d6, 0xd1dfff, 0xb2cff0, 0xefccfd, 0x69abc5, 0xd3d3d3, 0x282b33, 0xc6c6c6, 0x7ebebd, 0x1f2024, 0x1f2024, 0xc6c6c6}},
{"Wombat", [22]uint32{0x000000, 0xff615a, 0xb1e969, 0xebd99c, 0x5da9f6, 0xe86aff, 0x82fff7, 0xdedacf, 0x4a4a4a, 0xf58c80, 0xddf88f, 0xeee5b2, 0xa5c7ff, 0xddaaff, 0xb7fff9, 0xffffff, 0x171717, 0xdedacf, 0xbbbbbb, 0xffffff, 0x453b39, 0xb6bbc0}},
{"Wryan", [22]uint32{0x333333, 0x8c4665, 0x287373, 0x7c7c99, 0x395573, 0x5e468c, 0x31658c, 0x899ca1, 0x3d3d3d, 0xbf4d80, 0x53a6a6, 0x9e9ecb, 0x477ab3, 0x7e62b3, 0x6096bf, 0xc0c0c0, 0x101010, 0x999993, 0x9e9ecb, 0x000000, 0x4d4d4d, 0xffffff}},
{"Xcode Dark", [22]uint32{0x414453, 0xff8170, 0x78c2b3, 0xd9c97c, 0x4eb0cc, 0xff7ab2, 0xb281eb, 0xdfdfe0, 0x7f8c98, 0xff8170, 0xacf2e4, 0xffa14f, 0x6bdfff, 0xff7ab2, 0xdabaff, 0xdfdfe0, 0x292a30, 0xdfdfe0, 0xdfdfe0, 0x292a30, 0x414453, 0xdfdfe0}},
{"Xcode Dark hc", [22]uint32{0x43454b, 0xff8a7a, 0x83c9bc, 0xd9c668, 0x4ec4e6, 0xff85b8, 0xcda1ff, 0xffffff, 0x838991, 0xff8a7a, 0xb1faeb, 0xffa14f, 0x6bdfff, 0xff85b8, 0xe5cfff, 0xffffff, 0x1f1f24, 0xffffff, 0xffffff, 0x1f1f24, 0x43454b, 0xffffff}},
{"Xcode Light", [22]uint32{0xb4d8fd, 0xd12f1b, 0x3e8087, 0x78492a, 0x0f68a0, 0xad3da4, 0x804fb8, 0x262626, 0x8a99a6, 0xd12f1b, 0x23575c, 0x78492a, 0x0b4f79, 0xad3da4, 0x4b21b0, 0x262626, 0xffffff, 0x262626, 0x262626, 0xffffff, 0xb4d8fd, 0x262626}},
{"Xcode Light hc", [22]uint32{0xb4d8fd, 0xad1805, 0x355d61, 0x78492a, 0x0058a1, 0x9c2191, 0x703daa, 0x000000, 0x8a99a6, 0xad1805, 0x174145, 0x78492a, 0x003f73, 0x9c2191, 0x441ea1, 0x000000, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xb4d8fd, 0x000000}},
{"Xcode WWDC", [22]uint32{0x494d5c, 0xbb383a, 0x94c66e, 0xd28e5d, 0x8884c5, 0xb73999, 0x00aba4, 0xe7e8eb, 0x7f869e, 0xbb383a, 0x94c66e, 0xd28e5d, 0x8884c5, 0xb73999, 0x00aba4, 0xe7e8eb, 0x292c36, 0xe7e8eb, 0xe7e8eb, 0x292c36, 0x494d5c, 0xe7e8eb}},
{"Y2K Chrome", [22]uint32{0x383f4f, 0xdc2626, 0x15803d, 0x0891b2, 0xf97316, 0x7c3aed, 0x2563eb, 0x475569, 0xa3b1c4, 0xb01e1e, 0x116631, 0x077792, 0xc75c12, 0x632ebe, 0x1e4fbc, 0x0f172a, 0xf1f5f9, 0x0f172a, 0x0f172a, 0xf1f5f9, 0x0f172a, 0xf1f5f9}},
{"Zenbones", [22]uint32{0xf0edec, 0xa8334c, 0x4f6c31, 0x944927, 0x286486, 0x88507d, 0x3b8992, 0x2c363c, 0xb5a7a0, 0x94253e, 0x3f5a22, 0x803d1c, 0x1d5573, 0x7b3b70, 0x2b747c, 0x4f5e68, 0xf0edec, 0x2c363c, 0x2c363c, 0xf0edec, 0xcbd9e3, 0x2c363c}},
{"Zenbones Dark", [22]uint32{0x1c1917, 0xde6e7c, 0x819b69, 0xb77e64, 0x6099c0, 0xb279a7, 0x66a5ad, 0xb4bdc3, 0x4d4540, 0xe8838f, 0x8bae68, 0xd68c67, 0x61abda, 0xcf86c1, 0x65b8c1, 0x888f94, 0x1c1917, 0xb4bdc3, 0xc4cacf, 0x1c1917, 0x3d4042, 0xb4bdc3}},
{"Zenbones Light", [22]uint32{0xf0edec, 0xa8334c, 0x4f6c31, 0x944927, 0x286486, 0x88507d, 0x3b8992, 0x2c363c, 0xb5a7a0, 0x94253e, 0x3f5a22, 0x803d1c, 0x1d5573, 0x7b3b70, 0x2b747c, 0x4f5e68, 0xf0edec, 0x2c363c, 0x2c363c, 0xf0edec, 0xcbd9e3, 0x2c363c}},
{"Zenburn", [22]uint32{0x4d4d4d, 0x7d5d5d, 0x60b48a, 0xf0dfaf, 0x5d6d7d, 0xdc8cc3, 0x8cd0d3, 0xdcdccc, 0x709080, 0xdca3a3, 0xc3bf9f, 0xe0cf9f, 0x94bff3, 0xec93d3, 0x93e0e3, 0xffffff, 0x3f3f3f, 0xdcdccc, 0x73635a, 0x000000, 0x21322f, 0xc2d87a}},
{"Zenburned", [22]uint32{0x404040, 0xe3716e, 0x819b69, 0xb77e64, 0x6099c0, 0xb279a7, 0x66a5ad, 0xf0e4cf, 0x6f6768, 0xec8685, 0x8bae68, 0xd68c67, 0x61abda, 0xcf86c1, 0x65b8c1, 0xc0ab86, 0x404040, 0xf0e4cf, 0xf3eadb, 0x404040, 0x746956, 0xf0e4cf}},
{"Zenwritten Dark", [22]uint32{0x191919, 0xde6e7c, 0x819b69, 0xb77e64, 0x6099c0, 0xb279a7, 0x66a5ad, 0xbbbbbb, 0x4a4546, 0xe8838f, 0x8bae68, 0xd68c67, 0x61abda, 0xcf86c1, 0x65b8c1, 0x8e8e8e, 0x191919, 0xbbbbbb, 0xc9c9c9, 0x191919, 0x404040, 0xbbbbbb}},
{"Zenwritten Light", [22]uint32{0xeeeeee, 0xa8334c, 0x4f6c31, 0x944927, 0x286486, 0x88507d, 0x3b8992, 0x353535, 0xaca9a9, 0x94253e, 0x3f5a22, 0x803d1c, 0x1d5573, 0x7b3b70, 0x2b747c, 0x5c5c5c, 0xeeeeee, 0x353535, 0x353535, 0xeeeeee, 0xd7d7d7, 0x353535}},
{"base16-icy", [22]uint32{0x021012, 0x16c2d9, 0x4dd0e1, 0x80deea, 0x00bcd4, 0x00adc1, 0x26c6d6, 0x095b67, 0x1e484e, 0xb3ebf2, 0x4dd0e1, 0x80deea, 0x00bcd4, 0x00adc1, 0x26c6d6, 0x0c7c7c, 0x021012, 0x095b67, 0x16c2d9, 0x021012, 0x041f23, 0x425052}},
{"branch", [22]uint32{0x35241c, 0xc2562d, 0x96a65e, 0xd29b5a, 0x3b8e8c, 0xc47e5b, 0x639a90, 0xcfc1a9, 0x564a45, 0xc2562d, 0x96a65e, 0xd29b5a, 0x3b8e8c, 0xc47e5b, 0x639a90, 0xcfc1a9, 0x32221a, 0xcfc1a9, 0xcfc1a9, 0x32221a, 0xcfc1a9, 0x32221a}},
{"cyberpunk-icy", [22]uint32{0x1a1a2e, 0xff0055, 0x00ff9f, 0xfffc00, 0x7b2fff, 0xff00ff, 0x00ffff, 0xd4b3f7, 0x444468, 0xff3377, 0x33ffb2, 0xfffe33, 0x9955ff, 0xff55ff, 0x55ffff, 0xffffff, 0x0a0a0f, 0xd4b3f7, 0x00ffff, 0x0a0a0f, 0x004d4d, 0x0a0a0f}},
{"datum (dark)", [22]uint32{0x2b2f35, 0xfe9864, 0x54dcaa, 0xe8df69, 0x69b9f7, 0xfa94cd, 0x6ae5ec, 0xdbe0e8, 0x8f98a3, 0xf8bd5f, 0x54dcaa, 0xfcdcad, 0xb2dafb, 0xf5b9d9, 0xa5f5f9, 0xeef2f7, 0x0f1318, 0xdbe0e8, 0xfa94cd, 0x0f1318, 0x2b2f35, 0xdbe0e8}},
{"datum (light)", [22]uint32{0x292e35, 0xa24500, 0x007553, 0x656023, 0x0176b8, 0x973070, 0x0d7a7f, 0xb4b9bf, 0x616a76, 0x976700, 0x007553, 0x4d3919, 0x2f516c, 0x633750, 0x154b4e, 0xe7ecf2, 0xf1f6fd, 0x292e35, 0x973070, 0xf1f6fd, 0xced3d9, 0x292e35}},
{"hazyland", [22]uint32{0x7b7080, 0xff8fc4, 0xb2ffe3, 0xf6e6a8, 0x96ccff, 0xb4b7f2, 0x8ff7f0, 0xeee4ff, 0x7b7080, 0xff8fc4, 0xb2ffe3, 0xf6e6a8, 0x96ccff, 0xb4b7f2, 0x8ff7f0, 0xeee4ff, 0x171219, 0xeee4ff, 0xff8fc4, 0x171219, 0x0d2847, 0xeee4ff}},
{"iTerm2 Dark Background", [22]uint32{0x000000, 0xc91b00, 0x00c200, 0xc7c400, 0x0225c7, 0xca30c7, 0x00c5c7, 0xc7c7c7, 0x686868, 0xff6e67, 0x5ffa68, 0xfffc67, 0x6871ff, 0xff77ff, 0x60fdff, 0xffffff, 0x000000, 0xc7c7c7, 0xc7c7c7, 0x8c8c8c, 0xc1deff, 0x000000}},
{"iTerm2 Default", [22]uint32{0x000000, 0xc91b00, 0x00c200, 0xc7c400, 0x2225c4, 0xca30c7, 0x00c5c7, 0xffffff, 0x686868, 0xff6e67, 0x5ffa68, 0xfffc67, 0x6871ff, 0xff77ff, 0x60fdff, 0xffffff, 0x000000, 0xffffff, 0xe5e5e5, 0x000000, 0xc1deff, 0x000000}},
{"iTerm2 Light Background", [22]uint32{0x000000, 0xc91b00, 0x00c200, 0xc7c400, 0x0225c7, 0xca30c7, 0x00c5c7, 0xbababa, 0x686868, 0xff6e67, 0x39d442, 0xccc934, 0x6871ff, 0xff77ff, 0x3ad7d9, 0xffffff, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xc1deff, 0x000000}},
{"iTerm2 Pastel Dark Background", [22]uint32{0x626262, 0xff8373, 0xb4fb73, 0xfffdc3, 0xa5d5fe, 0xff90fe, 0xd1d1fe, 0xf1f1f1, 0x8f8f8f, 0xffc4be, 0xd6fcba, 0xfffed5, 0xc2e3ff, 0xffb2fe, 0xe6e6fe, 0xffffff, 0x000000, 0xc7c7c7, 0xffb473, 0x8c8c8c, 0x454d96, 0xf4f4f4}},
{"iTerm2 Smoooooth", [22]uint32{0x14191e, 0xb43c2a, 0x00c200, 0xc7c400, 0x2744c7, 0xc040be, 0x00c5c7, 0xc7c7c7, 0x686868, 0xdd7975, 0x58e790, 0xece100, 0xa7abf2, 0xe17ee1, 0x60fdff, 0xffffff, 0x15191f, 0xdcdcdc, 0xffffff, 0x000000, 0xb3d7ff, 0x000000}},
{"iTerm2 Solarized Dark", [22]uint32{0x073642, 0xdc322f, 0x859900, 0xb58900, 0x268bd2, 0xd33682, 0x2aa198, 0xeee8d5, 0x335e69, 0xcb4b16, 0x586e75, 0x657b83, 0x839496, 0x6c71c4, 0x93a1a1, 0xfdf6e3, 0x002b36, 0x839496, 0x839496, 0x073642, 0x073642, 0x93a1a1}},
{"iTerm2 Solarized Light", [22]uint32{0x073642, 0xdc322f, 0x859900, 0xb58900, 0x268bd2, 0xd33682, 0x2aa198, 0xbbb5a2, 0x002b36, 0xcb4b16, 0x586e75, 0x657b83, 0x839496, 0x6c71c4, 0x93a1a1, 0xfdf6e3, 0xfdf6e3, 0x657b83, 0x657b83, 0xeee8d5, 0xeee8d5, 0x586e75}},
{"iTerm2 Tango Dark", [22]uint32{0x000000, 0xd81e00, 0x5ea702, 0xcfae00, 0x427ab3, 0x89658e, 0x00a7aa, 0xdbded8, 0x686a66, 0xf54235, 0x99e343, 0xfdeb61, 0x84b0d8, 0xbc94b7, 0x37e6e8, 0xf1f1f0, 0x000000, 0xffffff, 0xffffff, 0x000000, 0xc1deff, 0x000000}},
{"iTerm2 Tango Light", [22]uint32{0x000000, 0xd81e00, 0x5ea702, 0xcfae00, 0x427ab3, 0x89658e, 0x00a7aa, 0xc1c4be, 0x686a66, 0xf54235, 0x8cd636, 0xd7c53b, 0x84b0d8, 0xbc94b7, 0x1eccce, 0xf1f1f0, 0xffffff, 0x000000, 0x000000, 0xffffff, 0xc1deff, 0x000000}},
{"novmbr", [22]uint32{0x282a2e, 0x9f6434, 0x9dac5f, 0xcca75f, 0x2f7d7c, 0xb5896e, 0x52877f, 0xc7b8ac, 0x5d4e47, 0x9f6434, 0x9dac5f, 0xcca75f, 0x2f7d7c, 0xb5896e, 0x52877f, 0xc7b8ac, 0x241d1a, 0xc7b8ac, 0xc7b8ac, 0x241d1a, 0xc7b8ac, 0x241d1a}},
{"owl", [22]uint32{0x302c2c, 0x5a5a5a, 0x989898, 0xcacaca, 0x656565, 0xb1b1b1, 0x7f7f7f, 0xdedede, 0x5d595b, 0xda5b2c, 0x989898, 0xcacaca, 0x656565, 0xb1b1b1, 0x7f7f7f, 0xffffff, 0x2f2b2c, 0xdedede, 0xdedede, 0x2f2b2c, 0xdedede, 0x2f2b2c}},
{"traffic", [22]uint32{0x282d31, 0x934e46, 0x637268, 0xc79e84, 0x515e67, 0x715f5e, 0x5c6f7d, 0xcfb9a8, 0x4e575e, 0x934e46, 0x637270, 0xc79e84, 0x515e67, 0x715f5e, 0x5c6f7d, 0xddcec2, 0x272c30, 0xcfb9a8, 0xcfb9a8, 0x272c30, 0xcfb9a8, 0x272c30}},
{"urban", [22]uint32{0x33303b, 0x87404f, 0x74934e, 0xae835a, 0x615772, 0x854b64, 0x625464, 0xc0a79a, 0x5c5865, 0x87404f, 0x74934e, 0xae835a, 0x615772, 0x854b64, 0x625464, 0xc0a79a, 0x312e39, 0xc0a79a, 0xc0a79a, 0x312e39, 0xc0a79a, 0x312e39}},
}
+159
View File
@@ -0,0 +1,159 @@
package terminal
import (
"image"
"slices"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
"github.com/egoist/mygo/ui"
)
// Layers of images (Kitty graphics), as Ghostty draws them, by their z.
const (
belowBackground = iota // z below -2^30
belowText // negative z
aboveText
)
// shownImage is a placement of an image as the view draws it: the part of
// its bitmap, where it goes from the grid's origin in device pixels, and
// its layer.
type shownImage struct {
bmp *ui.Bitmap
src ui.Rect
x, y, w, h int
z int32
layer int
}
// cachedImage is an image's bitmap, as of its generation.
type cachedImage struct {
gen uint64
bmp *ui.Bitmap
seen bool
}
// readImages reads the placements that show, the virtual ones that
// placeholder cells may show, and the bitmaps of their images, which it
// keeps while placements show them; t.mu is held.
func (v *view) readImages(term *vt.Terminal) {
v.images = v.images[:0]
clear(v.virtual)
for _, c := range v.bitmaps {
c.seen = false
}
term.Placements(func(pl vt.Placement) {
if pl.Virtual {
bmp := v.bitmap(term, pl.ImageID)
if bmp == nil {
return
}
if v.virtual == nil {
v.virtual = map[uint32][]virtualImage{}
}
w, h := bmp.Size()
v.virtual[pl.ImageID] = append(v.virtual[pl.ImageID], virtualImage{
id: pl.ID, bmp: bmp, imgW: w, imgH: h,
cols: pl.ParamCols, rows: pl.ParamRows, layer: layerOf(pl.Z),
})
return
}
if !pl.Visible || pl.Width <= 0 || pl.Height <= 0 || pl.SrcW <= 0 || pl.SrcH <= 0 {
return
}
bmp := v.bitmap(term, pl.ImageID)
if bmp == nil {
return
}
v.images = append(v.images, shownImage{
bmp: bmp,
src: ui.Rect{X: float32(pl.SrcX), Y: float32(pl.SrcY), W: float32(pl.SrcW), H: float32(pl.SrcH)},
x: pl.Col*v.cellW + pl.XOffset, y: pl.Row*v.cellH + pl.YOffset, w: pl.Width, h: pl.Height,
z: pl.Z, layer: layerOf(pl.Z),
})
})
for id, c := range v.bitmaps {
if !c.seen {
delete(v.bitmaps, id)
}
}
slices.SortStableFunc(v.images, func(a, b shownImage) int { return int(a.z) - int(b.z) })
}
// bitmap returns the bitmap of an image, made again when its pixels
// change, nil while they have yet to arrive; it keeps it for this frame.
func (v *view) bitmap(term *vt.Terminal, id uint32) *ui.Bitmap {
gen := term.ImageGeneration(id)
if gen == 0 {
return nil
}
c := v.bitmaps[id]
if c == nil || c.gen != gen {
img, ok := term.Image(id)
if !ok {
return nil
}
if c == nil {
if v.bitmaps == nil {
v.bitmaps = map[uint32]*cachedImage{}
}
c = &cachedImage{}
v.bitmaps[id] = c
}
c.gen, c.bmp = gen, ui.NewBitmap(decoded(img))
}
c.seen = true
return c.bmp
}
// layerOf returns the layer of a placement's z.
func layerOf(z int32) int {
switch {
case z < -(1 << 30):
return belowBackground
case z < 0:
return belowText
}
return aboveText
}
// drawImages draws the images of a layer, within the grid.
func (v *view) drawImages(p *ui.Painter, layer int, ox, oy float32) {
s := v.scale
grid := ui.Rect{X: ox, Y: oy, W: float32(v.cols*v.cellW) / s, H: float32(v.rows*v.cellH) / s}
for _, im := range v.images {
if im.layer != layer {
continue
}
dst := ui.Rect{X: ox + float32(im.x)/s, Y: oy + float32(im.y)/s, W: float32(im.w) / s, H: float32(im.h) / s}
p.Clip(grid, 0, func() { p.ImageRegion(im.bmp, im.src, dst, ui.ImageOptions{}) })
}
v.drawHolders(p, layer, ox, oy, grid)
}
// decoded returns an image's pixels as an image.
func decoded(img vt.Image) *image.NRGBA {
w, h := img.Width, img.Height
out := image.NewNRGBA(image.Rect(0, 0, w, h))
px := img.Pixels
switch img.Format {
case vt.ImageRGBA:
copy(out.Pix, px)
case vt.ImageRGB:
for i := 0; i < w*h && 3*i+2 < len(px); i++ {
copy(out.Pix[4*i:], px[3*i:3*i+3])
out.Pix[4*i+3] = 0xff
}
case vt.ImageGrayAlpha:
for i := 0; i < w*h && 2*i+1 < len(px); i++ {
g := px[2*i]
out.Pix[4*i], out.Pix[4*i+1], out.Pix[4*i+2], out.Pix[4*i+3] = g, g, g, px[2*i+1]
}
case vt.ImageGray:
for i := 0; i < w*h && i < len(px); i++ {
g := px[i]
out.Pix[4*i], out.Pix[4*i+1], out.Pix[4*i+2], out.Pix[4*i+3] = g, g, g, 0xff
}
}
return out
}
+91
View File
@@ -0,0 +1,91 @@
package terminal
import (
"bytes"
"encoding/base64"
"fmt"
"image"
imagecolor "image/color"
"image/draw"
"image/png"
"testing"
"github.com/egoist/mygo/ui"
)
// kittyImage returns the Kitty graphics sequence that transmits and
// places a w×h image of one color, as RGBA, with more keys.
func kittyImage(id, w, h int, c ui.Color, keys string) string {
px := bytes.Repeat([]byte{c.R, c.G, c.B, 0xff}, w*h)
return fmt.Sprintf("\x1b_Ga=T,f=32,s=%d,v=%d,i=%d,q=2%s;%s\x1b\\", w, h, id, keys, base64.StdEncoding.EncodeToString(px))
}
// Images programs place (Kitty graphics) show where they placed them,
// over the text unless placed under it, and go when deleted: grok shows a
// pasted image's preview so.
func TestImages(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe(), Theme: LightTheme()})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 400, 200)
tt.Frame()
at := func(col, row int) ui.Color {
x, y := cellCenter(term, col, row)
c := tt.Image().RGBAAt(int(x*term.v.scale), int(y*term.v.scale))
return ui.RGB(c.R, c.G, c.B)
}
red, blue := ui.RGB(255, 0, 0), ui.RGB(0, 0, 255)
bg := LightTheme().Background
// Two cells by two of red at row 1, column 2; the cursor stays.
term.Feed([]byte("\x1b[2;3H" + kittyImage(7, 2*term.v.cellW, 2*term.v.cellH, red, ",C=1")))
tt.Frame()
for _, c := range []struct {
col, row int
want ui.Color
}{{2, 1, red}, {3, 2, red}, {4, 1, bg}, {2, 3, bg}} {
if got := at(c.col, c.row); got != c.want {
t.Errorf("cell %d,%d is %v, want %v", c.col, c.row, got, c.want)
}
}
// Under the cells' backgrounds, a cell with its own hides it.
term.Feed([]byte("\x1b[5;1H" + kittyImage(8, term.v.cellW, term.v.cellH, blue, ",z=-1073741825,C=1") + "\x1b[42m \x1b[0m"))
tt.Frame()
if got := at(0, 4); got == blue {
t.Errorf("an image under the backgrounds shows over a cell's own")
}
// Deleted, it goes.
term.Feed([]byte("\x1b_Ga=d,d=I,i=7,q=2\x1b\\"))
tt.Frame()
if got := at(2, 1); got != bg {
t.Errorf("a deleted image's cell is %v, want %v", got, bg)
}
}
// Images sent as PNG (f=100), as grok sends a pasted image's preview,
// decode and show.
func TestImagePNG(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe(), Theme: LightTheme()})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 400, 200)
tt.Frame()
src := image.NewNRGBA(image.Rect(0, 0, 3*term.v.cellW, 2*term.v.cellH))
draw.Draw(src, src.Bounds(), image.NewUniform(imagecolor.NRGBA{G: 255, A: 255}), image.Point{}, draw.Src)
var b bytes.Buffer
png.Encode(&b, src)
data := base64.StdEncoding.EncodeToString(b.Bytes())
// In chunks, as programs send big ones.
term.Feed([]byte("\x1b[2;2H\x1b_Ga=T,f=100,q=2,m=1;" + data[:40] + "\x1b\\\x1b_Gm=0;" + data[40:] + "\x1b\\"))
tt.Frame()
x, y := cellCenter(term, 2, 2)
c := tt.Image().RGBAAt(int(x*term.v.scale), int(y*term.v.scale))
if got := ui.RGB(c.R, c.G, c.B); got != ui.RGB(0, 255, 0) {
t.Errorf("the image's cell is %v, want green", got)
}
}
@@ -0,0 +1,206 @@
// Libbuild builds libghostty-vt for every platform MyGo supports from
// Ghostty's sources at a commit, with Zig (the version Ghostty asks for),
// and writes mygo-plugin.json, which names the files and their SHA-256 for
// the CLI and the terminal package, and ghostty_themes.go, the themes that
// Ghostty ships:
//
// go generate ./plugins/terminal
//
// With -themes, it only writes the themes, which needs no Zig.
//
// The files go into plugins/terminal/build, to publish as the assets of the
// release libghostty-vt-<commit>, which mygo-plugin.json points at:
//
// gh release create libghostty-vt-<commit> plugins/terminal/build/* --latest=false ...
//
// macOS's libraries are linked by Apple's linker when Xcode is installed,
// which the build of Ghostty prefers, so build them on a Mac.
package main
import (
"bytes"
"crypto/sha256"
"debug/elf"
"encoding/binary"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
// commit is the commit of Ghostty this package binds.
const commit = "befcdfd2c3a1cb24d9ec886e93c95b2b5daa7028"
var targets = []struct {
goos, goarch, zig string
// name is the file in apps; built is where Zig puts it.
name, built string
}{
{"darwin", "arm64", "aarch64-macos", "libghostty-vt.dylib", "lib/libghostty-vt.dylib"},
{"darwin", "amd64", "x86_64-macos", "libghostty-vt.dylib", "lib/libghostty-vt.dylib"},
// The glibc of Debian 10 and Ubuntu 20.04, and later.
{"linux", "amd64", "x86_64-linux-gnu.2.28", "libghostty-vt.so", "lib/libghostty-vt.so"},
{"linux", "arm64", "aarch64-linux-gnu.2.28", "libghostty-vt.so", "lib/libghostty-vt.so"},
{"windows", "amd64", "x86_64-windows-gnu", "ghostty-vt.dll", "bin/ghostty-vt.dll"},
{"windows", "arm64", "aarch64-windows-gnu", "ghostty-vt.dll", "bin/ghostty-vt.dll"},
}
func main() {
src := flag.String("src", "", "a checkout of Ghostty, at the commit (cloned into the user's cache when empty)")
out := flag.String("out", "build", "the directory of the libraries")
release := flag.String("release", "https://github.com/egoist/mygo/releases/download/libghostty-vt-"+commit[:12], "the URL of the release hosting the libraries")
themes := flag.Bool("themes", false, "only write the themes")
flag.Parse()
if *themes {
writeThemes(*src)
return
}
if *src == "" {
*src = checkout()
}
if err := os.MkdirAll(*out, 0o755); err != nil {
log.Fatal(err)
}
files := map[string]map[string]string{}
for _, t := range targets {
prefix, err := os.MkdirTemp("", "libghostty-vt-")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(prefix)
log.Printf("building %s/%s", t.goos, t.goarch)
run(*src, "zig", "build", "-Demit-lib-vt", "-Dtarget="+t.zig, "-Doptimize=ReleaseFast", "-Dstrip=true", "--prefix", prefix)
ext := filepath.Ext(t.name)
asset := fmt.Sprintf("libghostty-vt-%s-%s%s", t.goos, t.goarch, ext)
built := filepath.Join(prefix, t.built)
if t.goos == "linux" {
// The build keeps the debug information of ELF libraries,
// four fifths of them.
built = stripELF(built)
}
sum := copyFile(built, filepath.Join(*out, asset))
files[t.goos+"-"+t.goarch] = map[string]string{"name": t.name, "url": *release + "/" + asset, "sha256": sum}
}
manifest := map[string]any{"libraries": []any{map[string]any{
"name": "libghostty-vt",
"source": "https://github.com/ghostty-org/ghostty/tree/" + commit,
"files": files,
}}}
data, err := json.MarshalIndent(manifest, "", " ")
if err != nil {
log.Fatal(err)
}
if err := os.WriteFile("mygo-plugin.json", append(data, '\n'), 0o644); err != nil {
log.Fatal(err)
}
log.Printf("wrote mygo-plugin.json; publish %s as the assets of %s", *out, *release)
writeThemes(*src)
}
// checkout returns a checkout of Ghostty at the commit in the user's
// cache, cloning or fetching it.
func checkout() string {
cache, err := os.UserCacheDir()
if err != nil {
log.Fatal(err)
}
dir := filepath.Join(cache, "mygo", "ghostty-src")
if _, err := os.Stat(filepath.Join(dir, ".git")); err != nil {
run("", "git", "clone", "--filter=blob:none", "https://github.com/ghostty-org/ghostty", dir)
} else {
run(dir, "git", "fetch", "origin")
}
run(dir, "git", "checkout", "--detach", commit)
return dir
}
func run(dir, name string, args ...string) {
cmd := exec.Command(name, args...)
cmd.Dir = dir
cmd.Stdout, cmd.Stderr = os.Stderr, os.Stderr
if err := cmd.Run(); err != nil {
log.Fatalf("%s %s: %v", name, strings.Join(args, " "), err)
}
}
// copyFile copies src, following links, to dst and returns its SHA-256.
func copyFile(src, dst string) string {
in, err := os.Open(src)
if err != nil {
log.Fatal(err)
}
defer in.Close()
f, err := os.Create(dst)
if err != nil {
log.Fatal(err)
}
h := sha256.New()
if _, err := io.Copy(io.MultiWriter(f, h), in); err != nil {
log.Fatal(err)
}
if err := f.Close(); err != nil {
log.Fatal(err)
}
return hex.EncodeToString(h.Sum(nil))
}
// stripELF writes a copy of the ELF library at path without the contents
// of its debug sections, as `strip --strip-debug` would, and returns its
// path. What loading uses (the segments, and the sections in them) stays
// in place; the other sections after the segments move down, and the
// debug sections keep their headers, empty, so that no index changes.
func stripELF(path string) string {
data, err := os.ReadFile(path)
if err != nil {
log.Fatal(err)
}
f, err := elf.NewFile(bytes.NewReader(data))
if err != nil {
log.Fatal(err)
}
if f.Class != elf.ELFCLASS64 || f.Data != elf.ELFDATA2LSB {
log.Fatalf("%s: not a 64-bit little-endian ELF file", path)
}
end := uint64(0)
for _, p := range f.Progs {
end = max(end, p.Off+p.Filesz)
}
out := append([]byte(nil), data[:end]...)
le := binary.LittleEndian
shoff := le.Uint64(data[0x28:])
shentsize, shnum := uint64(le.Uint16(data[0x3a:])), uint64(le.Uint16(data[0x3c:]))
headers := append([]byte(nil), data[shoff:shoff+shentsize*shnum]...)
for i, s := range f.Sections {
h := headers[uint64(i)*shentsize:]
if s.Type == elf.SHT_NULL || s.Type == elf.SHT_NOBITS || s.Flags&elf.SHF_ALLOC != 0 || s.Offset < end {
continue
}
size := s.FileSize
if strings.HasPrefix(s.Name, ".debug") || strings.HasPrefix(s.Name, ".zdebug") {
size = 0
}
align := max(s.Addralign, 1)
for uint64(len(out))%align != 0 {
out = append(out, 0)
}
le.PutUint64(h[0x18:], uint64(len(out))) // sh_offset
le.PutUint64(h[0x20:], size) // sh_size
out = append(out, data[s.Offset:s.Offset+size]...)
}
for len(out)%8 != 0 {
out = append(out, 0)
}
le.PutUint64(out[0x28:], uint64(len(out))) // e_shoff
out = append(out, headers...)
stripped := path + ".stripped"
if err := os.WriteFile(stripped, out, 0o755); err != nil {
log.Fatal(err)
}
return stripped
}
@@ -0,0 +1,195 @@
package main
import (
"archive/tar"
"bufio"
"bytes"
"compress/gzip"
"fmt"
"go/format"
"io"
"log"
"net/http"
"os"
"path"
"path/filepath"
"regexp"
"slices"
"strconv"
"strings"
)
// themesFile is the Go file with the themes Ghostty ships.
const themesFile = "ghostty_themes.go"
// themeKeys are the keys of a theme of Ghostty's after its palette, in the
// order of ghosttyTheme's colors.
var themeKeys = []string{"background", "foreground", "cursor-color", "cursor-text", "selection-background", "selection-foreground"}
// themesLicense is the license of the themes, iTerm2-Color-Schemes'.
const themesLicense = `MIT License
Copyright (c) 2011 to Present Mark Badolato
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This license covers the iTerm-Color-Schemes repository collection of themes.
The copyright/license for each individual theme belongs to the author of that theme.`
// writeThemes writes the themes that the Ghostty at the commit ships, from
// the archive its build.zig.zon names, into themesFile: from the checkout
// src, else from GitHub.
func writeThemes(src string) {
var zon []byte
if src != "" {
var err error
if zon, err = os.ReadFile(filepath.Join(src, "build.zig.zon")); err != nil {
log.Fatal(err)
}
} else {
zon = fetch("https://raw.githubusercontent.com/ghostty-org/ghostty/" + commit + "/build.zig.zon")
}
m := regexp.MustCompile(`\.iterm2_themes\s*=\s*\.\{\s*\.url\s*=\s*"([^"]+)"`).FindSubmatch(zon)
if m == nil {
log.Fatal("build.zig.zon names no iterm2_themes")
}
url := string(m[1])
log.Printf("reading the themes of %s", url)
gz, err := gzip.NewReader(bytes.NewReader(fetch(url)))
if err != nil {
log.Fatal(err)
}
type theme struct {
name string
colors [22]uint32
}
var themes []theme
tr := tar.NewReader(gz)
for {
h, err := tr.Next()
if err == io.EOF {
break
} else if err != nil {
log.Fatal(err)
}
dir, name := path.Split(h.Name)
if h.Typeflag != tar.TypeReg || path.Clean(dir) != "ghostty" {
continue
}
data, err := io.ReadAll(tr)
if err != nil {
log.Fatal(err)
}
colors, err := parseTheme(data)
if err != nil {
log.Fatalf("theme %q: %v", name, err)
}
themes = append(themes, theme{name, colors})
}
if len(themes) == 0 {
log.Fatal("the archive has no themes")
}
slices.SortFunc(themes, func(a, b theme) int { return strings.Compare(a.name, b.name) })
var b bytes.Buffer
b.WriteString("// Code generated by go generate (internal/libbuild); DO NOT EDIT.\n\npackage terminal\n\n")
fmt.Fprintf(&b, "// ghosttyThemes are the themes the Ghostty this package binds ships, from\n// iTerm2-Color-Schemes (https://github.com/mbadolato/iTerm2-Color-Schemes),\n// as %s has them:\n//\n", path.Base(url))
for line := range strings.Lines(themesLicense) {
b.WriteString(strings.TrimRight("//\t"+line, " \t\n") + "\n")
}
b.WriteString("var ghosttyThemes = [...]ghosttyTheme{\n")
for _, t := range themes {
fmt.Fprintf(&b, "\t{%s, [22]uint32{", strconv.Quote(t.name))
for i, c := range t.colors {
if i > 0 {
b.WriteString(", ")
}
fmt.Fprintf(&b, "0x%06x", c)
}
b.WriteString("}},\n")
}
b.WriteString("}\n")
src2, err := format.Source(b.Bytes())
if err != nil {
log.Fatal(err)
}
if err := os.WriteFile(themesFile, src2, 0o644); err != nil {
log.Fatal(err)
}
log.Printf("wrote %d themes into %s", len(themes), themesFile)
}
// parseTheme reads the colors of a theme Ghostty ships, which sets each
// of them in #rrggbb: anything else is an error, for the terminal package
// to read it.
func parseTheme(data []byte) ([22]uint32, error) {
var colors [22]uint32
set := map[int]bool{}
sc := bufio.NewScanner(bytes.NewReader(data))
for sc.Scan() {
line := strings.TrimSpace(sc.Text())
if line == "" || line[0] == '#' {
continue
}
key, value, ok := strings.Cut(line, "=")
if !ok {
return colors, fmt.Errorf("%q sets nothing", line)
}
key, value = strings.TrimSpace(key), strings.TrimSpace(value)
i := slices.Index(themeKeys, key) + 16
if key == "palette" {
index, c, _ := strings.Cut(value, "=")
n, err := strconv.Atoi(strings.TrimSpace(index))
if err != nil || n < 0 || n > 255 {
return colors, fmt.Errorf("%q is no palette entry", value)
}
if n >= 16 {
continue
}
i, value = n, strings.TrimSpace(c)
} else if i < 16 {
return colors, fmt.Errorf("unknown key %q", key)
}
hex, ok := strings.CutPrefix(value, "#")
v, err := strconv.ParseUint(hex, 16, 32)
if !ok || len(hex) != 6 || err != nil {
return colors, fmt.Errorf("%s is %q, not #rrggbb", key, value)
}
colors[i], set[i] = uint32(v), true
}
if len(set) != len(colors) {
return colors, fmt.Errorf("sets %d colors of %d", len(set), len(colors))
}
return colors, sc.Err()
}
func fetch(url string) []byte {
res, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
log.Fatalf("%s: %s", url, res.Status)
}
data, err := io.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
return data
}
@@ -0,0 +1,123 @@
// Package library finds libghostty-vt for the terminal plugin: next to
// the app, in the user's cache, or downloaded there, as mygo-plugin.json
// names it.
package library
import (
"context"
"encoding/json/v2"
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"time"
"github.com/egoist/mygo"
fetch "github.com/egoist/mygo/internal/download"
)
// nativeLibraries is the format of mygo-plugin.json.
type nativeLibraries struct {
Libraries []struct {
Name string `json:"name"`
Files map[string]nativeFile `json:"files"`
} `json:"libraries"`
}
type nativeFile struct {
Name string `json:"name"`
URL string `json:"url"`
SHA256 string `json:"sha256"`
}
// library returns the build of libghostty-vt for this platform that the
// manifest names.
func library(manifest []byte) (nativeFile, error) {
var n nativeLibraries
if err := json.Unmarshal(manifest, &n); err != nil {
return nativeFile{}, err
}
target := runtime.GOOS + "-" + runtime.GOARCH
for _, l := range n.Libraries {
if f, ok := l.Files[target]; ok && l.Name == "libghostty-vt" {
return f, nil
}
}
return nativeFile{}, fmt.Errorf("terminal: libghostty-vt has no build for %s", target)
}
// Find returns the libghostty-vt that manifest names for this platform,
// the first of:
//
// - the file $MYGO_GHOSTTY_VT names;
// - the one among the app's resources (mygo.PathResources), where `mygo
// build` and `mygo dev` put it, signed with the app on macOS;
// - the one next to the executable;
// - the one in the user's cache, where the CLI downloads it
// (<cache>/mygo/natives/<sha256>/), which programs that are not
// packaged apps, as under `go run` and `go test`, download there when
// it is missing, checking its SHA-256.
//
// Packaged apps never download it: build them with the CLI.
func Find(manifest []byte) (string, error) {
if p := os.Getenv("MYGO_GHOSTTY_VT"); p != "" {
return p, nil
}
f, err := library(manifest)
if err != nil {
return "", err
}
var dirs []string
if dir, err := mygo.App.Path(mygo.PathResources); err == nil {
dirs = append(dirs, dir)
}
if exe, err := os.Executable(); err == nil {
dirs = append(dirs, filepath.Dir(exe))
}
cached, err := cachePath(f)
if err == nil {
dirs = append(dirs, filepath.Dir(cached))
}
for _, dir := range dirs {
p := filepath.Join(dir, f.Name)
if _, err := os.Stat(p); err == nil {
return p, nil
}
}
if mygo.App.IsPackaged() {
return "", fmt.Errorf("terminal: %s is missing from the app: build it with mygo build", f.Name)
}
if cached == "" {
return "", err
}
if err := download(f, cached); err != nil {
return "", err
}
return cached, nil
}
// cachePath returns where the CLI and this package keep a downloaded
// library.
func cachePath(f nativeFile) (string, error) {
dir, err := os.UserCacheDir()
if err != nil {
return "", err
}
return filepath.Join(dir, "mygo", "natives", f.SHA256, f.Name), nil
}
// download downloads f to path, checking its SHA-256, once among the
// processes that need it at the same time.
func download(f nativeFile, path string) error {
if f.URL == "" || f.SHA256 == "" {
return fmt.Errorf("terminal: no download of %s for %s/%s", f.Name, runtime.GOOS, runtime.GOARCH)
}
log.Printf("terminal: downloading %s into %s", f.URL, filepath.Dir(path))
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
if err := fetch.Cached(ctx, fetch.File{URL: f.URL, SHA256: f.SHA256}, path); err != nil {
return fmt.Errorf("terminal: downloading %s: %w", f.Name, err)
}
return nil
}
+63
View File
@@ -0,0 +1,63 @@
// Package pty runs processes in pseudo-terminals, in pure Go: /dev/ptmx on
// macOS and Linux, ConPTY on Windows.
package pty
import (
"errors"
"sync"
)
// Options describe a process to start in a pseudo-terminal.
type Options struct {
// Path is the program; Args its arguments, with Args[0] what the
// program sees as its name ("-zsh" starts a login shell).
Path string
Args []string
// Dir is the working directory, Env the environment ("KEY=value").
Dir string
Env []string
// Cols and Rows are the size of the terminal in cells, Width and
// Height in pixels.
Cols, Rows, Width, Height int
}
// ErrClosed is returned by Write after Close.
var ErrClosed = errors.New("pty: closed")
// PTY is a process running in a pseudo-terminal: Read returns its output,
// Write types into it.
type PTY struct {
sys
waitOnce sync.Once
code int
waitErr error
exited chan struct{}
}
// Start starts a process in a pseudo-terminal.
func Start(o Options) (*PTY, error) {
if o.Cols <= 0 || o.Rows <= 0 {
o.Cols, o.Rows = 80, 24
}
if len(o.Args) == 0 {
o.Args = []string{o.Path}
}
p := &PTY{exited: make(chan struct{})}
if err := p.start(o); err != nil {
return nil, err
}
go func() {
p.code, p.waitErr = p.wait()
close(p.exited)
}()
return p, nil
}
// Wait waits for the process to exit and returns its exit code.
func (p *PTY) Wait() (int, error) {
<-p.exited
return p.code, p.waitErr
}
// Exited is closed when the process exited.
func (p *PTY) Exited() <-chan struct{} { return p.exited }
@@ -0,0 +1,54 @@
//go:build !ios
package pty
import (
"bytes"
"fmt"
"os"
"syscall"
"unsafe"
)
// The ioctls of grantpt, unlockpt and ptsname on macOS (sys/ttycom.h).
const (
tiocptygrant = 0x20007454 // _IO('t', 84)
tiocptyunlk = 0x20007452 // _IO('t', 82)
tiocptygname = 0x40807453 // _IOC(IOC_OUT, 't', 83, 128)
)
func openMaster() (*os.File, string, error) {
master, err := os.OpenFile("/dev/ptmx", os.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
if err != nil {
return nil, "", fmt.Errorf("pty: %w", err)
}
var name [128]byte
for _, step := range []struct {
req uintptr
arg unsafe.Pointer
}{{tiocptygrant, nil}, {tiocptyunlk, nil}, {tiocptygname, unsafe.Pointer(&name[0])}} {
if err := ioctl(master, step.req, step.arg); err != nil {
master.Close()
return nil, "", fmt.Errorf("pty: %w", err)
}
}
n := bytes.IndexByte(name[:], 0)
if n < 0 {
n = len(name)
}
return master, string(name[:n]), nil
}
// waitReadable waits until the master has output, for a read that came back
// with EAGAIN because the os package could not make the descriptor one its
// poller waits on.
func (p *PTY) waitReadable() error {
fd := int(p.master.Fd())
var r syscall.FdSet
r.Bits[fd/32] |= 1 << (uint(fd) % 32)
for {
if err := syscall.Select(fd+1, &r, nil, nil, nil); err != syscall.EINTR {
return err
}
}
}
@@ -0,0 +1,43 @@
//go:build !android
package pty
import (
"fmt"
"os"
"strconv"
"syscall"
"unsafe"
)
func openMaster() (*os.File, string, error) {
master, err := os.OpenFile("/dev/ptmx", os.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
if err != nil {
return nil, "", fmt.Errorf("pty: %w", err)
}
var unlock int32
if err := ioctl(master, syscall.TIOCSPTLCK, unsafe.Pointer(&unlock)); err != nil {
master.Close()
return nil, "", fmt.Errorf("pty: unlocking: %w", err)
}
var n uint32
if err := ioctl(master, syscall.TIOCGPTN, unsafe.Pointer(&n)); err != nil {
master.Close()
return nil, "", fmt.Errorf("pty: %w", err)
}
return master, "/dev/pts/" + strconv.Itoa(int(n)), nil
}
// waitReadable waits until the master has output, for a read that came back
// with EAGAIN because the os package could not make the descriptor one its
// poller waits on.
func (p *PTY) waitReadable() error {
fd := int(p.master.Fd())
var r syscall.FdSet
r.Bits[fd/64] |= 1 << (uint(fd) % 64)
for {
if _, err := syscall.Select(fd+1, &r, nil, nil, nil); err != syscall.EINTR {
return err
}
}
}
@@ -0,0 +1,18 @@
//go:build !(darwin && !ios) && !(linux && !android) && !windows
package pty
import "errors"
type sys struct{}
func (p *PTY) start(Options) error { return errors.ErrUnsupported }
func (p *PTY) wait() (int, error) { return 0, errors.ErrUnsupported }
func (p *PTY) Read([]byte) (int, error) { return 0, errors.ErrUnsupported }
func (p *PTY) Write([]byte) (int, error) { return 0, errors.ErrUnsupported }
func (p *PTY) Resize(cols, rows, w, h int) error { return errors.ErrUnsupported }
func (p *PTY) ClearScreen() error { return nil }
func (p *PTY) Pid() int { return 0 }
func (p *PTY) Foreground() int { return 0 }
func (p *PTY) Close() error { return nil }
func (p *PTY) Kill() error { return errors.ErrUnsupported }
@@ -0,0 +1,110 @@
package pty
import (
"bytes"
"io"
"os"
"runtime"
"strings"
"testing"
"time"
"github.com/egoist/mygo/internal/wait"
)
// readAll reads the output of p until the process exits and the output
// ends.
func readAll(t *testing.T, p *PTY) string {
t.Helper()
var out bytes.Buffer
done := make(chan struct{})
go func() {
io.Copy(&out, p)
close(done)
}()
select {
case <-p.Exited():
case <-time.After(wait.Guard):
t.Fatal("the process did not exit")
}
// What the process wrote before it exited is still to read.
time.AfterFunc(200*time.Millisecond, func() { p.Close() })
<-done
return out.String()
}
func TestStart(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("uses sh")
}
p, err := Start(Options{Path: "/bin/sh", Args: []string{"sh", "-c", "echo hello; stty size; [ -t 0 ] && echo tty; exit 3"}, Cols: 100, Rows: 30, Env: []string{"TERM=dumb"}})
if err != nil {
t.Fatal(err)
}
out := readAll(t, p)
for _, want := range []string{"hello\r\n", "30 100\r\n", "tty\r\n"} {
if !strings.Contains(out, want) {
t.Errorf("output %q lacks %q", out, want)
}
}
if code, err := p.Wait(); code != 3 || err != nil {
t.Errorf("exit = %d, %v", code, err)
}
}
func TestResizeAndInput(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("uses sh")
}
p, err := Start(Options{Path: "/bin/sh", Args: []string{"sh", "-c", "read line; echo got $line; stty size"}, Env: []string{"TERM=dumb"}})
if err != nil {
t.Fatal(err)
}
if err := p.Resize(120, 40, 0, 0); err != nil {
t.Fatal(err)
}
if _, err := p.Write([]byte("typed\r")); err != nil {
t.Fatal(err)
}
out := readAll(t, p)
for _, want := range []string{"got typed\r\n", "40 120\r\n"} {
if !strings.Contains(out, want) {
t.Errorf("output %q lacks %q", out, want)
}
}
}
func TestClose(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("uses sh")
}
p, err := Start(Options{Path: "/bin/sh", Args: []string{"sh", "-c", "sleep 30"}})
if err != nil {
t.Fatal(err)
}
// Closing the terminal hangs up the process.
p.Close()
select {
case <-p.Exited():
case <-time.After(5 * time.Second):
p.Kill()
t.Fatal("the process outlived its terminal")
}
}
func TestConPTY(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("ConPTY")
}
cmd := os.Getenv("COMSPEC")
p, err := Start(Options{Path: cmd, Args: []string{"cmd", "/c", "echo hello& exit /b 3"}, Cols: 100, Rows: 30})
if err != nil {
t.Fatal(err)
}
if out := readAll(t, p); !strings.Contains(out, "hello") {
t.Errorf("output %q lacks hello", out)
}
if code, err := p.Wait(); code != 3 || err != nil {
t.Errorf("exit = %d, %v", code, err)
}
}
@@ -0,0 +1,158 @@
//go:build (darwin && !ios) || (linux && !android)
package pty
import (
"errors"
"fmt"
"io"
"os"
"os/exec"
"syscall"
"unsafe"
)
type sys struct {
master *os.File
cmd *exec.Cmd
}
func (p *PTY) start(o Options) error {
master, slaveName, err := openMaster()
if err != nil {
return err
}
slave, err := os.OpenFile(slaveName, os.O_RDWR|syscall.O_NOCTTY, 0)
if err != nil {
master.Close()
return fmt.Errorf("pty: opening %s: %w", slaveName, err)
}
defer slave.Close() // the child has its own copies
if err := setSize(master, o.Cols, o.Rows, o.Width, o.Height); err != nil {
master.Close()
return err
}
cmd := &exec.Cmd{Path: o.Path, Args: o.Args, Dir: o.Dir, Env: o.Env, Stdin: slave, Stdout: slave, Stderr: slave}
// A session of its own, whose controlling terminal is the slave (the
// child's descriptor 0), so that the terminal's signals reach the
// process group in the foreground.
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true, Setctty: true, Ctty: 0}
if err := cmd.Start(); err != nil {
master.Close()
return err
}
p.master, p.cmd = master, cmd
return nil
}
func (p *PTY) wait() (int, error) {
err := p.cmd.Wait()
if e, ok := errors.AsType[*exec.ExitError](err); ok {
if ws, ok := e.Sys().(syscall.WaitStatus); ok && ws.Signaled() {
return 128 + int(ws.Signal()), nil
}
return e.ExitCode(), nil
}
return 0, err
}
// Read reads the output of the process; it returns io.EOF once no process
// has the terminal open any more, or after Close.
func (p *PTY) Read(b []byte) (int, error) {
for {
n, err := p.master.Read(b)
if n > 0 {
return n, nil
}
if err == nil {
return 0, nil
}
// Nothing to read yet, which a read on a master that the os package
// cannot wait on says with EAGAIN: that is not the end of the
// program. A reader that takes it for the end closes the master,
// and the kernel then hangs the program up with SIGHUP, before it
// runs a single command.
if errors.Is(err, syscall.EAGAIN) || errors.Is(err, syscall.EINTR) {
if werr := p.waitReadable(); werr != nil {
return 0, werr
}
continue
}
// Linux reports EIO when the last process with the terminal
// open closes it.
if errors.Is(err, syscall.EIO) || errors.Is(err, os.ErrClosed) {
err = io.EOF
}
return 0, err
}
}
// Write types b into the terminal.
func (p *PTY) Write(b []byte) (int, error) {
n, err := p.master.Write(b)
if errors.Is(err, os.ErrClosed) {
err = ErrClosed
}
return n, err
}
// Resize sets the size of the terminal, which sends the process SIGWINCH.
func (p *PTY) Resize(cols, rows, width, height int) error {
return setSize(p.master, cols, rows, width, height)
}
// ClearScreen does nothing: the terminal has no screen of its own to
// clear, unlike ConPTY's console.
func (p *PTY) ClearScreen() error { return nil }
// Pid returns the process's ID.
func (p *PTY) Pid() int { return p.cmd.Process.Pid }
// Foreground returns the ID of the process group in the foreground of
// the terminal, 0 when it can't tell.
func (p *PTY) Foreground() int {
var pgrp int32
if ioctl(p.master, syscall.TIOCGPGRP, unsafe.Pointer(&pgrp)) != nil {
return 0
}
return int(pgrp)
}
// Close closes the terminal, which hangs up the processes that have it:
// they get SIGHUP. It does not wait for them to exit.
func (p *PTY) Close() error { return p.master.Close() }
// Kill kills the process and those of its process group, which it leads.
func (p *PTY) Kill() error {
if err := syscall.Kill(-p.cmd.Process.Pid, syscall.SIGKILL); err == nil {
return nil
}
return p.cmd.Process.Kill()
}
func setSize(f *os.File, cols, rows, width, height int) error {
ws := struct{ row, col, xpixel, ypixel uint16 }{clamp(rows), clamp(cols), clamp(width), clamp(height)}
return ioctl(f, syscall.TIOCSWINSZ, unsafe.Pointer(&ws))
}
func clamp(v int) uint16 { return uint16(max(0, min(v, 0xFFFF))) }
// ioctl calls ioctl on f with a pointer, which it converts in the system
// call, so that what it points to stays put meanwhile.
func ioctl(f *os.File, req uintptr, arg unsafe.Pointer) error {
c, err := f.SyscallConn()
if err != nil {
return err
}
var errno syscall.Errno
err = c.Control(func(fd uintptr) {
_, _, errno = syscall.Syscall(syscall.SYS_IOCTL, fd, req, uintptr(arg))
})
if err != nil {
return err
}
if errno != 0 {
return errno
}
return nil
}
@@ -0,0 +1,264 @@
package pty
import (
"errors"
"fmt"
"os"
"strings"
"sync"
"syscall"
"unicode/utf16"
"unsafe"
)
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll") // a KnownDLL
procCreatePseudoConsole = kernel32.NewProc("CreatePseudoConsole")
procResizePseudoConsole = kernel32.NewProc("ResizePseudoConsole")
procClosePseudoConsole = kernel32.NewProc("ClosePseudoConsole")
procInitializeProcThreadAttributeList = kernel32.NewProc("InitializeProcThreadAttributeList")
procUpdateProcThreadAttribute = kernel32.NewProc("UpdateProcThreadAttribute")
procDeleteProcThreadAttributeList = kernel32.NewProc("DeleteProcThreadAttributeList")
procRtlGetVersion = syscall.NewLazyDLL("ntdll.dll").NewProc("RtlGetVersion") // a KnownDLL
)
const (
procThreadAttributePseudoConsole = 0x00020016
extendedStartupInfoPresent = 0x00080000
createUnicodeEnvironment = 0x00000400
)
type startupInfoEx struct {
syscall.StartupInfo
attributes uintptr
}
type sys struct {
mu sync.Mutex
console uintptr // the HPCON, 0 once closed
in *os.File
out *os.File
process syscall.Handle
pid int
}
func (p *PTY) start(o Options) error {
if err := procCreatePseudoConsole.Find(); err != nil {
return errors.New("pty: ConPTY needs Windows 10 1809 or later")
}
// The console reads what is typed from inR and writes the output to
// outW; this side writes to inW and reads outR.
var inR, inW, outR, outW syscall.Handle
if err := syscall.CreatePipe(&inR, &inW, nil, 0); err != nil {
return fmt.Errorf("pty: %w", err)
}
if err := syscall.CreatePipe(&outR, &outW, nil, 0); err != nil {
syscall.CloseHandle(inR)
syscall.CloseHandle(inW)
return fmt.Errorf("pty: %w", err)
}
var console uintptr
r, _, _ := procCreatePseudoConsole.Call(coord(o.Cols, o.Rows), uintptr(inR), uintptr(outW), 0, uintptr(unsafe.Pointer(&console)))
// The console has its own copies of its ends.
syscall.CloseHandle(inR)
syscall.CloseHandle(outW)
if r != 0 {
syscall.CloseHandle(inW)
syscall.CloseHandle(outR)
return fmt.Errorf("pty: CreatePseudoConsole: %w", syscall.Errno(r&0xFFFF))
}
p.console = console
p.in, p.out = os.NewFile(uintptr(inW), "conpty-in"), os.NewFile(uintptr(outR), "conpty-out")
if err := p.spawn(o); err != nil {
p.Close()
p.out.Close()
return err
}
return nil
}
func (p *PTY) spawn(o Options) error {
var size uintptr
procInitializeProcThreadAttributeList.Call(0, 1, 0, uintptr(unsafe.Pointer(&size)))
list := make([]byte, size)
if r, _, err := procInitializeProcThreadAttributeList.Call(uintptr(unsafe.Pointer(&list[0])), 1, 0, uintptr(unsafe.Pointer(&size))); r == 0 {
return fmt.Errorf("pty: InitializeProcThreadAttributeList: %w", err)
}
defer procDeleteProcThreadAttributeList.Call(uintptr(unsafe.Pointer(&list[0])))
if r, _, err := procUpdateProcThreadAttribute.Call(uintptr(unsafe.Pointer(&list[0])), 0, procThreadAttributePseudoConsole, p.console, unsafe.Sizeof(p.console), 0, 0); r == 0 {
return fmt.Errorf("pty: UpdateProcThreadAttribute: %w", err)
}
si := startupInfoEx{attributes: uintptr(unsafe.Pointer(&list[0]))}
si.Cb = uint32(unsafe.Sizeof(si))
// The console's own standard handles: without invalid ones, a child of
// a process whose output is redirected would write there instead.
si.Flags = syscall.STARTF_USESTDHANDLES
si.StdInput, si.StdOutput, si.StdErr = syscall.InvalidHandle, syscall.InvalidHandle, syscall.InvalidHandle
cmdline, err := syscall.UTF16PtrFromString(commandLine(o.Path, o.Args))
if err != nil {
return err
}
var dir *uint16
if o.Dir != "" {
if dir, err = syscall.UTF16PtrFromString(o.Dir); err != nil {
return err
}
}
var env *uint16
if o.Env != nil {
block := environmentBlock(o.Env)
env = &block[0]
}
var pi syscall.ProcessInformation
err = syscall.CreateProcess(nil, cmdline, nil, nil, false, extendedStartupInfoPresent|createUnicodeEnvironment, env, dir, &si.StartupInfo, &pi)
if err != nil {
return fmt.Errorf("pty: starting %s: %w", o.Path, err)
}
syscall.CloseHandle(pi.Thread)
p.process, p.pid = pi.Process, int(pi.ProcessId)
return nil
}
func (p *PTY) wait() (int, error) {
if _, err := syscall.WaitForSingleObject(p.process, syscall.INFINITE); err != nil {
return 0, err
}
var code uint32
err := syscall.GetExitCodeProcess(p.process, &code)
syscall.CloseHandle(p.process)
return int(code), err
}
// Read reads the output of the process; it returns io.EOF after Close, once
// the console wrote what it had.
func (p *PTY) Read(b []byte) (int, error) { return p.out.Read(b) }
// Write types b into the terminal.
func (p *PTY) Write(b []byte) (int, error) {
n, err := p.in.Write(b)
if errors.Is(err, os.ErrClosed) {
err = ErrClosed
}
return n, err
}
// Resize sets the size of the terminal.
func (p *PTY) Resize(cols, rows, width, height int) error {
p.mu.Lock()
defer p.mu.Unlock()
if p.console == 0 {
return ErrClosed
}
if r, _, _ := procResizePseudoConsole.Call(p.console, coord(cols, rows)); r != 0 {
return fmt.Errorf("pty: ResizePseudoConsole: %w", syscall.Errno(r&0xFFFF))
}
return nil
}
// ClearScreen tells the console that the terminal cleared its screen, as
// Windows Terminal's ClearPseudoConsole does: the console clears its
// buffer and repaints with the cursor's line at the top. Without it, the
// console keeps the prompt on its old row and, as it redraws with
// absolute cursor moves (PSReadLine's predictions), takes the cursor back
// down there. It does nothing before Windows 11 24H2, whose console may
// shut down on a signal it doesn't know, or once the console is closed.
func (p *PTY) ClearScreen() error {
if windowsBuild() < 26100 {
return nil
}
p.mu.Lock()
defer p.mu.Unlock()
if p.console == 0 {
return nil
}
// kernel32 doesn't export ClearPseudoConsole. The HPCON points at the
// console's handles, first the pipe of its signals, which take a
// 16-bit code: PTY_SIGNAL_CLEAR_WINDOW is 2.
signals := **(**syscall.Handle)(unsafe.Pointer(&p.console))
var n uint32
if err := syscall.WriteFile(signals, []byte{2, 0}, &n, nil); err != nil {
return fmt.Errorf("pty: clearing the console: %w", err)
}
return nil
}
// windowsBuild returns the build of Windows 10 or 11, the maximum on a
// later major version. RtlGetVersion tells the version whatever the
// executable's manifest declares.
var windowsBuild = sync.OnceValue(func() uint32 {
var v struct {
size, major, minor, build, platform uint32
servicePack [128]uint16
}
v.size = uint32(unsafe.Sizeof(v))
procRtlGetVersion.Call(uintptr(unsafe.Pointer(&v)))
switch {
case v.major > 10:
return ^uint32(0)
case v.major < 10:
return 0
}
return v.build
})
// Pid returns the process's ID.
func (p *PTY) Pid() int { return p.pid }
// Foreground returns 0: a console has no process groups in its foreground.
func (p *PTY) Foreground() int { return 0 }
// Close closes the console, which ends the processes attached to it. Read
// returns io.EOF once it wrote what it had.
func (p *PTY) Close() error {
p.mu.Lock()
console := p.console
p.console = 0
p.mu.Unlock()
if console == 0 {
return nil
}
p.in.Close()
// ClosePseudoConsole waits for the output to be read on Windows
// before 11 24H2: Read keeps reading meanwhile, until the end of the
// output, then the pipe goes.
go func() {
procClosePseudoConsole.Call(console)
p.out.Close()
}()
return nil
}
// Kill kills the process.
func (p *PTY) Kill() error { return syscall.TerminateProcess(p.process, 1) }
// coord packs a COORD, which ConPTY takes by value.
func coord(cols, rows int) uintptr {
return uintptr(uint16(max(1, min(cols, 0x7FFF)))) | uintptr(uint16(max(1, min(rows, 0x7FFF))))<<16
}
// commandLine joins a program and its arguments as the C runtime splits
// them; args[0] is the program's name.
func commandLine(path string, args []string) string {
parts := []string{syscall.EscapeArg(path)}
if len(args) > 1 {
for _, a := range args[1:] {
parts = append(parts, syscall.EscapeArg(a))
}
}
return strings.Join(parts, " ")
}
// environmentBlock encodes env as CreateProcess takes it: NUL-terminated
// UTF-16 strings, then another NUL.
func environmentBlock(env []string) []uint16 {
var b []uint16
for _, kv := range env {
b = append(b, utf16.Encode([]rune(kv))...)
b = append(b, 0)
}
if len(b) == 0 {
b = append(b, 0)
}
return append(b, 0)
}
@@ -0,0 +1,76 @@
package pty
import (
"bytes"
"io"
"os/exec"
"regexp"
"strings"
"sync"
"testing"
"github.com/egoist/mygo/internal/wait"
)
// TestConPTYClearScreen clears the screen of PowerShell, whose prompt sat
// on the console's last row: the console repaints it on the first, which
// PSReadLine's redraws then keep to.
func TestConPTYClearScreen(t *testing.T) {
if windowsBuild() < 26100 {
t.Skip("ClearScreen needs Windows 11 24H2")
}
shell, err := exec.LookPath("pwsh")
if err != nil {
if shell, err = exec.LookPath("powershell"); err != nil {
t.Skip("no PowerShell")
}
}
p, err := Start(Options{Path: shell, Args: []string{"pwsh", "-NoLogo", "-NoProfile"}, Cols: 80, Rows: 10})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
p.Kill()
p.Close()
})
var mu sync.Mutex
var out bytes.Buffer
go io.Copy(writerFunc(func(b []byte) (int, error) {
mu.Lock()
defer mu.Unlock()
return out.Write(b)
}), p)
since := func(n int) string {
mu.Lock()
defer mu.Unlock()
return out.String()[n:]
}
length := func() int {
mu.Lock()
defer mu.Unlock()
return out.Len()
}
wait.Until(t, "the prompt", func() bool { return strings.Contains(since(0), "PS ") })
n := length()
if _, err := p.Write([]byte("1..20\r")); err != nil {
t.Fatal(err)
}
// The numbers, then the prompt again, on the last row.
wait.Until(t, "the numbers and the prompt", func() bool {
s := since(n)
i := strings.Index(s, "20")
return i >= 0 && strings.Contains(s[i:], "PS ")
})
n = length()
if err := p.ClearScreen(); err != nil {
t.Fatal(err)
}
top := regexp.MustCompile(`\x1b\[1;\d+H`)
wait.Until(t, "the prompt repainted on the first row", func() bool { return top.MatchString(since(n)) })
}
type writerFunc func([]byte) (int, error)
func (f writerFunc) Write(b []byte) (int, error) { return f(b) }
@@ -0,0 +1,185 @@
package vt
import (
"bytes"
"encoding/base64"
)
// ClipboardAnswer is how the ClipboardRead effect answers a program's
// read of the clipboard.
type ClipboardAnswer int
const (
// ClipboardRefused has the library refuse the read itself: an empty
// OSC 52 reply, an EPERM status for the Kitty protocol's OSC 5522,
// which the binding drops, as the read of a terminal that is not the
// one to answer. It is the zero value.
ClipboardRefused ClipboardAnswer = iota
// ClipboardAnswered answers the read with ClipboardReply.Contents
// now, which the library encodes as it returns.
ClipboardAnswered
// ClipboardDeferred holds the library's refusal back and answers the
// read later with Terminal.AnswerClipboard, which needs a
// ClipboardReply carrying a DeferredClipboardRead.
ClipboardDeferred
)
// DeferredClipboardRead is a read the embedder answers after its effect
// returned (ClipboardDeferred). The binding fills it as the library
// writes the refusal it holds back: kitty tells that the read came by
// the Kitty clipboard protocol (OSC 5522) rather than OSC 52; for OSC
// 52, prefix is the reply's beginning ("\x1b]52;" with the selector and
// its ";") and terminator how the request ended; refusal is what the
// library wrote to refuse the read (the empty OSC 52 reply, or the EPERM
// packet), which a denial writes again; mimes, list and primary are what
// the program asked for, and id is the id of a Kitty protocol read,
// echoed in its answer. Pass it to Terminal.AnswerClipboard.
type DeferredClipboardRead struct {
kitty bool
prefix, terminator, refusal []byte
mimes []string
list, primary bool
id string
}
// readChunkSize is how many raw bytes of one MIME type a Kitty protocol
// DATA packet carries.
const readChunkSize = 4096
// AnswerClipboard answers a read that the ClipboardRead effect deferred
// (ClipboardDeferred): allowed serves contents by MIME type, and
// available for the types listing (OSC 5522's "."), while denied writes
// the refusal the library wrote for the read and the binding held back.
// It is safe from any goroutine, and contents and available are not
// retained after it returns.
func (t *Terminal) AnswerClipboard(d *DeferredClipboardRead, allowed bool, contents map[string][]byte, available []string) {
if d == nil || t.effects.WritePTY == nil {
return
}
if !allowed {
t.effects.WritePTY(d.refusal)
return
}
if d.kitty {
t.effects.WritePTY(d.kittyAnswer(contents, available))
return
}
out := make([]byte, 0, len(d.prefix)+len(d.terminator)+16)
out = append(out, d.prefix...)
out = base64.StdEncoding.AppendEncode(out, contents["text/plain"])
out = append(out, d.terminator...)
t.effects.WritePTY(out)
}
// kittyAnswer encodes the read's answer as the library encodes one
// (ReadSuccess.encode in Ghostty's response.zig): an OK packet, the
// targets listing when asked for, the requested representations in
// request order as DATA packets, and DONE. The loc metadata is only on
// the OK packet, and no packet carries a password, as for a reply to a
// read.
func (d *DeferredClipboardRead) kittyAnswer(contents map[string][]byte, available []string) []byte {
out := make([]byte, 0, 64)
packet := func(out []byte, status string, loc bool) []byte {
out = append(out, "\x1b]5522;type=read:status="...)
out = append(out, status...)
if loc && d.primary {
out = append(out, ":loc=primary"...)
}
if d.id != "" {
out = append(out, ":id="...)
out = append(out, d.id...)
}
return out
}
out = packet(out, "OK", true)
out = append(out, d.terminator...)
if d.list {
out = packet(out, "DATA", false)
out = append(out, ":mime="...)
out = base64.StdEncoding.AppendEncode(out, []byte("."))
if len(available) > 0 {
// The types joined by spaces with a trailing newline, whole
// types only, as the library writes them.
var raw []byte
for i, mime := range available {
sep := 0
if i > 0 {
sep = 1
}
if len(raw)+sep+len(mime)+1 > readChunkSize {
break
}
if i > 0 {
raw = append(raw, ' ')
}
raw = append(raw, mime...)
}
raw = append(raw, '\n')
out = append(out, ';')
out = base64.StdEncoding.AppendEncode(out, raw)
}
out = append(out, d.terminator...)
}
for _, mime := range d.mimes {
data := contents[mime]
for i := 0; i < len(data); i += readChunkSize {
n := min(len(data)-i, readChunkSize)
out = packet(out, "DATA", false)
out = append(out, ":mime="...)
out = base64.StdEncoding.AppendEncode(out, []byte(mime))
out = append(out, ';')
out = base64.StdEncoding.AppendEncode(out, data[i:i+n])
out = append(out, d.terminator...)
}
}
out = packet(out, "DONE", false)
out = append(out, d.terminator...)
return out
}
// setRefusal parses the bytes the library wrote to refuse a deferred read
// and keeps them for a denial.
func (d *DeferredClipboardRead) setRefusal(p []byte) bool {
switch {
case bytes.HasPrefix(p, []byte("\x1b]52;")):
// p is "\x1b]52;<selector>;<terminator>": the payload is empty.
first := bytes.IndexByte(p, ';')
if first < 0 {
return false
}
second := bytes.IndexByte(p[first+1:], ';')
if second < 0 {
return false
}
second += first + 1
d.kitty = false
d.prefix = append([]byte(nil), p[:second+1]...)
d.terminator = append([]byte(nil), p[second+1:]...)
d.refusal = append([]byte(nil), p...)
return true
case bytes.HasPrefix(p, []byte("\x1b]5522;type=read:status=")):
d.kitty = true
d.refusal = append([]byte(nil), p...)
switch {
case bytes.HasSuffix(p, []byte("\x1b\\")):
d.terminator = append([]byte(nil), p[len(p)-2:]...)
case len(p) > 0 && p[len(p)-1] == '\x07':
d.terminator = append([]byte(nil), p[len(p)-1:]...)
default:
d.terminator = append([]byte(nil), "\x1b\\"...)
}
d.id = ""
if i := bytes.Index(p, []byte(":id=")); i >= 0 {
rest := p[i+len(":id="):]
if j := bytes.IndexAny(rest, ":\x1b\x07"); j >= 0 {
rest = rest[:j]
}
d.id = string(rest)
}
if bytes.Contains(p, []byte(":loc=primary")) {
d.primary = true
}
return true
}
return false
}
+369
View File
@@ -0,0 +1,369 @@
package vt
import (
"runtime"
"unsafe"
)
// Key is a GhosttyKey: a key by its place on the keyboard, as the W3C's
// KeyboardEvent.code names them.
type Key int32
// Keys, in the order of GhosttyKey.
const (
KeyUnidentified Key = iota
KeyBackquote
KeyBackslash
KeyBracketLeft
KeyBracketRight
KeyComma
KeyDigit0
KeyDigit1
KeyDigit2
KeyDigit3
KeyDigit4
KeyDigit5
KeyDigit6
KeyDigit7
KeyDigit8
KeyDigit9
KeyEqual
KeyIntlBackslash
KeyIntlRo
KeyIntlYen
KeyA
KeyB
KeyC
KeyD
KeyE
KeyF
KeyG
KeyH
KeyI
KeyJ
KeyK
KeyL
KeyM
KeyN
KeyO
KeyP
KeyQ
KeyR
KeyS
KeyT
KeyU
KeyV
KeyW
KeyX
KeyY
KeyZ
KeyMinus
KeyPeriod
KeyQuote
KeySemicolon
KeySlash
KeyAltLeft
KeyAltRight
KeyBackspace
KeyCapsLock
KeyContextMenu
KeyControlLeft
KeyControlRight
KeyEnter
KeyMetaLeft
KeyMetaRight
KeyShiftLeft
KeyShiftRight
KeySpace
KeyTab
KeyConvert
KeyKanaMode
KeyNonConvert
KeyDelete
KeyEnd
KeyHelp
KeyHome
KeyInsert
KeyPageDown
KeyPageUp
KeyArrowDown
KeyArrowLeft
KeyArrowRight
KeyArrowUp
)
// KeyEscape and the function keys follow the 41 keys of the numpad.
const (
KeyEscape Key = KeyArrowUp + 1 + 41 + iota
KeyF1
)
// Mods are modifier keys (GhosttyMods): Shift, Ctrl, Alt and Super, the
// same bits as MyGo's.
type Mods uint16
const (
ModShift Mods = 1 << iota
ModCtrl
ModAlt
ModSuper
)
// KeyAction is what happened to a key.
type KeyAction int32
const (
KeyRelease KeyAction = iota
KeyPress
KeyRepeat
)
// KeyEvent is a key to encode for the program.
type KeyEvent struct {
Action KeyAction
Key Key
Mods Mods
// Consumed are the modifiers that made Text, as Shift an "A".
Consumed Mods
// Text is what the key types, without what Ctrl or Alt change; empty
// for keys that type nothing.
Text string
// Unshifted is the character the key types without modifiers.
Unshifted rune
// Composing tells that an input method is composing.
Composing bool
}
// KeyEncoder encodes keys as the terminal's modes ask: legacy sequences,
// xterm's modifyOtherKeys or the Kitty keyboard protocol.
type KeyEncoder struct {
h, ev uintptr
buf [128]byte
}
// NewKeyEncoder makes a key encoder.
func NewKeyEncoder() (*KeyEncoder, error) {
e := &KeyEncoder{}
if err := result(call(fnKeyEncoderNew, 0, uintptr(unsafe.Pointer(&e.h)))); err != nil {
return nil, err
}
if err := result(call(fnKeyEventNew, 0, uintptr(unsafe.Pointer(&e.ev)))); err != nil {
e.Free()
return nil, err
}
return e, nil
}
// Free frees the encoder.
func (e *KeyEncoder) Free() {
if e.ev != 0 {
call(fnKeyEventFree, e.ev)
}
if e.h != 0 {
call(fnKeyEncoderFree, e.h)
}
*e = KeyEncoder{}
}
// Sync takes the terminal's modes, and whether Option is Alt on macOS.
func (e *KeyEncoder) Sync(t *Terminal, optionAsAlt bool) {
call(fnKeyEncoderSetoptFromTerminal, e.h, t.h)
v := int32(b2u(optionAsAlt))
call(fnKeyEncoderSetopt, e.h, 6, uintptr(unsafe.Pointer(&v)))
}
// Encode returns the bytes the program reads for k, valid until the next
// call; nil for keys that send nothing.
func (e *KeyEncoder) Encode(k KeyEvent) []byte {
call(fnKeyEventSetAction, e.ev, uintptr(k.Action))
call(fnKeyEventSetKey, e.ev, uintptr(k.Key))
call(fnKeyEventSetMods, e.ev, uintptr(k.Mods))
call(fnKeyEventSetConsumedMods, e.ev, uintptr(k.Consumed))
call(fnKeyEventSetComposing, e.ev, b2u(k.Composing))
call(fnKeyEventSetUnshifted, e.ev, uintptr(k.Unshifted))
// The event keeps the text's address until it is encoded.
var pin runtime.Pinner
defer pin.Unpin()
text := []byte(k.Text)
if len(text) > 0 {
pin.Pin(&text[0])
call(fnKeyEventSetUTF8, e.ev, uintptr(unsafe.Pointer(&text[0])), uintptr(len(text)))
} else {
call(fnKeyEventSetUTF8, e.ev, 0, 0)
}
var n uintptr
r := call(fnKeyEncoderEncode, e.h, e.ev, uintptr(unsafe.Pointer(&e.buf[0])), uintptr(len(e.buf)), uintptr(unsafe.Pointer(&n)))
if Result(int32(r)) == OutOfSpace && n > 0 {
big := make([]byte, n)
r = call(fnKeyEncoderEncode, e.h, e.ev, uintptr(unsafe.Pointer(&big[0])), n, uintptr(unsafe.Pointer(&n)))
call(fnKeyEventSetUTF8, e.ev, 0, 0)
if !ok(r) {
return nil
}
return big[:n]
}
call(fnKeyEventSetUTF8, e.ev, 0, 0)
if !ok(r) || n == 0 {
return nil
}
return e.buf[:n]
}
// MouseAction is what the pointer did.
type MouseAction int32
const (
MousePress MouseAction = iota
MouseRelease
MouseMotion
)
// Mouse buttons: 1 left, 2 right, 3 middle, 4 and 5 the wheel up and down,
// 6 and 7 left and right.
const (
ButtonNone = 0
ButtonLeft = 1
ButtonRight = 2
ButtonMiddle = 3
WheelUp = 4
WheelDown = 5
WheelLeft = 6
WheelRight = 7
)
// MouseEncoder encodes pointer events in the format and for the events
// the program asked for.
type MouseEncoder struct {
h, ev uintptr
buf [64]byte
}
// NewMouseEncoder makes a mouse encoder.
func NewMouseEncoder() (*MouseEncoder, error) {
m := &MouseEncoder{}
if err := result(call(fnMouseEncoderNew, 0, uintptr(unsafe.Pointer(&m.h)))); err != nil {
return nil, err
}
if err := result(call(fnMouseEventNew, 0, uintptr(unsafe.Pointer(&m.ev)))); err != nil {
m.Free()
return nil, err
}
// Motion is reported once per cell, as xterm does.
v := true
call(fnMouseEncoderSetopt, m.h, 4, uintptr(unsafe.Pointer(&v)))
return m, nil
}
// Free frees the encoder.
func (m *MouseEncoder) Free() {
if m.ev != 0 {
call(fnMouseEventFree, m.ev)
}
if m.h != 0 {
call(fnMouseEncoderFree, m.h)
}
*m = MouseEncoder{}
}
// Sync takes the terminal's mouse modes, the geometry of the screen in
// pixels, and whether a button is held.
func (m *MouseEncoder) Sync(t *Terminal, width, height, cellWidth, cellHeight, padLeft, padTop int, pressed bool) {
call(fnMouseEncoderSetoptFromTerminal, m.h, t.h)
s := mouseEncoderSize{
size: unsafe.Sizeof(mouseEncoderSize{}), screenWidth: uint32(max(width, 1)), screenHeight: uint32(max(height, 1)),
cellWidth: uint32(max(cellWidth, 1)), cellHeight: uint32(max(cellHeight, 1)),
paddingTop: uint32(max(padTop, 0)), paddingLeft: uint32(max(padLeft, 0)),
}
call(fnMouseEncoderSetopt, m.h, 2, uintptr(unsafe.Pointer(&s)))
call(fnMouseEncoderSetopt, m.h, 3, uintptr(unsafe.Pointer(&pressed)))
}
// Encode returns the bytes the program reads for a pointer event at x, y
// pixels, valid until the next call; nil when it asked for no such event.
func (m *MouseEncoder) Encode(action MouseAction, button int, mods Mods, x, y float32) []byte {
call(fnMouseEventSetAction, m.ev, uintptr(action))
if button == ButtonNone {
call(fnMouseEventClearButton, m.ev)
} else {
call(fnMouseEventSetButton, m.ev, uintptr(button))
}
call(fnMouseEventSetMods, m.ev, uintptr(mods))
mouseEventSetPosition(m.ev, mousePosition{x, y})
var n uintptr
if !ok(call(fnMouseEncoderEncode, m.h, m.ev, uintptr(unsafe.Pointer(&m.buf[0])), uintptr(len(m.buf)), uintptr(unsafe.Pointer(&n)))) || n == 0 {
return nil
}
return m.buf[:n]
}
// EncodeFocus returns the report of the terminal gaining or losing the
// focus (mode 1004).
func EncodeFocus(gained bool) []byte {
var buf [8]byte
var n uintptr
if !ok(call(fnFocusEncode, b2u(!gained), uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)), uintptr(unsafe.Pointer(&n)))) {
return nil
}
return buf[:n]
}
// EncodePaste returns text as the program reads a paste: bracketed (mode
// 2004), or with newlines as carriage returns, and without the control
// characters that could run commands.
func EncodePaste(text string, bracketed bool) []byte {
data := []byte(text)
if len(data) == 0 {
return nil
}
out := make([]byte, len(data)+16)
var n uintptr
r := call(fnPasteEncode, uintptr(unsafe.Pointer(&data[0])), uintptr(len(data)), b2u(bracketed), uintptr(unsafe.Pointer(&out[0])), uintptr(len(out)), uintptr(unsafe.Pointer(&n)))
if Result(int32(r)) == OutOfSpace && n > 0 {
data = []byte(text) // encoding may have changed it in place
out = make([]byte, n)
r = call(fnPasteEncode, uintptr(unsafe.Pointer(&data[0])), uintptr(len(data)), b2u(bracketed), uintptr(unsafe.Pointer(&out[0])), n, uintptr(unsafe.Pointer(&n)))
}
if !ok(r) {
return nil
}
return out[:n]
}
// PasteEvent tells the program what the clipboard offers a paste, by the
// MIME types, for it to read what it wants (mode 5522, the Kitty
// clipboard protocol); the program's reads come to Effects.ClipboardRead,
// granted. The event goes to the program through Effects.WritePTY. It
// reports whether the event was sent: it is not when the mode is not set
// or the terminal has no ClipboardRead, when the paste is the embedder's
// to encode (EncodePaste).
func (t *Terminal) PasteEvent(mimes []string) bool {
if !t.Mode(ModePasteEvents) || t.effects.ClipboardRead == nil {
return false
}
var keep [][]byte
cs := make([]cString, 0, len(mimes))
for _, m := range mimes {
cs = append(cs, cStringOf(m, &keep))
}
p := paste{size: unsafe.Sizeof(paste{}), source: 0 /* the clipboard */, mimesLen: uintptr(len(cs))}
if len(cs) > 0 {
p.mimes = uintptr(unsafe.Pointer(&cs[0]))
// The library asks a reader for data only when it pastes text
// itself, which it does not for an event; one is still required.
p.reader = mimeReader{read: cbNoRead}
}
var written bool
r := call(fnTerminalPaste, t.h, uintptr(unsafe.Pointer(&p)), uintptr(unsafe.Pointer(&written)))
runtime.KeepAlive(keep)
runtime.KeepAlive(cs)
return ok(r) && written
}
// PasteIsSafe reports whether pasting text cannot run a command by itself.
func PasteIsSafe(text string) bool {
if text == "" {
return true
}
b := []byte(text)
return cbool(call(fnPasteIsSafe, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b))))
}
+23
View File
@@ -0,0 +1,23 @@
//go:build (darwin && !ios) || (linux && !android && (amd64 || arm64)) || (windows && (amd64 || arm64))
package vt
import "github.com/ebitengine/purego"
// Supported reports whether the platform can load the library.
const Supported = true
// call calls a C function whose arguments are integers or pointers. Go
// pointers converted in the call, as in uintptr(unsafe.Pointer(&x)), are
// moved to the heap and kept alive until it returns (go:uintptrescapes):
// otherwise stack growth could move x while the library uses it.
//
//go:uintptrescapes
func call(fn uintptr, args ...uintptr) uintptr {
r, _, _ := purego.SyscallN(fn, args...)
return r
}
func registerFunc(fptr any, addr uintptr) { purego.RegisterFunc(fptr, addr) }
func newCallback(fn any) uintptr { return purego.NewCallback(fn) }
@@ -0,0 +1,18 @@
//go:build !(darwin && !ios) && !(linux && !android && (amd64 || arm64)) && !(windows && (amd64 || arm64))
package vt
import "errors"
// Supported reports whether the platform can load the library.
const Supported = false
func open(string) (uintptr, error) { return 0, errors.ErrUnsupported }
func sym(uintptr, string) (uintptr, error) { return 0, errors.ErrUnsupported }
func call(uintptr, ...uintptr) uintptr { panic("vt: libghostty-vt is not supported on this platform") }
func registerFunc(any, uintptr) {}
func newCallback(any) uintptr { return 0 }
+266
View File
@@ -0,0 +1,266 @@
package vt
import (
"bytes"
"image"
"image/draw"
"image/png"
"unsafe"
)
// Data of the Kitty graphics protocol's images (GhosttyKittyGraphicsData,
// GhosttyKittyGraphicsImageData, GhosttyKittyGraphicsPlacementData).
const (
dataKittyGraphics = 30
kittyPlacementIterator = 1
imageWidth = 3
imageHeight = 4
imageFormat = 5
imageData = 7
imageDataLen = 8
imageGeneration = 9
placementImageID = 1
placementID = 2
placementVirtual = 3
placementXOffset = 4
placementYOffset = 5
placementColumns = 10
placementRows = 11
placementZ = 12
placementSourceX = 6
placementSourceY = 7
placementSourceW = 8
placementSourceH = 9
)
// ImageFormat is how an image's pixels are laid out (GhosttyKittyImageFormat).
type ImageFormat int32
// Image formats: PNG is decoded to RGBA as an image arrives.
const (
ImageRGB ImageFormat = 0
ImageRGBA ImageFormat = 1
ImageGrayAlpha ImageFormat = 3
ImageGray ImageFormat = 4
)
// SetImageLimit sets how many bytes the images of the Kitty graphics
// protocol may take, zero refusing them (and deleting those there are).
func (t *Terminal) SetImageLimit(bytes uint64) {
t.set(optKittyImageLimit, unsafe.Pointer(&bytes))
}
// Image is an image of the Kitty graphics protocol.
type Image struct {
ID uint32
Width, Height int
Format ImageFormat
// Pixels are the image's, decoded; Generation changes when they do.
Pixels []byte
Generation uint64
}
// Placement is where a program placed an image (Kitty graphics), as the
// screen shows it now.
type Placement struct {
ImageID, ID uint32
// Virtual tells that the placement shows through the cells of Unicode
// placeholders rather than where it is placed.
Virtual bool
// Col and Row are its top left cell on the screen, Row negative when
// its top scrolled off; Visible tells that some of it shows.
Col, Row int
Visible bool
// XOffset and YOffset place it within its first cell, in pixels;
// Width and Height are the pixels it takes on the screen, Cols and Rows
// the cells.
XOffset, YOffset int
Width, Height int
Cols, Rows int
// SrcX, SrcY, SrcW and SrcH are the part of the image it shows, in the
// image's pixels.
SrcX, SrcY, SrcW, SrcH int
// Z orders it: below the cells' backgrounds when below -1<<30, below
// the text when negative, above it otherwise.
Z int32
// Params are the placement as a program asked for it: offsets, the
// part of the image and the cells, 0 for what the image gives.
ParamCols, ParamRows int
ParamSrcX, ParamSrcY, ParamSrcW, ParamSrcH int
}
// renderInfo is a GhosttyKittyGraphicsPlacementRenderInfo.
type renderInfo struct {
size uintptr
pixelWidth, pixelHeight, gridCols, gridRows uint32
viewportCol, viewportRow int32
viewportVisible bool
sourceX, sourceY, sourceW, sourceH uint32
}
// graphics returns the image storage of the screen that shows, 0 without
// one.
func (t *Terminal) graphics() uintptr {
var g uintptr
if t.get(dataKittyGraphics, unsafe.Pointer(&g)) != nil {
return 0
}
return g
}
// Placements calls fn with each placement of the screen that shows.
func (t *Terminal) Placements(fn func(Placement)) {
g := t.graphics()
if g == 0 {
return
}
var it uintptr
if !ok(call(fnPlacementIteratorNew, 0, uintptr(unsafe.Pointer(&it)))) || it == 0 {
return
}
defer call(fnPlacementIteratorFree, it)
if !ok(call(fnKittyGet, g, kittyPlacementIterator, uintptr(unsafe.Pointer(&it)))) {
return
}
u32 := func(data int) int {
var v uint32
call(fnPlacementGet, it, uintptr(data), uintptr(unsafe.Pointer(&v)))
return int(v)
}
for cbool(call(fnPlacementNext, it)) {
var p Placement
p.ImageID, p.ID = uint32(u32(placementImageID)), uint32(u32(placementID))
call(fnPlacementGet, it, placementVirtual, uintptr(unsafe.Pointer(&p.Virtual)))
call(fnPlacementGet, it, placementZ, uintptr(unsafe.Pointer(&p.Z)))
p.XOffset, p.YOffset = u32(placementXOffset), u32(placementYOffset)
p.ParamCols, p.ParamRows = u32(placementColumns), u32(placementRows)
p.ParamSrcX, p.ParamSrcY = u32(placementSourceX), u32(placementSourceY)
p.ParamSrcW, p.ParamSrcH = u32(placementSourceW), u32(placementSourceH)
img := call(fnKittyImage, g, uintptr(p.ImageID))
if img != 0 {
ri := renderInfo{size: unsafe.Sizeof(renderInfo{})}
if ok(call(fnPlacementRenderInfo, it, img, t.h, uintptr(unsafe.Pointer(&ri)))) {
p.Col, p.Row, p.Visible = int(ri.viewportCol), int(ri.viewportRow), ri.viewportVisible
p.Width, p.Height = int(ri.pixelWidth), int(ri.pixelHeight)
p.Cols, p.Rows = int(ri.gridCols), int(ri.gridRows)
p.SrcX, p.SrcY, p.SrcW, p.SrcH = int(ri.sourceX), int(ri.sourceY), int(ri.sourceW), int(ri.sourceH)
}
}
fn(p)
}
}
// ImageGeneration returns the generation of an image, 0 when there is no
// such image or its pixels have yet to arrive.
func (t *Terminal) ImageGeneration(id uint32) uint64 {
img := t.image(id)
if img == 0 {
return 0
}
var gen uint64
var p uintptr
if !ok(call(fnKittyImageGet, img, imageData, uintptr(unsafe.Pointer(&p)))) || p == 0 {
return 0
}
call(fnKittyImageGet, img, imageGeneration, uintptr(unsafe.Pointer(&gen)))
return gen
}
func (t *Terminal) image(id uint32) uintptr {
g := t.graphics()
if g == 0 {
return 0
}
return call(fnKittyImage, g, uintptr(id))
}
// Image returns an image, its pixels copied; false when there is no such
// image or its pixels have yet to arrive.
func (t *Terminal) Image(id uint32) (Image, bool) {
img := t.image(id)
if img == 0 {
return Image{}, false
}
var w, h uint32
var format int32
var p, n uintptr
var gen uint64
call(fnKittyImageGet, img, imageWidth, uintptr(unsafe.Pointer(&w)))
call(fnKittyImageGet, img, imageHeight, uintptr(unsafe.Pointer(&h)))
call(fnKittyImageGet, img, imageFormat, uintptr(unsafe.Pointer(&format)))
call(fnKittyImageGet, img, imageGeneration, uintptr(unsafe.Pointer(&gen)))
if !ok(call(fnKittyImageGet, img, imageData, uintptr(unsafe.Pointer(&p)))) || p == 0 {
return Image{}, false
}
call(fnKittyImageGet, img, imageDataLen, uintptr(unsafe.Pointer(&n)))
pixels := make([]byte, n)
copy(pixels, unsafe.Slice((*byte)(mem(p)), n))
return Image{ID: id, Width: int(w), Height: int(h), Format: ImageFormat(format), Pixels: pixels, Generation: gen}, true
}
// sysDecodePNG is GHOSTTY_SYS_OPT_DECODE_PNG.
const sysDecodePNG = 1
// sysImage is a GhosttySysImage: a PNG decoded, its pixels RGBA in memory
// of the library's allocator.
type sysImage struct {
width, height uint32
data, dataLen uintptr
}
// Ghostty's limits on an image, as Kitty's: no side longer than
// maxImageSide pixels, and no more than maxImageBytes of pixels.
const (
maxImageSide = 10000
maxImageBytes = 400 << 20
)
// imageFits reports whether an image of w×h RGBA pixels is within
// Ghostty's limits.
func imageFits(w, h int) bool {
return w > 0 && h > 0 && w <= maxImageSide && h <= maxImageSide && 4*w*h <= maxImageBytes
}
// decodePNG gives the library a PNG decoder, without which it refuses
// images sent as PNG (Kitty graphics, f=100), as grok sends them. A PNG
// whose header gives it more pixels than Ghostty's limits take is refused
// before it is decoded, as its size is the program's to claim; the pixels
// are converted into the library's memory, with no copy of them between.
func decodePNG() {
cb := newCallback(func(_, alloc, data, n, out uintptr) uintptr {
if data == 0 || n == 0 {
return 0
}
src := unsafe.Slice((*byte)(mem(data)), n)
cfg, err := png.DecodeConfig(bytes.NewReader(src))
if err != nil || !imageFits(cfg.Width, cfg.Height) {
return 0
}
img, err := png.Decode(bytes.NewReader(src))
if err != nil {
return 0
}
b := img.Bounds()
w, h := b.Dx(), b.Dy()
if !imageFits(w, h) {
return 0
}
size := uintptr(4 * w * h)
p := call(fnAlloc, alloc, size)
if p == 0 {
return 0
}
dst := &image.NRGBA{Pix: unsafe.Slice((*byte)(mem(p)), size), Stride: 4 * w, Rect: image.Rect(0, 0, w, h)}
if nrgba, ok := img.(*image.NRGBA); ok && nrgba.Stride == 4*w && b.Min == (image.Point{}) {
copy(dst.Pix, nrgba.Pix)
} else {
draw.Draw(dst, dst.Rect, img, b.Min, draw.Src)
}
*(*sysImage)(mem(out)) = sysImage{width: uint32(w), height: uint32(h), data: p, dataLen: size}
return 1
})
call(fnSysSet, sysDecodePNG, cb)
}
@@ -0,0 +1,133 @@
package vt
import (
"bytes"
"compress/zlib"
"encoding/base64"
"encoding/binary"
"fmt"
"hash/crc32"
"image"
"image/color"
"image/draw"
"image/png"
"runtime"
"testing"
)
// sendPNG transmits a PNG as an image of the Kitty graphics protocol
// (f=100), in chunks.
func sendPNG(term *Terminal, id int, data []byte) {
enc := base64.StdEncoding.EncodeToString(data)
var b bytes.Buffer
for i := 0; i == 0 || i < len(enc); i += 4096 {
more := 0
if i+4096 < len(enc) {
more = 1
}
part := enc[i:min(i+4096, len(enc))]
if i == 0 {
fmt.Fprintf(&b, "\x1b_Ga=t,f=100,i=%d,q=2,m=%d;%s\x1b\\", id, more, part)
} else {
fmt.Fprintf(&b, "\x1b_Gm=%d;%s\x1b\\", more, part)
}
}
term.Write(b.Bytes())
}
// pngClaiming returns a PNG whose header claims w×h gray pixels, with
// almost none of them.
func pngClaiming(w, h int) []byte {
var b bytes.Buffer
b.WriteString("\x89PNG\r\n\x1a\n")
chunk := func(typ string, data []byte) {
binary.Write(&b, binary.BigEndian, uint32(len(data)))
b.WriteString(typ)
b.Write(data)
binary.Write(&b, binary.BigEndian, crc32.ChecksumIEEE(append([]byte(typ), data...)))
}
ihdr := binary.BigEndian.AppendUint32(nil, uint32(w))
ihdr = binary.BigEndian.AppendUint32(ihdr, uint32(h))
chunk("IHDR", append(ihdr, 8, 0, 0, 0, 0)) // 8-bit gray
var z bytes.Buffer
zw := zlib.NewWriter(&z)
zw.Write(make([]byte, 64))
zw.Close()
chunk("IDAT", z.Bytes())
chunk("IEND", nil)
return b.Bytes()
}
// PNGs of every kind decode to RGBA, and one that claims more pixels than
// Ghostty takes is refused before it is decoded.
func TestPNGLimits(t *testing.T) {
loadLib(t)
term, err := NewTerminal(20, 5, Effects{})
if err != nil {
t.Fatal(err)
}
defer term.Free()
term.SetImageLimit(320 << 20)
r := image.Rect(0, 0, 3, 2)
nrgba := image.NewNRGBA(r)
rgb := image.NewRGBA(r)
gray := image.NewGray(r)
pal := image.NewPaletted(r, color.Palette{color.NRGBA{1, 2, 3, 255}, color.NRGBA{200, 100, 50, 128}})
deep := image.NewNRGBA64(r)
for y := range 2 {
for x := range 3 {
c := color.NRGBA{uint8(40 * x), uint8(90 * y), 77, uint8(100 + 50*x)}
nrgba.SetNRGBA(x, y, c)
rgb.Set(x, y, color.NRGBA{c.R, c.G, c.B, 255})
gray.SetGray(x, y, color.Gray{uint8(60*x + 30*y)})
pal.SetColorIndex(x, y, uint8((x+y)%2))
deep.Set(x, y, c)
}
}
for i, img := range []image.Image{nrgba, rgb, gray, pal, deep} {
var b bytes.Buffer
if err := png.Encode(&b, img); err != nil {
t.Fatal(err)
}
id := i + 1
sendPNG(term, id, b.Bytes())
got, ok := term.Image(uint32(id))
if !ok {
t.Errorf("image %d (%T) refused", id, img)
continue
}
want := image.NewNRGBA(r)
draw.Draw(want, r, img, image.Point{}, draw.Src)
if got.Format != ImageRGBA || got.Width != 3 || got.Height != 2 || !bytes.Equal(got.Pixels, want.Pix) {
t.Errorf("image %d (%T): format %d, %d×%d, pixels %v, want %v", id, img, got.Format, got.Width, got.Height, got.Pixels, want.Pix)
}
}
// Ghostty's limits: no side over 10000 pixels.
var b bytes.Buffer
png.Encode(&b, image.NewGray(image.Rect(0, 0, maxImageSide+1, 1)))
sendPNG(term, 10, b.Bytes())
if _, ok := term.Image(10); ok {
t.Error("an image 10001 pixels wide was taken")
}
b.Reset()
png.Encode(&b, image.NewGray(image.Rect(0, 0, maxImageSide, 1)))
sendPNG(term, 11, b.Bytes())
if _, ok := term.Image(11); !ok {
t.Error("an image 10000 pixels wide was refused")
}
// A header that claims 20000×20000 pixels, which decoding would
// allocate before reading them: refused with next to no memory.
var before, after runtime.MemStats
runtime.ReadMemStats(&before)
sendPNG(term, 12, pngClaiming(20000, 20000))
runtime.ReadMemStats(&after)
if _, ok := term.Image(12); ok {
t.Error("an image of 20000×20000 pixels was taken")
}
if n := after.TotalAlloc - before.TotalAlloc; n > 16<<20 {
t.Errorf("refusing it allocated %d MB", n>>20)
}
}
+456
View File
@@ -0,0 +1,456 @@
// Package vt binds libghostty-vt, the terminal emulator of Ghostty, which
// it loads at run time through purego: no cgo. It mirrors the structs of
// the C API it passes, checks them against the layouts the library
// describes (ghostty_type_json) as it loads, and reads packed cells by the
// bit positions the library reports, so that a library of another version
// fails to load instead of corrupting memory.
//
// Nothing here is safe for concurrent use: callers serialize the calls on a
// Terminal and on what is made from it.
package vt
import (
"encoding/json/v2"
"errors"
"fmt"
"sync"
"unsafe"
)
var lib struct {
mu sync.Mutex
loaded bool
err error
}
// Symbols called with integer and pointer arguments only, through call.
var (
fnTerminalNew, fnTerminalFree, fnTerminalReset, fnTerminalResize, fnTerminalSet, fnTerminalGet,
fnTerminalVTWrite, fnTerminalCompress, fnTerminalCompressionActivity uintptr
fnRenderStateNew, fnRenderStateFree, fnRenderStateBeginUpdate, fnRenderStateEndUpdate, fnRenderStateClean,
fnRenderStateGet, fnRowIteratorNew, fnRowIteratorFree, fnRowIteratorNext, fnRowGet,
fnRowCellsNew, fnRowCellsFree, fnRowCellsSelect, fnRowCellsGet uintptr
fnKeyEncoderNew, fnKeyEncoderFree, fnKeyEncoderSetopt, fnKeyEncoderSetoptFromTerminal, fnKeyEncoderEncode,
fnKeyEventNew, fnKeyEventFree, fnKeyEventSetAction, fnKeyEventSetKey, fnKeyEventSetMods,
fnKeyEventSetConsumedMods, fnKeyEventSetComposing, fnKeyEventSetUTF8, fnKeyEventSetUnshifted uintptr
fnMouseEncoderNew, fnMouseEncoderFree, fnMouseEncoderSetopt, fnMouseEncoderSetoptFromTerminal,
fnMouseEncoderReset, fnMouseEncoderEncode, fnMouseEventNew, fnMouseEventFree, fnMouseEventSetAction,
fnMouseEventSetButton, fnMouseEventClearButton, fnMouseEventSetMods uintptr
fnFocusEncode, fnPasteEncode, fnPasteIsSafe, fnTerminalPaste, fnFree uintptr
fnGestureNew, fnGestureFree, fnGestureReset, fnGestureGet, fnGestureEventNew, fnGestureEventFree,
fnGestureEventSet, fnGestureEvent, fnSelectAll uintptr
fnGridRefHyperlinkURI, fnGridRefGraphemes, fnGridRefCell, fnGridRefRow, fnRowData, fnTypeJSON, fnFormatterFormatAlloc, fnFormatterFree uintptr
fnSearchNew, fnSearchFree, fnSearchSet, fnSearchGet, fnSearchFeed, fnSearchTick, fnPointFromGridRef uintptr
fnKittyGet, fnKittyImage, fnKittyImageGet, fnPlacementIteratorNew, fnPlacementIteratorFree,
fnPlacementNext, fnPlacementGet, fnPlacementRenderInfo, fnSysSet, fnAlloc uintptr
// Bound with registerFunc below: they take structs or floats.
fnTerminalScrollViewport, fnTerminalGridRef, fnMouseEventSetPosition, fnSelectionFormatAlloc, fnFormatterTerminalNew uintptr
)
// Functions taking structs or floats by value, which purego passes as the
// platform's C ABI does.
var (
terminalScrollViewport func(t uintptr, v scrollViewport)
terminalGridRef func(t uintptr, p point, out *GridRef) int32
mouseEventSetPosition func(ev uintptr, pos mousePosition)
selectionFormatAlloc func(t uintptr, alloc uintptr, opts selectionFormatOptions, out *uintptr, n *uintptr) int32
formatterTerminalNew func(alloc uintptr, out *uintptr, t uintptr, opts formatterOptions) int32
)
var symbols = []struct {
name string
addr *uintptr
}{
{"ghostty_terminal_new", &fnTerminalNew},
{"ghostty_terminal_free", &fnTerminalFree},
{"ghostty_terminal_reset", &fnTerminalReset},
{"ghostty_terminal_resize", &fnTerminalResize},
{"ghostty_terminal_set", &fnTerminalSet},
{"ghostty_terminal_get", &fnTerminalGet},
{"ghostty_terminal_vt_write", &fnTerminalVTWrite},
{"ghostty_terminal_compress", &fnTerminalCompress},
{"ghostty_terminal_compression_activity", &fnTerminalCompressionActivity},
{"ghostty_terminal_scroll_viewport", &fnTerminalScrollViewport},
{"ghostty_terminal_grid_ref", &fnTerminalGridRef},
{"ghostty_render_state_new", &fnRenderStateNew},
{"ghostty_render_state_free", &fnRenderStateFree},
{"ghostty_render_state_begin_update", &fnRenderStateBeginUpdate},
{"ghostty_render_state_end_update", &fnRenderStateEndUpdate},
{"ghostty_render_state_clean", &fnRenderStateClean},
{"ghostty_render_state_get", &fnRenderStateGet},
{"ghostty_render_state_row_iterator_new", &fnRowIteratorNew},
{"ghostty_render_state_row_iterator_free", &fnRowIteratorFree},
{"ghostty_render_state_row_iterator_next", &fnRowIteratorNext},
{"ghostty_render_state_row_get", &fnRowGet},
{"ghostty_render_state_row_cells_new", &fnRowCellsNew},
{"ghostty_render_state_row_cells_free", &fnRowCellsFree},
{"ghostty_render_state_row_cells_select", &fnRowCellsSelect},
{"ghostty_render_state_row_cells_get", &fnRowCellsGet},
{"ghostty_key_encoder_new", &fnKeyEncoderNew},
{"ghostty_key_encoder_free", &fnKeyEncoderFree},
{"ghostty_key_encoder_setopt", &fnKeyEncoderSetopt},
{"ghostty_key_encoder_setopt_from_terminal", &fnKeyEncoderSetoptFromTerminal},
{"ghostty_key_encoder_encode", &fnKeyEncoderEncode},
{"ghostty_key_event_new", &fnKeyEventNew},
{"ghostty_key_event_free", &fnKeyEventFree},
{"ghostty_key_event_set_action", &fnKeyEventSetAction},
{"ghostty_key_event_set_key", &fnKeyEventSetKey},
{"ghostty_key_event_set_mods", &fnKeyEventSetMods},
{"ghostty_key_event_set_consumed_mods", &fnKeyEventSetConsumedMods},
{"ghostty_key_event_set_composing", &fnKeyEventSetComposing},
{"ghostty_key_event_set_utf8", &fnKeyEventSetUTF8},
{"ghostty_key_event_set_unshifted_codepoint", &fnKeyEventSetUnshifted},
{"ghostty_mouse_encoder_new", &fnMouseEncoderNew},
{"ghostty_mouse_encoder_free", &fnMouseEncoderFree},
{"ghostty_mouse_encoder_setopt", &fnMouseEncoderSetopt},
{"ghostty_mouse_encoder_setopt_from_terminal", &fnMouseEncoderSetoptFromTerminal},
{"ghostty_mouse_encoder_reset", &fnMouseEncoderReset},
{"ghostty_mouse_encoder_encode", &fnMouseEncoderEncode},
{"ghostty_mouse_event_new", &fnMouseEventNew},
{"ghostty_mouse_event_free", &fnMouseEventFree},
{"ghostty_mouse_event_set_action", &fnMouseEventSetAction},
{"ghostty_mouse_event_set_button", &fnMouseEventSetButton},
{"ghostty_mouse_event_clear_button", &fnMouseEventClearButton},
{"ghostty_mouse_event_set_mods", &fnMouseEventSetMods},
{"ghostty_mouse_event_set_position", &fnMouseEventSetPosition},
{"ghostty_focus_encode", &fnFocusEncode},
{"ghostty_paste_encode", &fnPasteEncode},
{"ghostty_terminal_paste", &fnTerminalPaste},
{"ghostty_paste_is_safe", &fnPasteIsSafe},
{"ghostty_free", &fnFree},
{"ghostty_selection_gesture_new", &fnGestureNew},
{"ghostty_selection_gesture_free", &fnGestureFree},
{"ghostty_selection_gesture_reset", &fnGestureReset},
{"ghostty_selection_gesture_get", &fnGestureGet},
{"ghostty_kitty_graphics_get", &fnKittyGet},
{"ghostty_kitty_graphics_image", &fnKittyImage},
{"ghostty_kitty_graphics_image_get", &fnKittyImageGet},
{"ghostty_kitty_graphics_placement_iterator_new", &fnPlacementIteratorNew},
{"ghostty_kitty_graphics_placement_iterator_free", &fnPlacementIteratorFree},
{"ghostty_kitty_graphics_placement_next", &fnPlacementNext},
{"ghostty_kitty_graphics_placement_get", &fnPlacementGet},
{"ghostty_kitty_graphics_placement_render_info", &fnPlacementRenderInfo},
{"ghostty_sys_set", &fnSysSet},
{"ghostty_alloc", &fnAlloc},
{"ghostty_selection_gesture_event_new", &fnGestureEventNew},
{"ghostty_selection_gesture_event_free", &fnGestureEventFree},
{"ghostty_selection_gesture_event_set", &fnGestureEventSet},
{"ghostty_selection_gesture_event", &fnGestureEvent},
{"ghostty_terminal_select_all", &fnSelectAll},
{"ghostty_terminal_selection_format_alloc", &fnSelectionFormatAlloc},
{"ghostty_grid_ref_hyperlink_uri", &fnGridRefHyperlinkURI},
{"ghostty_grid_ref_graphemes", &fnGridRefGraphemes},
{"ghostty_grid_ref_cell", &fnGridRefCell},
{"ghostty_grid_ref_row", &fnGridRefRow},
{"ghostty_row_get", &fnRowData},
{"ghostty_type_json", &fnTypeJSON},
{"ghostty_formatter_terminal_new", &fnFormatterTerminalNew},
{"ghostty_formatter_format_alloc", &fnFormatterFormatAlloc},
{"ghostty_formatter_free", &fnFormatterFree},
{"ghostty_search_new", &fnSearchNew},
{"ghostty_search_free", &fnSearchFree},
{"ghostty_search_set", &fnSearchSet},
{"ghostty_search_get", &fnSearchGet},
{"ghostty_search_feed", &fnSearchFeed},
{"ghostty_search_tick", &fnSearchTick},
{"ghostty_terminal_point_from_grid_ref", &fnPointFromGridRef},
}
// Load loads the library at path. Only the first call loads one: later
// calls report how it went, whatever their path.
func Load(path string) error {
lib.mu.Lock()
defer lib.mu.Unlock()
if lib.loaded || lib.err != nil {
return lib.err
}
lib.err = load(path)
lib.loaded = lib.err == nil
return lib.err
}
func load(path string) error {
h, err := open(path)
if err != nil {
return fmt.Errorf("loading %s: %w", path, err)
}
for _, s := range symbols {
if *s.addr, err = sym(h, s.name); err != nil {
return fmt.Errorf("%s is not a libghostty-vt this package binds: %w", path, err)
}
}
if err := checkLayouts(); err != nil {
return fmt.Errorf("%s is not a libghostty-vt this package binds: %w", path, err)
}
registerFunc(&terminalScrollViewport, fnTerminalScrollViewport)
registerFunc(&terminalGridRef, fnTerminalGridRef)
registerFunc(&mouseEventSetPosition, fnMouseEventSetPosition)
registerFunc(&selectionFormatAlloc, fnSelectionFormatAlloc)
registerFunc(&formatterTerminalNew, fnFormatterTerminalNew)
makeCallbacks()
decodePNG()
return nil
}
// Loaded reports whether Load succeeded.
func Loaded() bool {
lib.mu.Lock()
defer lib.mu.Unlock()
return lib.loaded
}
// Result is a GhosttyResult other than GHOSTTY_SUCCESS.
type Result int32
const (
success Result = 0
OutOfMemory Result = -1
Invalid Result = -2
OutOfSpace Result = -3
NoValue Result = -4
IOError Result = -5
Exceeded Result = -6
Rejected Result = -7
)
func (r Result) Error() string {
switch r {
case OutOfMemory:
return "libghostty-vt: out of memory"
case Invalid:
return "libghostty-vt: invalid value"
case OutOfSpace:
return "libghostty-vt: out of space"
case NoValue:
return "libghostty-vt: no value"
case IOError:
return "libghostty-vt: I/O error"
case Exceeded:
return "libghostty-vt: limit exceeded"
case Rejected:
return "libghostty-vt: rejected"
}
return fmt.Sprintf("libghostty-vt: error %d", int32(r))
}
// result converts what a function returning GhosttyResult returned.
func result(r uintptr) error {
if v := Result(int32(r)); v != success {
return v
}
return nil
}
// ok reports whether a function returning GhosttyResult succeeded.
func ok(r uintptr) bool { return int32(r) == 0 }
// cbool reads a C bool returned in a register, whose upper bits are
// undefined.
func cbool(r uintptr) bool { return byte(r) != 0 }
func b2u(b bool) uintptr {
if b {
return 1
}
return 0
}
// mem converts an address the library gave into a pointer.
func mem(p uintptr) unsafe.Pointer { return *(*unsafe.Pointer)(unsafe.Pointer(&p)) }
// goString copies a string the library owns.
func goString(p, n uintptr) string {
if p == 0 || n == 0 {
return ""
}
return string(unsafe.Slice((*byte)(mem(p)), n))
}
// cStringAt copies a NUL-terminated string the library owns.
func cStringAt(p uintptr) string {
n := uintptr(0)
for *(*byte)(unsafe.Add(mem(p), n)) != 0 {
n++
}
return goString(p, n)
}
// cell is the layout of the packed GhosttyCell, from the manifest.
var cell struct {
tag, codepoint, styleID, wide, hyperlink bitField
// paletteIndex, r, g and b are the content of cells holding only a
// background color.
paletteIndex, r, g, b bitField
}
type bitField struct{ lsb, width uint }
func (f bitField) of(v uint64) uint64 { return v >> f.lsb & (1<<f.width - 1) }
// manifest is what ghostty_type_json describes.
type manifest struct {
ABI struct {
PointerSize int `json:"pointer_size"`
} `json:"abi"`
Types map[string]typeInfo `json:"types"`
}
type typeInfo struct {
Kind string `json:"kind"`
Size uintptr `json:"size"`
Fields map[string]fieldInfo `json:"fields"`
Bits map[string]bitInfo `json:"bits"`
Values map[string]int64 `json:"values"`
}
// enums are values of enums this package hardcodes, which the manifest
// must agree with.
var enums = []struct {
typ, name string
value int64
}{
{"GhosttyKey", "A", int64(KeyA)},
{"GhosttyKey", "ARROW_UP", int64(KeyArrowUp)},
{"GhosttyKey", "ESCAPE", int64(KeyEscape)},
{"GhosttyKey", "F1", int64(KeyF1)},
{"GhosttyKeyAction", "REPEAT", int64(KeyRepeat)},
{"GhosttyMouseAction", "MOTION", int64(MouseMotion)},
{"GhosttyMouseButton", "FIVE", WheelDown},
{"GhosttyRenderStateCursorVisualStyle", "BLOCK_HOLLOW", int64(CursorBlockHollow)},
{"GhosttyRenderStateDirty", "FULL", int64(Full)},
{"GhosttyTerminalData", "KITTY_GRAPHICS", dataKittyGraphics},
{"GhosttyTerminalData", "COLOR_FOREGROUND", dataColorFg},
{"GhosttyTerminalData", "COLOR_FOREGROUND_DEFAULT", dataColorFgDefault},
{"GhosttyTerminalData", "KITTY_KEYBOARD_FLAGS", dataKittyKeyboardFlags},
{"GhosttyTerminalData", "SCROLLBACK_ROWS", dataScrollbackRows},
{"GhosttyTerminalData", "MOUSE_TRACKING", dataMouseTracking},
{"GhosttyTerminalData", "MOUSE_SHAPE", dataMouseShape},
{"GhosttyRowData", "WRAP", rowDataWrap},
{"GhosttyRowData", "SEMANTIC_PROMPT", rowDataSemanticPrompt},
{"GhosttyRowSemanticPrompt", "PROMPT_CONTINUATION", int64(PromptContinuation)},
{"GhosttyRenderStateRowData", "RAW", rowDataRaw},
{"GhosttyKittyGraphicsPlacementData", "Z", placementZ},
{"GhosttyKittyGraphicsImageData", "GENERATION", imageGeneration},
{"GhosttyKittyImageFormat", "GRAY", int64(ImageGray)},
{"GhosttySysOption", "DECODE_PNG", sysDecodePNG},
{"GhosttyCellWide", "SPACER_HEAD", int64(SpacerHead)},
{"GhosttyStyleColorTag", "RGB", colorRGB},
{"GhosttySgrUnderline", "DASHED", UnderlineDashed},
{"GhosttyTerminalScrollViewportTag", "ROW", 3},
{"GhosttyPointTag", "VIEWPORT", 1},
{"GhosttyClipboardWriteResult", "UNSUPPORTED", 2},
{"GhosttySelectionGestureEventType", "DRAG", gestureDrag},
{"GhosttySearchStatus", "COMPLETE", int64(SearchComplete)},
{"GhosttySearchOption", "SELECT_PREV", searchOptSelectPrev},
{"GhosttySearchData", "VIEWPORT_MATCHES", searchDataViewportMatches},
{"GhosttySearchScroll", "NONE", searchScrollNone},
{"GhosttyPointTag", "SCREEN", pointScreen},
}
type fieldInfo struct {
Offset uintptr `json:"offset"`
}
type bitInfo struct {
LSB uint `json:"lsb"`
Width uint `json:"width"`
Arms map[string]*bitArms `json:"arms"`
}
type bitArms struct {
Bits map[string]bitInfo `json:"bits"`
}
// layout is a struct this package mirrors: its size and the offsets of
// its fields as Go lays them out.
type layout struct {
size uintptr
fields map[string]uintptr
}
// checkLayouts compares the structs of this package with the layouts the
// library reports, and reads the bit positions of packed cells.
func checkLayouts() error {
p := call(fnTypeJSON)
if p == 0 {
return errors.New("no type manifest")
}
var m manifest
if err := json.Unmarshal([]byte(cStringAt(p)), &m); err != nil {
return fmt.Errorf("type manifest: %w", err)
}
return m.check()
}
func (m *manifest) check() error {
if m.ABI.PointerSize != int(unsafe.Sizeof(uintptr(0))) {
return fmt.Errorf("built for %d-byte pointers", m.ABI.PointerSize)
}
for name, want := range layouts() {
t, ok := m.Types[name]
if !ok {
return fmt.Errorf("no type %s", name)
}
if t.Size != want.size {
return fmt.Errorf("%s is %d bytes, not %d", name, t.Size, want.size)
}
for field, off := range want.fields {
f, ok := t.Fields[field]
if !ok {
return fmt.Errorf("%s has no field %s", name, field)
}
if f.Offset != off {
return fmt.Errorf("%s.%s is at %d, not %d", name, field, f.Offset, off)
}
}
}
for _, e := range enums {
if v, ok := m.Types[e.typ].Values[e.name]; !ok || v != e.value {
return fmt.Errorf("%s %s is not %d", e.typ, e.name, e.value)
}
}
c, ok := m.Types["GhosttyCell"]
if !ok || c.Kind != "packed" || c.Size != 8 {
return errors.New("GhosttyCell is not a packed 64-bit value")
}
var errs []error
field := func(dst *bitField, name string) {
b, ok := c.Bits[name]
if !ok {
errs = append(errs, fmt.Errorf("GhosttyCell has no %s", name))
}
*dst = bitField{b.LSB, b.Width}
}
arm := func(dst *bitField, tag, name string) {
content := c.Bits["content"]
a := content.Arms[tag]
if a == nil {
errs = append(errs, fmt.Errorf("GhosttyCell content has no %s", tag))
return
}
b, ok := a.Bits[name]
if !ok {
errs = append(errs, fmt.Errorf("GhosttyCell content has no %s.%s", tag, name))
}
*dst = bitField{content.LSB + b.LSB, b.Width}
}
field(&cell.tag, "content_tag")
field(&cell.styleID, "style_id")
field(&cell.wide, "wide")
field(&cell.hyperlink, "hyperlink")
arm(&cell.codepoint, "CODEPOINT", "codepoint")
arm(&cell.paletteIndex, "BG_COLOR_PALETTE", "index")
arm(&cell.r, "BG_COLOR_RGB", "r")
arm(&cell.g, "BG_COLOR_RGB", "g")
arm(&cell.b, "BG_COLOR_RGB", "b")
return errors.Join(errs...)
}
@@ -0,0 +1,11 @@
//go:build (darwin && !ios) || (linux && !android && (amd64 || arm64))
package vt
import "github.com/ebitengine/purego"
func open(path string) (uintptr, error) {
return purego.Dlopen(path, purego.RTLD_NOW|purego.RTLD_LOCAL)
}
func sym(h uintptr, name string) (uintptr, error) { return purego.Dlsym(h, name) }
@@ -0,0 +1,14 @@
//go:build windows && (amd64 || arm64)
package vt
import "syscall"
func open(path string) (uintptr, error) {
h, err := syscall.LoadLibrary(path)
return uintptr(h), err
}
func sym(h uintptr, name string) (uintptr, error) {
return syscall.GetProcAddress(syscall.Handle(h), name)
}
+384
View File
@@ -0,0 +1,384 @@
package vt
import (
"fmt"
"strconv"
"strings"
"unsafe"
)
// RenderState is a GhosttyRenderState: what a frame draws of a terminal,
// copied from it by an update, with the rows that changed since the last
// frame marked dirty.
type RenderState struct {
h uintptr
rows uintptr // the row iterator
cells uintptr // the cells of the iterator's row
// raw holds the cells of the row read last.
raw []Cell
}
// Render state data (GhosttyRenderStateData and its row and cell kinds).
const (
rsDataCols = 1
rsDataRows = 2
rsDataDirty = 3
rsDataRowIterator = 4
rsDataCursor = 18
rsDataColors = 19
rowDataDirty = 1
rowDataRaw = 2
rowDataCells = 3
rowDataSelection = 4
rowDataCellsRaw = 5
rowDataID = 7
cellDataStyle = 2
cellDataGraphemesLen = 3
cellDataGraphemesBuf = 4
)
// NewRenderState makes an empty render state.
func NewRenderState() (*RenderState, error) {
r := &RenderState{}
if err := result(call(fnRenderStateNew, 0, uintptr(unsafe.Pointer(&r.h)))); err != nil {
return nil, err
}
if err := result(call(fnRowIteratorNew, 0, uintptr(unsafe.Pointer(&r.rows)))); err != nil {
r.Free()
return nil, err
}
if err := result(call(fnRowCellsNew, 0, uintptr(unsafe.Pointer(&r.cells)))); err != nil {
r.Free()
return nil, err
}
return r, nil
}
// Free frees the render state.
func (r *RenderState) Free() {
if r.cells != 0 {
call(fnRowCellsFree, r.cells)
}
if r.rows != 0 {
call(fnRowIteratorFree, r.rows)
}
if r.h != 0 {
call(fnRenderStateFree, r.h)
}
*r = RenderState{}
}
// BeginUpdate copies the terminal's state, the only step that needs the
// terminal; EndUpdate finishes the update without it.
func (r *RenderState) BeginUpdate(t *Terminal) error {
return result(call(fnRenderStateBeginUpdate, r.h, t.h))
}
// EndUpdate finishes the update BeginUpdate started.
func (r *RenderState) EndUpdate() { call(fnRenderStateEndUpdate, r.h) }
// Update updates the render state from the terminal in one step.
func (r *RenderState) Update(t *Terminal) error {
if err := r.BeginUpdate(t); err != nil {
return err
}
r.EndUpdate()
return nil
}
// Clean marks everything drawn.
func (r *RenderState) Clean() { call(fnRenderStateClean, r.h) }
func (r *RenderState) get(data int, out unsafe.Pointer) error {
return result(call(fnRenderStateGet, r.h, uintptr(data), uintptr(out)))
}
// Dirty is how much of a frame changed.
type Dirty int32
const (
Clean Dirty = iota
Partial
Full
)
// Dirty reports how much changed since the last Clean.
func (r *RenderState) Dirty() Dirty {
var d Dirty
r.get(rsDataDirty, unsafe.Pointer(&d))
return d
}
// Size returns the size of the viewport in cells.
func (r *RenderState) Size() (cols, rows int) {
var c, rr uint16
r.get(rsDataCols, unsafe.Pointer(&c))
r.get(rsDataRows, unsafe.Pointer(&rr))
return int(c), int(rr)
}
// Colors are the colors of a frame: those programs set, else the defaults.
type Colors struct {
Background, Foreground RGB
// Cursor is the cursor's color when HasCursor is set; it takes the
// text's otherwise.
Cursor RGB
HasCursor bool
Palette [256]RGB
}
// Colors returns the colors of the frame.
func (r *RenderState) Colors() Colors {
c := renderColors{size: unsafe.Sizeof(renderColors{})}
r.get(rsDataColors, unsafe.Pointer(&c))
return Colors{Background: c.background, Foreground: c.foreground, Cursor: c.cursor, HasCursor: c.cursorHasValue, Palette: c.palette}
}
// Cursor is the cursor of a frame.
type Cursor struct {
// InView reports that the cursor is in the viewport, at column X of
// row Y; WideTail that it is on the second half of a wide character.
InView bool
X, Y int
WideTail bool
// Visible reports that programs show the cursor, Blinking that it
// blinks, Password that the program reads a password.
Visible, Blinking, Password bool
Style CursorStyle
}
// Cursor returns the cursor of the frame.
func (r *RenderState) Cursor() Cursor {
c := renderCursor{size: unsafe.Sizeof(renderCursor{})}
r.get(rsDataCursor, unsafe.Pointer(&c))
return Cursor{
InView: c.viewportHasValue, X: int(c.viewportX), Y: int(c.viewportY), WideTail: c.wideTail,
Visible: c.visible, Blinking: c.blinking, Password: c.passwordInput, Style: CursorStyle(c.visualStyle),
}
}
// Rows starts going through the rows of the frame, top to bottom, with
// NextRow.
func (r *RenderState) Rows() { r.get(rsDataRowIterator, unsafe.Pointer(&r.rows)) }
// NextRow moves to the next row, and reports whether there is one.
func (r *RenderState) NextRow() bool { return cbool(call(fnRowIteratorNext, r.rows)) }
func (r *RenderState) rowGet(data int, out unsafe.Pointer) bool {
return ok(call(fnRowGet, r.rows, uintptr(data), uintptr(out)))
}
// RowDirty reports whether the row changed since the last Clean.
func (r *RenderState) RowDirty() bool {
var v bool
return r.rowGet(rowDataDirty, unsafe.Pointer(&v)) && v
}
// RowWrapped reports whether the row soft-wraps into the next.
func (r *RenderState) RowWrapped() bool {
var raw uint64
if !r.rowGet(rowDataRaw, unsafe.Pointer(&raw)) {
return false
}
var v bool
return ok(call(fnRowData, uintptr(raw), rowDataWrap, uintptr(unsafe.Pointer(&v)))) && v
}
// RowPrompt returns how the row belongs to a shell's prompt.
func (r *RenderState) RowPrompt() RowPrompt {
var raw uint64
if !r.rowGet(rowDataRaw, unsafe.Pointer(&raw)) {
return NoPrompt
}
v := NoPrompt
if !ok(call(fnRowData, uintptr(raw), rowDataSemanticPrompt, uintptr(unsafe.Pointer(&v)))) {
return NoPrompt
}
return v
}
// RowID returns the identity of the row, which it keeps as it scrolls.
func (r *RenderState) RowID() RowID {
var id RowID
r.rowGet(rowDataID, unsafe.Pointer(&id))
return id
}
// RowSelection returns the selected columns of the row, from start to end
// inclusive.
func (r *RenderState) RowSelection() (start, end int, ok bool) {
s := rowSelection{size: unsafe.Sizeof(rowSelection{})}
if !r.rowGet(rowDataSelection, unsafe.Pointer(&s)) {
return 0, 0, false
}
return int(s.startX), int(s.endX), true
}
// Wide is how wide a cell's character is.
type Wide uint8
const (
Narrow Wide = iota
// WideChar takes this cell and the next, a SpacerTail.
WideChar
SpacerTail
// SpacerHead ends a soft-wrapped row before a wide character that did
// not fit.
SpacerHead
)
// Cell is a cell of a row.
type Cell struct {
// Codepoint is the character, 0 for none; Grapheme reports more
// codepoints after it (CellGraphemes).
Codepoint rune
Grapheme bool
// Style identifies the cell's style (CellStyle) among the row's
// cells: 0 is the default.
Style uint16
Wide Wide
Hyperlink bool
// Background is the color of a cell without text whose background
// a program filled, when HasBackground; Palette tells that it is
// the palette's color of index Background.R.
Background RGB
HasBackground bool
Palette bool
}
// RowCells returns the cells of the row, valid until the next update.
func (r *RenderState) RowCells() []Cell {
var v cellsView
if !r.rowGet(rowDataCellsRaw, unsafe.Pointer(&v)) || v.ptr == 0 {
return nil
}
raw := unsafe.Slice((*uint64)(mem(v.ptr)), v.len)
r.raw = r.raw[:0]
for _, c := range raw {
var out Cell
switch cell.tag.of(c) {
case 0, 1: // a codepoint, of a grapheme cluster for 1
out.Codepoint = rune(cell.codepoint.of(c))
out.Grapheme = cell.tag.of(c) == 1
case 2:
out.HasBackground, out.Palette = true, true
out.Background.R = uint8(cell.paletteIndex.of(c))
case 3:
out.HasBackground = true
out.Background = RGB{uint8(cell.r.of(c)), uint8(cell.g.of(c)), uint8(cell.b.of(c))}
}
out.Style = uint16(cell.styleID.of(c))
out.Wide = Wide(cell.wide.of(c))
out.Hyperlink = cell.hyperlink.of(c) != 0
r.raw = append(r.raw, out)
}
// The cells of the row for the style and grapheme lookups.
r.rowGet(rowDataCells, unsafe.Pointer(&r.cells))
return r.raw
}
// Color is the color of a style: none (the default), an index of the
// palette, or an RGB color.
type Color struct {
Kind uint8 // 0 none, 1 palette, 2 RGB
Index uint8
RGB RGB
}
func (c styleColor) color() Color {
switch c.tag {
case colorPalette:
return Color{Kind: 1, Index: c.value[0]}
case colorRGB:
return Color{Kind: 2, RGB: RGB{c.value[0], c.value[1], c.value[2]}}
}
return Color{}
}
// Underline styles.
const (
UnderlineNone = iota
UnderlineSingle
UnderlineDouble
UnderlineCurly
UnderlineDotted
UnderlineDashed
)
// Style is how a cell's text shows.
type Style struct {
FG, BG, UnderlineColor Color
Bold, Italic, Faint, Blink, Inverse, Invisible, Strikethrough, Overline bool
Underline int
}
// SGR returns the SGR sequence that sets the style from none.
func (s Style) SGR() string {
p := []string{"0"}
add := func(on bool, code string) {
if on {
p = append(p, code)
}
}
add(s.Bold, "1")
add(s.Faint, "2")
add(s.Italic, "3")
switch s.Underline {
case UnderlineNone:
case UnderlineSingle:
p = append(p, "4")
default:
p = append(p, "4:"+strconv.Itoa(s.Underline))
}
add(s.Blink, "5")
add(s.Inverse, "7")
add(s.Invisible, "8")
add(s.Strikethrough, "9")
add(s.Overline, "53")
for _, c := range []struct {
c Color
base string
}{{s.FG, "38"}, {s.BG, "48"}, {s.UnderlineColor, "58"}} {
switch c.c.Kind {
case 1:
p = append(p, c.base+":5:"+strconv.Itoa(int(c.c.Index)))
case 2:
p = append(p, fmt.Sprintf("%s:2::%d:%d:%d", c.base, c.c.RGB.R, c.c.RGB.G, c.c.RGB.B))
}
}
return "\x1b[" + strings.Join(p, ";") + "m"
}
// CellStyle returns the style of cell x of the row RowCells read.
func (r *RenderState) CellStyle(x int) Style {
s := style{size: unsafe.Sizeof(style{})}
if ok(call(fnRowCellsSelect, r.cells, uintptr(x))) {
call(fnRowCellsGet, r.cells, cellDataStyle, uintptr(unsafe.Pointer(&s)))
}
return Style{
FG: s.fg.color(), BG: s.bg.color(), UnderlineColor: s.underlineColor.color(),
Bold: s.bold, Italic: s.italic, Faint: s.faint, Blink: s.blink, Inverse: s.inverse,
Invisible: s.invisible, Strikethrough: s.strikethrough, Overline: s.overline, Underline: int(s.underline),
}
}
// CellGraphemes appends the codepoints of cell x of the row RowCells read
// to buf.
func (r *RenderState) CellGraphemes(x int, buf []rune) []rune {
if !ok(call(fnRowCellsSelect, r.cells, uintptr(x))) {
return buf
}
var n uint32
call(fnRowCellsGet, r.cells, cellDataGraphemesLen, uintptr(unsafe.Pointer(&n)))
if n == 0 {
return buf
}
cps := make([]uint32, n)
call(fnRowCellsGet, r.cells, cellDataGraphemesBuf, uintptr(unsafe.Pointer(&cps[0])))
for _, c := range cps {
buf = append(buf, rune(c))
}
return buf
}
+50
View File
@@ -0,0 +1,50 @@
package vt
import (
"bytes"
"unsafe"
)
// What a Mirror reads of a terminal besides its rows, which a render state
// reads.
const (
rowDataWrap = 1
rowDataSemanticPrompt = 6
dataKittyKeyboardFlags = 8
dataScrollbackRows = 15
)
// ScrollbackRows returns how many rows the scrollback holds.
func (t *Terminal) ScrollbackRows() int {
var n uintptr
t.get(dataScrollbackRows, unsafe.Pointer(&n))
return int(n)
}
// KittyKeyboardFlags returns the flags of the kitty keyboard protocol
// programs set.
func (t *Terminal) KittyKeyboardFlags() int {
var f uint8
t.get(dataKittyKeyboardFlags, unsafe.Pointer(&f))
return int(f)
}
// ModifyOtherKeys reports whether xterm's modifyOtherKeys mode 2 is on
// (CSI > 4 ; 2 m). The library tells it in no GhosttyTerminalData, but a
// key encoder takes it from the terminal with the other modes: without the
// Kitty keyboard protocol, Ctrl+P is CSI 27 ; 5 ; 112 ~ in mode 2, and ^P
// otherwise.
func (t *Terminal) ModifyOtherKeys() bool {
e, err := NewKeyEncoder()
if err != nil {
return false
}
defer e.Free()
call(fnKeyEncoderSetoptFromTerminal, e.h, t.h)
var kitty uint8
call(fnKeyEncoderSetopt, e.h, 5, uintptr(unsafe.Pointer(&kitty)))
b := e.Encode(KeyEvent{Action: KeyPress, Key: KeyP, Mods: ModCtrl, Text: "p", Unshifted: 'p'})
return bytes.HasPrefix(b, []byte("\x1b[27;"))
}
+183
View File
@@ -0,0 +1,183 @@
package vt
import (
"runtime"
"unsafe"
)
// Search options and data (GhosttySearchOption, GhosttySearchData).
const (
searchOptNeedle = 0
searchOptSelectNext = 1
searchOptSelectPrev = 2
searchOptSelectScroll = 3
searchScrollNone = 1
searchDataStatus = 0
searchDataTotal = 2
searchDataSelectedIndex = 3
searchDataSelectedMatch = 4
searchDataViewportMatches = 6
)
// SearchStatus is how far a search went (GhosttySearchStatus).
type SearchStatus int32
const (
// SearchRunning: Tick makes progress.
SearchRunning SearchStatus = iota
// SearchFeedRequired: Feed must read the terminal first.
SearchFeedRequired
// SearchComplete: the search caught up with the terminal as of the
// last Feed.
SearchComplete
)
// Search searches a terminal, its scrollback included, for text, as
// Ghostty's find does: matches follow the screen as it changes, and the
// screens as programs switch them. Matching is exact but for ASCII letters,
// whose case it ignores.
type Search struct {
h uintptr
}
// selectionBuffer is a GhosttySelectionBuffer.
type selectionBuffer struct {
ptr *Selection
cap, len uintptr
}
// NewSearch makes a search of t, which looks for nothing until SetText.
// Selecting a match scrolls nothing: the caller shows it where it likes.
func NewSearch(t *Terminal) (*Search, error) {
s := &Search{}
if err := result(call(fnSearchNew, 0, uintptr(unsafe.Pointer(&s.h)), t.h)); err != nil {
return nil, err
}
none := int32(searchScrollNone)
call(fnSearchSet, s.h, searchOptSelectScroll, uintptr(unsafe.Pointer(&none)))
return s, nil
}
// Free frees the search, before or after its terminal.
func (s *Search) Free() {
if s.h != 0 {
call(fnSearchFree, s.h)
s.h = 0
}
}
// SetText searches for text from scratch, or keeps the matches when it is
// the text searched already; "" searches for nothing.
func (s *Search) SetText(text string) {
b := []byte(text)
cs := cBytes(b)
call(fnSearchSet, s.h, searchOptNeedle, uintptr(unsafe.Pointer(&cs)))
runtime.KeepAlive(b)
}
// Feed reads what changed of the terminal, a bounded amount at a time.
func (s *Search) Feed() { call(fnSearchFeed, s.h) }
// Tick makes a bounded amount of progress, without the terminal.
func (s *Search) Tick() SearchStatus {
st := SearchComplete
call(fnSearchTick, s.h, uintptr(unsafe.Pointer(&st)))
return st
}
// Status returns how far the search went.
func (s *Search) Status() SearchStatus {
st := SearchComplete
call(fnSearchGet, s.h, searchDataStatus, uintptr(unsafe.Pointer(&st)))
return st
}
// Total returns how many matches the search found so far.
func (s *Search) Total() int {
var n uintptr
call(fnSearchGet, s.h, searchDataTotal, uintptr(unsafe.Pointer(&n)))
return int(n)
}
// Selected returns the index of the selected match, 0 the newest, and
// reports whether one is.
func (s *Search) Selected() (int, bool) {
var i uintptr
return int(i), ok(call(fnSearchGet, s.h, searchDataSelectedIndex, uintptr(unsafe.Pointer(&i))))
}
// SelectedMatch returns the selected match.
func (s *Search) SelectedMatch() (Selection, bool) {
m := Selection{size: unsafe.Sizeof(Selection{})}
return m, ok(call(fnSearchGet, s.h, searchDataSelectedMatch, uintptr(unsafe.Pointer(&m))))
}
// Select selects the next match toward older output, or toward newer
// output when back, wrapping around. It reports whether there was a match.
func (s *Search) Select(back bool) bool {
opt := uintptr(searchOptSelectNext)
if back {
opt = searchOptSelectPrev
}
return ok(call(fnSearchSet, s.h, opt, 0))
}
// ViewportMatches returns the matches on the pages the viewport shows, as
// of the last Feed, in buf's memory when it has room.
func (s *Search) ViewportMatches(buf []Selection) []Selection {
for {
buf = buf[:cap(buf)]
for i := range buf {
buf[i].size = unsafe.Sizeof(Selection{})
}
b := selectionBuffer{cap: uintptr(len(buf))}
if len(buf) > 0 {
b.ptr = &buf[0]
}
r := Result(int32(call(fnSearchGet, s.h, searchDataViewportMatches, uintptr(unsafe.Pointer(&b)))))
switch {
case r == success:
return buf[:b.len]
case r == OutOfSpace && int(b.len) > len(buf):
buf = make([]Selection, b.len)
default:
return buf[:0]
}
}
}
// ViewportPoint returns the column and the row of the viewport of a cell,
// and reports whether the viewport shows it.
func (t *Terminal) ViewportPoint(ref *GridRef) (x, y int, shown bool) {
return t.pointOf(ref, pointViewport)
}
// ScreenRow returns the row of a cell among those of the screen and its
// scrollback, 0 the oldest, as ScrollToRow takes it.
func (t *Terminal) ScreenRow(ref *GridRef) (int, bool) {
_, y, found := t.pointOf(ref, pointScreen)
return y, found
}
// GhosttyPointTag's coordinate systems.
const (
pointViewport = 1
pointScreen = 2
)
func (t *Terminal) pointOf(ref *GridRef, tag uintptr) (x, y int, found bool) {
var p struct {
x uint16
_ uint16
y uint32
}
if !ok(call(fnPointFromGridRef, t.h, uintptr(unsafe.Pointer(ref)), tag, uintptr(unsafe.Pointer(&p)))) {
return 0, 0, false
}
return int(p.x), int(p.y), true
}
// Ends returns the cells a selection starts and ends at.
func (s *Selection) Ends() (start, end *GridRef) { return &s.start, &s.end }
@@ -0,0 +1,150 @@
package vt
import "unsafe"
// Selection gesture events, options and data (GhosttySelectionGesture*).
const (
gesturePress = 0
gestureRelease = 1
gestureDrag = 2
gestureAutoTick = 3
gestureOptRef = 0
gestureOptPosition = 1
gestureOptRepeatDistance = 2
gestureOptTime = 3
gestureOptRepeatInterval = 4
gestureOptRectangle = 7
gestureOptGeometry = 8
gestureOptViewport = 9
gestureDataDragged = 1
gestureDataAutoscroll = 2
)
// Gesture turns presses and drags of the pointer into selections as
// Ghostty does: a click and a drag select cells, a double click words and
// a triple click lines, and dragging past the top or the bottom asks to
// scroll.
type Gesture struct {
h uintptr
press, release, drag, tick uintptr
}
// Geometry is the grid in pixels, for drags.
type Geometry struct {
Columns, CellWidth, PadLeft, Height int
}
// NewGesture makes a gesture: repeated clicks count within interval
// nanoseconds of each other and distance pixels.
func NewGesture(interval uint64, distance float64) (*Gesture, error) {
g := &Gesture{}
if err := result(call(fnGestureNew, 0, uintptr(unsafe.Pointer(&g.h)))); err != nil {
return nil, err
}
for _, e := range []struct {
h *uintptr
typ int
}{{&g.press, gesturePress}, {&g.release, gestureRelease}, {&g.drag, gestureDrag}, {&g.tick, gestureAutoTick}} {
if err := result(call(fnGestureEventNew, 0, uintptr(unsafe.Pointer(e.h)), uintptr(e.typ))); err != nil {
g.Free(nil)
return nil, err
}
}
call(fnGestureEventSet, g.press, gestureOptRepeatInterval, uintptr(unsafe.Pointer(&interval)))
call(fnGestureEventSet, g.press, gestureOptRepeatDistance, uintptr(unsafe.Pointer(&distance)))
return g, nil
}
// Free frees the gesture, which belongs to t (nil if it was never used).
func (g *Gesture) Free(t *Terminal) {
for _, e := range []uintptr{g.press, g.release, g.drag, g.tick} {
if e != 0 {
call(fnGestureEventFree, e)
}
}
if g.h != 0 {
th := uintptr(0)
if t != nil {
th = t.h
}
call(fnGestureFree, g.h, th)
}
*g = Gesture{}
}
func (g *Gesture) apply(t *Terminal, ev uintptr) (Selection, bool) {
s := Selection{size: unsafe.Sizeof(Selection{})}
return s, ok(call(fnGestureEvent, g.h, t.h, ev, uintptr(unsafe.Pointer(&s))))
}
// Press presses the pointer on cell ref at x, y pixels, at time ns of a
// monotonic clock. A double or triple click selects at once.
func (g *Gesture) Press(t *Terminal, ref GridRef, x, y float64, ns uint64) (Selection, bool) {
pos := surfacePosition{x, y}
call(fnGestureEventSet, g.press, gestureOptRef, uintptr(unsafe.Pointer(&ref)))
call(fnGestureEventSet, g.press, gestureOptPosition, uintptr(unsafe.Pointer(&pos)))
call(fnGestureEventSet, g.press, gestureOptTime, uintptr(unsafe.Pointer(&ns)))
return g.apply(t, g.press)
}
// Drag moves the pressed pointer to cell ref at x, y pixels, selecting a
// rectangle when rect is set.
func (g *Gesture) Drag(t *Terminal, ref GridRef, x, y float64, geo Geometry, rect bool) (Selection, bool) {
pos := surfacePosition{x, y}
gg := gestureGeometry{uint32(max(geo.Columns, 1)), uint32(max(geo.CellWidth, 1)), uint32(max(geo.PadLeft, 0)), uint32(max(geo.Height, 1))}
call(fnGestureEventSet, g.drag, gestureOptRef, uintptr(unsafe.Pointer(&ref)))
call(fnGestureEventSet, g.drag, gestureOptPosition, uintptr(unsafe.Pointer(&pos)))
call(fnGestureEventSet, g.drag, gestureOptGeometry, uintptr(unsafe.Pointer(&gg)))
call(fnGestureEventSet, g.drag, gestureOptRectangle, uintptr(unsafe.Pointer(&rect)))
return g.apply(t, g.drag)
}
// Tick continues a drag past an edge after the viewport scrolled, with the
// pointer at x, y pixels over column col of row row of the viewport.
func (g *Gesture) Tick(t *Terminal, col, row int, x, y float64, geo Geometry, rect bool) (Selection, bool) {
pos := surfacePosition{x, y}
gg := gestureGeometry{uint32(max(geo.Columns, 1)), uint32(max(geo.CellWidth, 1)), uint32(max(geo.PadLeft, 0)), uint32(max(geo.Height, 1))}
vp := struct {
x uint16
_ uint16
y uint32
}{x: uint16(max(col, 0)), y: uint32(max(row, 0))}
call(fnGestureEventSet, g.tick, gestureOptPosition, uintptr(unsafe.Pointer(&pos)))
call(fnGestureEventSet, g.tick, gestureOptGeometry, uintptr(unsafe.Pointer(&gg)))
call(fnGestureEventSet, g.tick, gestureOptViewport, uintptr(unsafe.Pointer(&vp)))
call(fnGestureEventSet, g.tick, gestureOptRectangle, uintptr(unsafe.Pointer(&rect)))
return g.apply(t, g.tick)
}
// Release releases the pointer over cell ref, or outside the grid when ref
// is nil.
func (g *Gesture) Release(t *Terminal, ref *GridRef) {
call(fnGestureEventSet, g.release, gestureOptRef, uintptr(unsafe.Pointer(ref)))
g.apply(t, g.release)
}
// Dragged reports whether the pointer moved to another cell since it was
// pressed.
func (g *Gesture) Dragged(t *Terminal) bool {
var v bool
return ok(call(fnGestureGet, g.h, t.h, gestureDataDragged, uintptr(unsafe.Pointer(&v)))) && v
}
// Autoscroll reports whether a drag past an edge asks to scroll up (-1) or
// down (1).
func (g *Gesture) Autoscroll(t *Terminal) int {
var v int32
call(fnGestureGet, g.h, t.h, gestureDataAutoscroll, uintptr(unsafe.Pointer(&v)))
switch v {
case 1:
return -1
case 2:
return 1
}
return 0
}
// Reset forgets the gesture's clicks.
func (g *Gesture) Reset(t *Terminal) { call(fnGestureReset, g.h, t.h) }
@@ -0,0 +1,869 @@
package vt
import (
"bytes"
"errors"
"fmt"
"runtime"
"slices"
"strings"
"sync"
"unsafe"
)
// Terminal is a GhosttyTerminal: the screen, its scrollback, the cursor
// and the modes, which the output of programs changes.
type Terminal struct {
h uintptr
id uintptr
// Effects are called during Write, on its goroutine; they must not
// call Write.
effects Effects
// silent is set while a clipboard read is refused: the refusal the
// library writes for it, a Kitty protocol EPERM, is dropped, as the
// read of a terminal that is not the one to answer.
silent bool
// deferred is the clipboard read the embedder answers later: the
// library's refusal, which follows the read's effect, is held back
// and captured in it.
deferred *DeferredClipboardRead
// reply gathers what the library writes while it answers a clipboard
// read, which WritePTY then gets at once.
reply *[]byte
}
// ClipboardRead is a program's request to read the clipboard.
type ClipboardRead struct {
// Mimes are the types asked for, in order of preference; List asks
// for the types available.
Mimes []string
List bool
// Primary is the selection clipboard of X11.
Primary bool
// Granted tells that the program holds the terminal's permission, as
// when it reads what a paste offered it.
Granted bool
// CanRemember tells that the program asked with a password (the one
// a paste event gave it, with its name): a terminal that pasted
// knows it — Granted says so — and one that does not never can, and
// leaves the read to the one it is for.
CanRemember bool
}
// ClipboardReply answers a ClipboardRead: Contents by MIME type, of the
// types asked for, and Available when the list was asked for. Without
// contents the read is refused. A deferred read carries Deferred instead.
type ClipboardReply struct {
Contents map[string][]byte
Available []string
// Deferred is the read to answer later, with ClipboardDeferred.
Deferred *DeferredClipboardRead
}
// Effects are what a terminal asks of its embedder while it processes
// output, all optional. They run during Terminal.Write, which they must
// not call.
type Effects struct {
// WritePTY answers the program, as to a query of the cursor's
// position. p is only valid during the call.
WritePTY func(p []byte)
Bell func()
// TitleChanged and PwdChanged tell that Title or Pwd changed.
TitleChanged func()
PwdChanged func()
// RenderHold tells that the program started or ended a synchronized
// update (mode 2026), during which the screen should not show.
RenderHold func(held bool)
// Clipboard writes text to the clipboard (OSC 52), and reports
// whether it did. primary is the selection clipboard of X11.
Clipboard func(text string, primary bool) bool
// ClipboardRead answers a program's read of the clipboard (OSC 52
// with "?", the Kitty clipboard protocol's OSC 5522): the contents of
// the MIME types asked for, and the types available when the program
// asks for the list. ClipboardAnswered writes the reply, encoded, to
// WritePTY in one call as ClipboardRead returns; ClipboardRefused
// refuses it (an empty OSC 52 reply, EPERM for OSC 5522), and the
// EPERM is dropped, so that a terminal that is not the one to answer
// stays silent; ClipboardDeferred holds the refusal back and answers
// later through Terminal.AnswerClipboard, for a terminal that must
// ask the user first.
ClipboardRead func(req ClipboardRead) (reply ClipboardReply, answer ClipboardAnswer)
// Size reports the size of the screen in cells and of a cell in
// pixels, for size reports.
Size func() (cols, rows, cellWidth, cellHeight int)
// Dark reports whether the colors are dark, for color scheme reports.
Dark func() bool
// Notify shows a desktop notification (OSC 9, OSC 777).
Notify func(title, body string)
// Progress reports the progress of the program (OSC 9;4): state is
// 0 to remove it, 1 to set it to progress (0 to 100), 2 for an error,
// 3 for indeterminate progress and 4 paused.
Progress func(state, progress int)
}
// terminals finds the terminal of a callback by its userdata.
var terminals struct {
sync.Mutex
next uintptr
m map[uintptr]*Terminal
}
func terminalOf(id uintptr) *Terminal {
terminals.Lock()
defer terminals.Unlock()
return terminals.m[id]
}
// Terminal options and data (GhosttyTerminalOption, GhosttyTerminalData).
const (
optUserdata = 0
optWritePTY = 1
optBell = 2
optTitleChanged = 5
optSize = 6
optColorScheme = 7
optDeviceAttributes = 8
optColorForeground = 11
optColorBackground = 12
optColorCursor = 13
optColorPalette = 14
optKittyImageLimit = 15
optDefaultCursorStyle = 22
optDefaultCursorBlink = 23
optPwdChanged = 25
optClipboardWrite = 26
optClipboardRead = 38
optScrollbackMaxBytes = 27
optDesktopNotification = 29
optProgressReport = 30
optModeDefault = 33
optMode = 34
optTerminfoName = 37
optResizePullBack = 40
optRenderHold = 41
dataCols = 1
dataRows = 2
dataCursorX = 3
dataCursorY = 4
dataActiveScreen = 6
dataScrollbar = 9
dataMouseTracking = 11
dataTitle = 12
dataPwd = 13
dataColorFg = 18 // then the background, the cursor and the palette
dataColorFgDefault = 22 // the same, defaults alone
dataViewportActive = 32
dataMode = 37
dataMouseShape = 41
)
// NewTerminal makes a terminal of cols columns and rows rows.
func NewTerminal(cols, rows int, effects Effects) (*Terminal, error) {
if !Loaded() {
return nil, errors.New("libghostty-vt is not loaded")
}
t := &Terminal{effects: effects}
if err := result(call(fnTerminalNew, 0, uintptr(unsafe.Pointer(&t.h)), uintptr(clamp16(cols)), uintptr(clamp16(rows)))); err != nil {
return nil, err
}
terminals.Lock()
if terminals.m == nil {
terminals.m = map[uintptr]*Terminal{}
}
terminals.next++
t.id = terminals.next
terminals.m[t.id] = t
terminals.Unlock()
t.setValue(optUserdata, t.id)
t.setValue(optWritePTY, cbWritePTY)
t.setValue(optBell, cbBell)
t.setValue(optTitleChanged, cbTitleChanged)
t.setValue(optPwdChanged, cbPwdChanged)
t.setValue(optRenderHold, cbRenderHold)
t.setValue(optClipboardWrite, cbClipboardWrite)
t.setValue(optClipboardRead, cbClipboardRead)
t.setValue(optSize, cbSize)
t.setValue(optColorScheme, cbColorScheme)
t.setValue(optDeviceAttributes, cbDeviceAttributes)
t.setValue(optDesktopNotification, cbDesktopNotification)
t.setValue(optProgressReport, cbProgressReport)
// Images of the Kitty graphics protocol are refused until SetImageLimit
// takes them, so that programs fall back to something else.
t.SetImageLimit(0)
return t, nil
}
// set sets an option to a pointer to its value. The pointer is converted
// in the call, so that the value stays put while the library reads it
// (see call).
func (t *Terminal) set(opt int, value unsafe.Pointer) error {
return result(call(fnTerminalSet, t.h, uintptr(opt), uintptr(value)))
}
// setValue sets an option that is a value itself: a callback, or the
// userdata.
func (t *Terminal) setValue(opt int, value uintptr) error {
return result(call(fnTerminalSet, t.h, uintptr(opt), value))
}
func (t *Terminal) get(data int, out unsafe.Pointer) error {
return result(call(fnTerminalGet, t.h, uintptr(data), uintptr(out)))
}
// Free frees the terminal.
func (t *Terminal) Free() {
if t.h == 0 {
return
}
call(fnTerminalFree, t.h)
t.h = 0
terminals.Lock()
delete(terminals.m, t.id)
terminals.Unlock()
}
// Write processes output of the program.
func (t *Terminal) Write(p []byte) {
if len(p) > 0 {
// A read that was deferred but whose refusal never came, as of a
// library of another version, is stale.
t.deferred = nil
call(fnTerminalVTWrite, t.h, uintptr(unsafe.Pointer(&p[0])), uintptr(len(p)))
t.deferred = nil
// A read that writes no refusal, as OSC 52's, leaves silent set;
// it is for that read alone.
t.silent = false
}
}
// Resize sets the size of the screen in cells, and of a cell in pixels.
func (t *Terminal) Resize(cols, rows, cellWidth, cellHeight int) error {
return result(call(fnTerminalResize, t.h, uintptr(clamp16(cols)), uintptr(clamp16(rows)), uintptr(max(cellWidth, 1)), uintptr(max(cellHeight, 1))))
}
// Size returns the size of the screen in cells.
func (t *Terminal) Size() (cols, rows int) {
var c, r uint16
t.get(dataCols, unsafe.Pointer(&c))
t.get(dataRows, unsafe.Pointer(&r))
return int(c), int(r)
}
// Cursor returns the cursor's column and row in the active screen, the
// bottom of the scrollback.
func (t *Terminal) Cursor() (x, y int) {
var cx, cy uint16
t.get(dataCursorX, unsafe.Pointer(&cx))
t.get(dataCursorY, unsafe.Pointer(&cy))
return int(cx), int(cy)
}
// Reset resets the terminal fully (RIS).
func (t *Terminal) Reset() { call(fnTerminalReset, t.h) }
// SetColors sets the default colors, which programs may change: the
// foreground, the background, the cursor's (nil for the text's) and the
// palette of 256 colors (nil for Ghostty's).
func (t *Terminal) SetColors(fg, bg RGB, cursor *RGB, palette *[256]RGB) {
t.set(optColorForeground, unsafe.Pointer(&fg))
t.set(optColorBackground, unsafe.Pointer(&bg))
t.set(optColorCursor, unsafe.Pointer(cursor))
t.set(optColorPalette, unsafe.Pointer(palette))
}
// SetScrollback limits the scrollback to about n bytes.
func (t *Terminal) SetScrollback(n int) {
v := uintptr(max(n, 0))
t.set(optScrollbackMaxBytes, unsafe.Pointer(&v))
}
// SetTerminfoName sets the name of the terminfo entry the terminal reports
// (XTGETTCAP TN).
func (t *Terminal) SetTerminfoName(name string) {
b := []byte(name)
s := cString{len: uintptr(len(b))}
// The string holds the address of b, which the call does not see.
var pin runtime.Pinner
defer pin.Unpin()
if len(b) > 0 {
pin.Pin(&b[0])
s.ptr = uintptr(unsafe.Pointer(&b[0]))
}
t.set(optTerminfoName, unsafe.Pointer(&s))
}
// CursorStyle is the shape of the cursor.
type CursorStyle int32
const (
CursorBar CursorStyle = iota
CursorBlock
CursorUnderline
CursorBlockHollow
)
// SetDefaultCursor sets the cursor that programs reset to (DECSCUSR 0).
func (t *Terminal) SetDefaultCursor(s CursorStyle, blink bool) {
t.set(optDefaultCursorStyle, unsafe.Pointer(&s))
t.set(optDefaultCursorBlink, unsafe.Pointer(&blink))
}
func (t *Terminal) str(data int) string {
var s cString
if t.get(data, unsafe.Pointer(&s)) != nil {
return ""
}
return goString(s.ptr, s.len)
}
// Title returns the title programs set (OSC 0, OSC 2).
func (t *Terminal) Title() string { return t.str(dataTitle) }
// Pwd returns the working directory the shell reported (OSC 7), as it
// reported it: a file URL, or a path.
func (t *Terminal) Pwd() string { return t.str(dataPwd) }
// Mode is a GhosttyMode: a DEC private mode, or an ANSI one with bit 15.
type Mode uint16
// Modes.
const (
ModeCursorKeys Mode = 1
ModeCursorVisible Mode = 25
ModeFocusEvent Mode = 1004
ModeAltScroll Mode = 1007
ModeBracketedPaste Mode = 2004
// ModePasteEvents has a paste tell the program what the clipboard
// holds, which it reads itself (the Kitty clipboard protocol).
ModePasteEvents Mode = 5522
ModeSyncOutput Mode = 2026
ModeGraphemes Mode = 2027
// ModeColorScheme has the terminal tell the program when its colors
// go from light to dark or back (CSI ? 997 ; 1 n for dark, 2 light).
ModeColorScheme Mode = 2031
)
// Mode reports whether a mode is set.
func (t *Terminal) Mode(m Mode) bool {
c := modeConfig{mode: uint16(m)}
return t.get(dataMode, unsafe.Pointer(&c)) == nil && c.value
}
// SetMode sets a mode.
func (t *Terminal) SetMode(m Mode, v bool) {
c := modeConfig{mode: uint16(m), value: v}
t.set(optMode, unsafe.Pointer(&c))
}
// SetModeDefault sets a mode, and the value a reset restores.
func (t *Terminal) SetModeDefault(m Mode, v bool) {
c := modeConfig{mode: uint16(m), value: v}
t.set(optModeDefault, unsafe.Pointer(&c))
}
// MouseTracking reports whether a program asked for mouse events.
func (t *Terminal) MouseTracking() bool {
var v bool
return t.get(dataMouseTracking, unsafe.Pointer(&v)) == nil && v
}
// MouseShape returns the pointer shape a program asked for (OSC 22), a
// GhosttyMouseShape.
func (t *Terminal) MouseShape() int {
var v int32
t.get(dataMouseShape, unsafe.Pointer(&v))
return int(v)
}
// TermColors are a terminal's colors; a color neither a program set nor a
// default gave is not Has.
type TermColors struct {
Foreground, Background, Cursor RGB
HasForeground, HasBackground, HasCursor bool
Palette [256]RGB
}
// Colors returns the colors programs see: those they set (OSC 4, 10, 11,
// 12) over the defaults, or with defaults the defaults alone.
func (t *Terminal) Colors(defaults bool) TermColors {
base := dataColorFg
if defaults {
base = dataColorFgDefault
}
var c TermColors
c.HasForeground = t.get(base, unsafe.Pointer(&c.Foreground)) == nil
c.HasBackground = t.get(base+1, unsafe.Pointer(&c.Background)) == nil
c.HasCursor = t.get(base+2, unsafe.Pointer(&c.Cursor)) == nil
t.get(base+3, unsafe.Pointer(&c.Palette))
return c
}
// AltScreen reports whether the alternate screen shows, as in full-screen
// programs.
func (t *Terminal) AltScreen() bool {
var v int32
return t.get(dataActiveScreen, unsafe.Pointer(&v)) == nil && v == 1
}
// Scrollbar returns where the viewport is in the scrollback.
func (t *Terminal) Scrollbar() Scrollbar {
var s Scrollbar
t.get(dataScrollbar, unsafe.Pointer(&s))
return s
}
// AtBottom reports whether the viewport follows the active screen, rather
// than showing the scrollback.
func (t *Terminal) AtBottom() bool {
var v bool
return t.get(dataViewportActive, unsafe.Pointer(&v)) != nil || v
}
// ScrollToTop, ScrollToBottom, ScrollBy and ScrollToRow move the viewport:
// to the top of the scrollback, to the active screen, by rows (negative
// up), or to show row first.
func (t *Terminal) ScrollToTop() { terminalScrollViewport(t.h, scrollViewport{tag: 0}) }
func (t *Terminal) ScrollToBottom() { terminalScrollViewport(t.h, scrollViewport{tag: 1}) }
func (t *Terminal) ScrollBy(rows int) {
terminalScrollViewport(t.h, scrollViewport{tag: 2, value: [2]uint64{uint64(int64(rows))}})
}
func (t *Terminal) ScrollToRow(row int) {
terminalScrollViewport(t.h, scrollViewport{tag: 3, value: [2]uint64{uint64(max(row, 0))}})
}
// CellAt returns the cell at column x of row y of the viewport.
func (t *Terminal) CellAt(x, y int) (GridRef, bool) {
ref := GridRef{size: unsafe.Sizeof(GridRef{})}
p := point{tag: 1, x: uint16(max(0, min(x, 0xFFFF))), y: uint32(max(y, 0))}
return ref, terminalGridRef(t.h, p, &ref) == 0
}
// SetResizePullBack sets whether growing the screen pulls rows back from
// the scrollback, which a pseudo-terminal keeping its own screen, as
// Windows' ConPTY, cannot follow.
func (t *Terminal) SetResizePullBack(v bool) {
t.set(optResizePullBack, unsafe.Pointer(&v))
}
// RowText returns the text of row y of the viewport, and the column of
// each of its runes.
func (t *Terminal) RowText(y int) (text []rune, cols []int) {
c, _ := t.Size()
var buf [16]uint32
for x := range c {
ref, found := t.CellAt(x, y)
if !found {
break
}
var raw uint64
if ok(call(fnGridRefCell, uintptr(unsafe.Pointer(&ref)), uintptr(unsafe.Pointer(&raw)))) {
if w := Wide(cell.wide.of(raw)); w == SpacerTail || w == SpacerHead {
continue
}
}
var n uintptr
if !ok(call(fnGridRefGraphemes, uintptr(unsafe.Pointer(&ref)), uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)), uintptr(unsafe.Pointer(&n)))) || n == 0 {
text, cols = append(text, ' '), append(cols, x)
continue
}
for _, r := range buf[:n] {
text, cols = append(text, rune(r)), append(cols, x)
}
}
return text, cols
}
// RowPrompt is how a row belongs to a shell's prompt, which the shell
// marks with OSC 133 (shell integration).
type RowPrompt int32
const (
NoPrompt RowPrompt = iota
// PromptStart is the row a prompt starts on (OSC 133;A).
PromptStart
// PromptContinuation is a row the prompt or its input goes on over:
// one a long command wraps onto, or a prompt's next line.
PromptContinuation
)
// Row returns how row y of the viewport belongs to a shell's prompt, and
// whether it soft-wraps into the next.
func (t *Terminal) Row(y int) (prompt RowPrompt, wrap bool) {
ref, found := t.CellAt(0, y)
if !found {
return NoPrompt, false
}
var row uint64
if !ok(call(fnGridRefRow, uintptr(unsafe.Pointer(&ref)), uintptr(unsafe.Pointer(&row)))) {
return NoPrompt, false
}
if !ok(call(fnRowData, uintptr(row), rowDataSemanticPrompt, uintptr(unsafe.Pointer(&prompt)))) {
prompt = NoPrompt
}
return prompt, ok(call(fnRowData, uintptr(row), rowDataWrap, uintptr(unsafe.Pointer(&wrap)))) && wrap
}
// Hyperlink returns the URI of the hyperlink (OSC 8) of a cell, or "".
func (t *Terminal) Hyperlink(ref GridRef) string {
var buf [512]byte
var n uintptr
r := call(fnGridRefHyperlinkURI, uintptr(unsafe.Pointer(&ref)), uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)), uintptr(unsafe.Pointer(&n)))
if Result(int32(r)) == OutOfSpace && n > 0 {
big := make([]byte, n)
r = call(fnGridRefHyperlinkURI, uintptr(unsafe.Pointer(&ref)), uintptr(unsafe.Pointer(&big[0])), n, uintptr(unsafe.Pointer(&n)))
if !ok(r) {
return ""
}
return string(big[:n])
}
if !ok(r) {
return ""
}
return string(buf[:n])
}
// SetSelection selects s, or nothing when s is nil.
func (t *Terminal) SetSelection(s *Selection) {
t.set(21, unsafe.Pointer(s))
}
// ExtendSelection moves the selection's logical end to ref, keeping its
// original anchor even for a reversed selection. Read a fresh snapshot:
// grid references cannot be kept across output, scrolling or resizing.
func (t *Terminal) ExtendSelection(ref GridRef) bool {
s := Selection{size: unsafe.Sizeof(Selection{})}
if t.get(31, unsafe.Pointer(&s)) != nil {
return false
}
s.end, s.rectangle = ref, false
return t.set(21, unsafe.Pointer(&s)) == nil
}
// SelectAll returns a selection of everything, scrollback included.
func (t *Terminal) SelectAll() (Selection, bool) {
s := Selection{size: unsafe.Sizeof(Selection{})}
return s, ok(call(fnSelectAll, t.h, uintptr(unsafe.Pointer(&s))))
}
// SelectionText returns the text of the selection, with soft-wrapped lines
// joined and trailing spaces trimmed, as Ghostty copies it.
func (t *Terminal) SelectionText() (string, bool) {
var p, n uintptr
opts := selectionFormatOptions{size: unsafe.Sizeof(selectionFormatOptions{}), unwrap: true, trim: true}
if selectionFormatAlloc(t.h, 0, opts, &p, &n) != 0 {
return "", false
}
s := goString(p, n)
if p != 0 {
call(fnFree, 0, p, n)
}
return s, true
}
// Text returns the text of the screen and its scrollback, with
// soft-wrapped lines joined and trailing spaces trimmed.
func (t *Terminal) Text() string {
opts := formatterOptions{size: unsafe.Sizeof(formatterOptions{}), unwrap: true, trim: true}
opts.extra.size = unsafe.Sizeof(opts.extra)
opts.extra.screen.size = unsafe.Sizeof(opts.extra.screen)
var f uintptr
if formatterTerminalNew(0, &f, t.h, opts) != 0 {
return ""
}
defer call(fnFormatterFree, f)
var p, n uintptr
if !ok(call(fnFormatterFormatAlloc, f, 0, uintptr(unsafe.Pointer(&p)), uintptr(unsafe.Pointer(&n)))) {
return ""
}
s := goString(p, n)
if p != 0 {
call(fnFree, 0, p, n)
}
return s
}
// formatVT is GHOSTTY_FORMATTER_FORMAT_VT: text with escape sequences.
const formatVT = 1
// VT returns the terminal's state as escape sequences, which restore it in
// a terminal of the same size: the scrollback and the screen with their
// styles and hyperlinks, then the modes, the scrolling region, the tab
// stops, the working directory, the keyboard's flags and the cursor. The
// palette is left out, as the terminal it restores in has colors of its
// own.
func (t *Terminal) VT() []byte {
opts := formatterOptions{size: unsafe.Sizeof(formatterOptions{}), emit: formatVT}
x := &opts.extra
x.size = unsafe.Sizeof(opts.extra)
x.modes, x.scrollingRegion, x.tabstops, x.pwd, x.keyboard = true, true, true, true, true
x.screen.size = unsafe.Sizeof(opts.extra.screen)
x.screen.cursor, x.screen.style, x.screen.hyperlink, x.screen.protection, x.screen.kittyKeyboard, x.screen.charsets = true, true, true, true, true, true
var f uintptr
if formatterTerminalNew(0, &f, t.h, opts) != 0 {
return nil
}
defer call(fnFormatterFree, f)
var p, n uintptr
if !ok(call(fnFormatterFormatAlloc, f, 0, uintptr(unsafe.Pointer(&p)), uintptr(unsafe.Pointer(&n)))) {
return nil
}
b := []byte(goString(p, n))
if p != 0 {
call(fnFree, 0, p, n)
}
return t.padRows(b)
}
// padRows adds the blank rows at the end of the screen, which the
// formatter leaves out, to the rows of a VT snapshot. Without them, the
// rows written scroll fewer into the scrollback of the terminal they are
// replayed in: what was scrollback shows on the screen, as after clear,
// and the cursor, on a blank row under the last one written, lands on
// that row, whose text what is written next overwrites. The rows end
// where the snapshot places the cursor, one "\r\n" after the other.
func (t *Terminal) padRows(b []byte) []byte {
_, rows := t.Size()
total := int(t.Scrollbar().Total)
if total <= rows || t.AltScreen() {
// No scrollback, or a full-screen program's screen, which has
// none: the cursor's position alone places it.
return b
}
x, y := t.Cursor()
end := bytes.LastIndex(b, fmt.Appendf(nil, "\x1b[%d;%dH", y+1, x+1))
if end < 0 {
return b
}
pad := total - (bytes.Count(b[:end], []byte("\r\n")) + 1)
if pad <= 0 {
return b
}
return slices.Concat(b[:end], bytes.Repeat([]byte("\r\n"), pad), b[end:])
}
// Compress compresses some of the scrollback, as when the terminal is
// idle, and reports whether more is left to compress.
func (t *Terminal) Compress() bool {
var r int32
if !ok(call(fnTerminalCompress, t.h, 0, uintptr(unsafe.Pointer(&r)))) {
return false
}
return r == 1
}
// Activity returns a token that changes when the scrollback may compress.
func (t *Terminal) Activity() uint64 {
var v uint64
call(fnTerminalCompressionActivity, t.h, uintptr(unsafe.Pointer(&v)))
return v
}
func clamp16(v int) int { return max(1, min(v, 0xFFFF)) }
// The callbacks of every terminal, made once: purego's are never freed.
var (
cbWritePTY, cbBell, cbTitleChanged, cbPwdChanged, cbRenderHold, cbClipboardWrite, cbClipboardRead, cbSize,
cbColorScheme, cbDeviceAttributes, cbDesktopNotification, cbProgressReport, cbNoRead uintptr
)
func makeCallbacks() {
// A GhosttyMimeReader for PasteEvent, which the library never calls
// (it reads nothing for an event); it gives no data if it did.
cbNoRead = newCallback(func(_, _, _, _, _ uintptr) uintptr { return 0 })
cbWritePTY = newCallback(func(_, id, data, n uintptr) uintptr {
if t := terminalOf(id); t != nil && t.effects.WritePTY != nil && n > 0 {
p := unsafe.Slice((*byte)(mem(data)), n)
if d := t.deferred; d != nil {
// A deferred read: what the library writes now is its
// refusal, which the read's answer replaces.
t.deferred = nil
if d.setRefusal(p) {
return 0
}
}
if t.silent && bytes.HasPrefix(p, []byte("\x1b]5522;type=read:status=EPERM")) {
// The refusal of a read that goes unanswered: the library
// writes it as the read's callback returns without a reply.
t.silent = false
return 0
}
if t.reply != nil {
*t.reply = append(*t.reply, p...)
return 0
}
t.effects.WritePTY(p)
}
return 0
})
cbClipboardRead = newCallback(func(_, id, req uintptr) uintptr {
r := (*clipboardRead)(mem(req))
t := terminalOf(id)
if t == nil || t.effects.ClipboardRead == nil {
return 0 // refused by the library
}
var in ClipboardRead
in.List, in.Primary, in.Granted, in.CanRemember = r.list, r.location != 0, r.granted, r.canRemember
for _, m := range unsafe.Slice((*cString)(mem(r.mimes)), r.mimesLen) {
in.Mimes = append(in.Mimes, goString(m.ptr, m.len))
}
out, answer := t.effects.ClipboardRead(in)
switch answer {
case ClipboardAnswered:
reply := clipboardReadReply{size: unsafe.Sizeof(clipboardReadReply{}), result: 1} // denied
var contents []clipboardContent
var available []cString
var keep [][]byte
for _, m := range in.Mimes {
if data, ok := out.Contents[m]; ok && len(data) > 0 {
contents = append(contents, clipboardContent{mime: cStringOf(m, &keep), data: cBytes(data)})
}
}
for _, m := range out.Available {
available = append(available, cStringOf(m, &keep))
}
if len(contents) > 0 || in.List && len(available) > 0 {
reply.result = 0
if len(contents) > 0 {
reply.contents, reply.contentsLen = uintptr(unsafe.Pointer(&contents[0])), uintptr(len(contents))
}
if len(available) > 0 {
reply.available, reply.availableLen = uintptr(unsafe.Pointer(&available[0])), uintptr(len(available))
}
}
var written []byte
t.reply = &written
call(r.reply, req, uintptr(unsafe.Pointer(&reply)))
t.reply = nil
if len(written) > 0 && t.effects.WritePTY != nil {
t.effects.WritePTY(written)
}
runtime.KeepAlive(keep)
runtime.KeepAlive(out)
runtime.KeepAlive(contents)
runtime.KeepAlive(available)
case ClipboardDeferred:
d := out.Deferred
if d != nil {
d.mimes, d.list, d.primary = in.Mimes, in.List, in.Primary
t.deferred = d
return 0
}
fallthrough
default: // ClipboardRefused: the library writes the refusal itself.
t.silent = true
}
return 0
})
cbBell = newCallback(func(_, id uintptr) uintptr {
if t := terminalOf(id); t != nil && t.effects.Bell != nil {
t.effects.Bell()
}
return 0
})
cbTitleChanged = newCallback(func(_, id uintptr) uintptr {
if t := terminalOf(id); t != nil && t.effects.TitleChanged != nil {
t.effects.TitleChanged()
}
return 0
})
cbPwdChanged = newCallback(func(_, id uintptr) uintptr {
if t := terminalOf(id); t != nil && t.effects.PwdChanged != nil {
t.effects.PwdChanged()
}
return 0
})
cbRenderHold = newCallback(func(_, id, held uintptr) uintptr {
if t := terminalOf(id); t != nil && t.effects.RenderHold != nil {
t.effects.RenderHold(cbool(held))
}
return 0
})
cbClipboardWrite = newCallback(func(_, id, req uintptr) uintptr {
w := (*clipboardWrite)(mem(req))
reply := clipboardWriteReply{size: unsafe.Sizeof(clipboardWriteReply{}), result: 1} // denied
t := terminalOf(id)
if t != nil && t.effects.Clipboard != nil {
// No contents clears the clipboard; otherwise the first plain
// text, else the first text of another kind, is written.
text, found := "", w.contentsLen == 0
for _, c := range unsafe.Slice((*clipboardContent)(mem(w.contents)), w.contentsLen) {
mime := goString(c.mime.ptr, c.mime.len)
if strings.HasPrefix(mime, "text/plain") || strings.HasPrefix(mime, "text/") && !found {
text, found = goString(c.data.ptr, c.data.len), true
}
}
switch {
case !found:
reply.result = 2 // unsupported
case t.effects.Clipboard(text, w.location != 0):
reply.result = 0
}
}
call(w.reply, req, uintptr(unsafe.Pointer(&reply)))
return 0
})
cbSize = newCallback(func(_, id, out uintptr) uintptr {
t := terminalOf(id)
if t == nil || t.effects.Size == nil {
return 0
}
cols, rows, cw, ch := t.effects.Size()
*(*sizeReport)(mem(out)) = sizeReport{rows: uint16(clamp16(rows)), columns: uint16(clamp16(cols)), cellWidth: uint32(max(cw, 1)), cellHeight: uint32(max(ch, 1))}
return 1
})
cbColorScheme = newCallback(func(_, id, out uintptr) uintptr {
t := terminalOf(id)
if t == nil || t.effects.Dark == nil {
return 0
}
v := int32(0)
if t.effects.Dark() {
v = 1
}
*(*int32)(mem(out)) = v
return 1
})
cbDeviceAttributes = newCallback(func(_, id, out uintptr) uintptr {
// As Ghostty answers: a VT220 with ANSI colors (DA1), of type 1
// and version 10 (DA2).
da := (*deviceAttributes)(mem(out))
*da = deviceAttributes{conformance: 62, numFeatures: 1, deviceType: 1, firmware: 10}
da.features[0] = 22
return 1
})
cbDesktopNotification = newCallback(func(_, id, req uintptr) uintptr {
if t := terminalOf(id); t != nil && t.effects.Notify != nil {
n := (*desktopNotification)(mem(req))
t.effects.Notify(goString(n.title.ptr, n.title.len), goString(n.body.ptr, n.body.len))
}
return 0
})
cbProgressReport = newCallback(func(_, id, req uintptr) uintptr {
if t := terminalOf(id); t != nil && t.effects.Progress != nil {
p := (*progressReport)(mem(req))
t.effects.Progress(int(p.state), int(p.progress))
}
return 0
})
}
// cStringOf points a GhosttyString at a copy of s, kept in keep for as
// long as the library may read it.
func cStringOf(s string, keep *[][]byte) cString {
if s == "" {
return cString{}
}
b := []byte(s)
*keep = append(*keep, b)
return cBytes(b)
}
// cBytes points a GhosttyString at b, which must stay alive and unchanged
// while the library reads it.
func cBytes(b []byte) cString {
if len(b) == 0 {
return cString{}
}
return cString{ptr: uintptr(unsafe.Pointer(&b[0])), len: uintptr(len(b))}
}
+357
View File
@@ -0,0 +1,357 @@
package vt
import "unsafe"
// RGB is a GhosttyColorRgb.
type RGB struct{ R, G, B uint8 }
// styleColor is a GhosttyStyleColor: a tag and, after padding, a union of a
// palette index and an RGB color.
type styleColor struct {
tag int32
_ int32
value [8]byte
}
const (
colorNone = 0
colorPalette = 1
colorRGB = 2
)
// style is a GhosttyStyle.
type style struct {
size uintptr
fg, bg, underlineColor styleColor
bold, italic, faint, blink, inverse, invisible, strikethrough, overline bool
underline int32
}
// renderCursor is a GhosttyRenderStateCursor.
type renderCursor struct {
size uintptr
viewportHasValue bool
viewportX, viewportY uint16
wideTail, visible, blinking, passwordInput bool
visualStyle int32
}
// renderColors is a GhosttyRenderStateColors.
type renderColors struct {
size uintptr
background, foreground, cursor RGB
cursorHasValue bool
palette [256]RGB
}
// rowSelection is a GhosttyRenderStateRowSelection.
type rowSelection struct {
size uintptr
startX, endX uint16
}
// cellsView is a GhosttyCellsView.
type cellsView struct {
ptr, len uintptr
}
// cString is a GhosttyString.
type cString struct {
ptr, len uintptr
}
// Scrollbar is a GhosttyTerminalScrollbar: the rows of the screen and its
// scrollback, the first row of the viewport and how many rows it shows.
type Scrollbar struct {
Total, Offset, Len uint64
}
// scrollViewport is a GhosttyTerminalScrollViewport.
type scrollViewport struct {
tag int32
_ int32
value [2]uint64
}
// modeConfig is a GhosttyTerminalModeConfig.
type modeConfig struct {
mode uint16
value bool
}
// GridRef is a GhosttyGridRef: a cell of the terminal, valid until the
// terminal next changes.
type GridRef struct {
size uintptr
node uintptr
x, y uint16
}
// point is a GhosttyPoint whose value is a coordinate.
type point struct {
tag int32
_ int32
x uint16
_ uint16
y uint32
_ uint64
}
// Selection is a GhosttySelection: two cells of the terminal, inclusive,
// valid until the terminal next changes.
type Selection struct {
size uintptr
start, end GridRef
rectangle bool
}
// selectionFormatOptions is a GhosttyTerminalSelectionFormatOptions.
type selectionFormatOptions struct {
size uintptr
emit int32
unwrap bool
trim bool
selection uintptr
}
// formatterOptions is a GhosttyFormatterTerminalOptions, with its extras
// (GhosttyFormatterTerminalExtra and GhosttyFormatterScreenExtra).
type formatterOptions struct {
size uintptr
emit int32
unwrap bool
trim bool
extra formatterExtra
selection uintptr
}
type formatterExtra struct {
size uintptr
palette, modes, scrollingRegion, tabstops, pwd, keyboard bool
screen struct {
size uintptr
cursor, style, hyperlink, protection, kittyKeyboard, charsets bool
}
}
// mouseEncoderSize is a GhosttyMouseEncoderSize.
type mouseEncoderSize struct {
size uintptr
screenWidth, screenHeight, cellWidth, cellHeight uint32
paddingTop, paddingBottom, paddingRight, paddingLeft uint32
}
// mousePosition is a GhosttyMousePosition.
type mousePosition struct{ x, y float32 }
// gestureGeometry is a GhosttySelectionGestureGeometry.
type gestureGeometry struct {
columns, cellWidth, paddingLeft, screenHeight uint32
}
// surfacePosition is a GhosttySurfacePosition.
type surfacePosition struct{ x, y float64 }
// sizeReport is a GhosttySizeReportSize.
type sizeReport struct {
rows, columns uint16
cellWidth, cellHeight uint32
}
// clipboardWrite is a GhosttyClipboardWrite.
type clipboardWrite struct {
size uintptr
location int32
contents uintptr
contentsLen uintptr
name cString
granted, canRemember bool
ctx, reply uintptr
}
// clipboardContent is a GhosttyClipboardContent.
type clipboardContent struct {
mime, data cString
}
// clipboardWriteReply is a GhosttyClipboardWriteReply.
type clipboardWriteReply struct {
size uintptr
result int32
remember bool
}
// clipboardRead is a GhosttyClipboardRead.
type clipboardRead struct {
size uintptr
location int32
mimes uintptr
mimesLen uintptr
list bool
name cString
granted, canRemember bool
ctx, reply uintptr
}
// clipboardReadReply is a GhosttyClipboardReadReply.
type clipboardReadReply struct {
size uintptr
result int32
contents uintptr
contentsLen uintptr
available uintptr
availableLen uintptr
remember bool
}
// paste is a GhosttyPaste: what a paste offers the program.
type paste struct {
size uintptr
location int32
source int32
mimes uintptr
mimesLen uintptr
reader mimeReader
allowUnsafe bool
}
// mimeReader is a GhosttyMimeReader.
type mimeReader struct {
read, userdata uintptr
}
// desktopNotification is a GhosttyTerminalDesktopNotification.
type desktopNotification struct {
size uintptr
title, body cString
}
// progressReport is a GhosttyTerminalProgressReport.
type progressReport struct {
size uintptr
state int32
progress int8
}
// deviceAttributes is a GhosttyDeviceAttributes.
type deviceAttributes struct {
conformance uint16
features [64]uint16
numFeatures uintptr
deviceType, firmware, romCartridge uint16
unitID uint32
}
// RowID identifies a row across render state updates (a
// GhosttyRenderStateRowId).
type RowID struct{ bits [2]uint64 }
func layouts() map[string]layout {
var (
ri renderInfo
si sysImage
sc styleColor
s style
c renderCursor
rc renderColors
rs rowSelection
cv cellsView
sb Scrollbar
sv scrollViewport
mc modeConfig
gr GridRef
pt point
sel Selection
sbu selectionBuffer
sfo selectionFormatOptions
mes mouseEncoderSize
cw clipboardWrite
cc clipboardContent
cwr clipboardWriteReply
cr clipboardRead
crr clipboardReadReply
pa paste
dn desktopNotification
pr progressReport
da deviceAttributes
fo formatterOptions
)
return map[string]layout{
"GhosttyColorRgb": {unsafe.Sizeof(RGB{}), map[string]uintptr{"r": 0, "g": 1, "b": 2}},
"GhosttyStyleColor": {unsafe.Sizeof(sc), map[string]uintptr{"tag": 0, "value": unsafe.Offsetof(sc.value)}},
"GhosttyStyle": {unsafe.Sizeof(s), map[string]uintptr{
"fg_color": unsafe.Offsetof(s.fg), "bg_color": unsafe.Offsetof(s.bg), "underline_color": unsafe.Offsetof(s.underlineColor),
"bold": unsafe.Offsetof(s.bold), "italic": unsafe.Offsetof(s.italic), "faint": unsafe.Offsetof(s.faint),
"blink": unsafe.Offsetof(s.blink), "inverse": unsafe.Offsetof(s.inverse), "invisible": unsafe.Offsetof(s.invisible),
"strikethrough": unsafe.Offsetof(s.strikethrough), "overline": unsafe.Offsetof(s.overline), "underline": unsafe.Offsetof(s.underline),
}},
"GhosttyRenderStateCursor": {unsafe.Sizeof(c), map[string]uintptr{
"viewport_has_value": unsafe.Offsetof(c.viewportHasValue), "viewport_x": unsafe.Offsetof(c.viewportX),
"viewport_y": unsafe.Offsetof(c.viewportY), "wide_tail": unsafe.Offsetof(c.wideTail), "visible": unsafe.Offsetof(c.visible),
"blinking": unsafe.Offsetof(c.blinking), "password_input": unsafe.Offsetof(c.passwordInput), "visual_style": unsafe.Offsetof(c.visualStyle),
}},
"GhosttyRenderStateColors": {unsafe.Sizeof(rc), map[string]uintptr{
"background": unsafe.Offsetof(rc.background), "foreground": unsafe.Offsetof(rc.foreground), "cursor": unsafe.Offsetof(rc.cursor),
"cursor_has_value": unsafe.Offsetof(rc.cursorHasValue), "palette": unsafe.Offsetof(rc.palette),
}},
"GhosttyRenderStateRowSelection": {unsafe.Sizeof(rs), map[string]uintptr{"start_x": unsafe.Offsetof(rs.startX), "end_x": unsafe.Offsetof(rs.endX)}},
"GhosttyCellsView": {unsafe.Sizeof(cv), map[string]uintptr{"ptr": 0, "len": unsafe.Offsetof(cv.len)}},
"GhosttyString": {unsafe.Sizeof(cString{}), map[string]uintptr{"ptr": 0, "len": unsafe.Offsetof(cString{}.len)}},
"GhosttyTerminalScrollbar": {unsafe.Sizeof(sb), map[string]uintptr{"total": 0, "offset": unsafe.Offsetof(sb.Offset), "len": unsafe.Offsetof(sb.Len)}},
"GhosttyTerminalScrollViewport": {unsafe.Sizeof(sv), map[string]uintptr{"tag": 0, "value": unsafe.Offsetof(sv.value)}},
"GhosttyTerminalModeConfig": {unsafe.Sizeof(mc), map[string]uintptr{"mode": 0, "value": unsafe.Offsetof(mc.value)}},
"GhosttyGridRef": {unsafe.Sizeof(gr), map[string]uintptr{"node": unsafe.Offsetof(gr.node), "x": unsafe.Offsetof(gr.x), "y": unsafe.Offsetof(gr.y)}},
"GhosttyPoint": {unsafe.Sizeof(pt), map[string]uintptr{"tag": 0, "value": unsafe.Offsetof(pt.x)}},
"GhosttyPointCoordinate": {8, map[string]uintptr{"x": unsafe.Offsetof(pt.x) - unsafe.Offsetof(pt.x), "y": unsafe.Offsetof(pt.y) - unsafe.Offsetof(pt.x)}},
"GhosttySelection": {unsafe.Sizeof(sel), map[string]uintptr{"start": unsafe.Offsetof(sel.start), "end": unsafe.Offsetof(sel.end), "rectangle": unsafe.Offsetof(sel.rectangle)}},
"GhosttySelectionBuffer": {unsafe.Sizeof(sbu), map[string]uintptr{"ptr": 0, "cap": unsafe.Offsetof(sbu.cap), "len": unsafe.Offsetof(sbu.len)}},
"GhosttyTerminalSelectionFormatOptions": {unsafe.Sizeof(sfo), map[string]uintptr{
"emit": unsafe.Offsetof(sfo.emit), "unwrap": unsafe.Offsetof(sfo.unwrap), "trim": unsafe.Offsetof(sfo.trim), "selection": unsafe.Offsetof(sfo.selection),
}},
"GhosttyMouseEncoderSize": {unsafe.Sizeof(mes), map[string]uintptr{
"screen_width": unsafe.Offsetof(mes.screenWidth), "screen_height": unsafe.Offsetof(mes.screenHeight),
"cell_width": unsafe.Offsetof(mes.cellWidth), "cell_height": unsafe.Offsetof(mes.cellHeight),
"padding_top": unsafe.Offsetof(mes.paddingTop), "padding_left": unsafe.Offsetof(mes.paddingLeft),
}},
"GhosttyMousePosition": {unsafe.Sizeof(mousePosition{}), map[string]uintptr{"x": 0, "y": 4}},
"GhosttyKittyGraphicsPlacementRenderInfo": {unsafe.Sizeof(ri), map[string]uintptr{
"pixel_width": unsafe.Offsetof(ri.pixelWidth), "grid_rows": unsafe.Offsetof(ri.gridRows),
"viewport_col": unsafe.Offsetof(ri.viewportCol), "viewport_visible": unsafe.Offsetof(ri.viewportVisible),
"source_x": unsafe.Offsetof(ri.sourceX), "source_height": unsafe.Offsetof(ri.sourceH),
}},
"GhosttySysImage": {unsafe.Sizeof(si), map[string]uintptr{"width": 0, "height": 4, "data": unsafe.Offsetof(si.data), "data_len": unsafe.Offsetof(si.dataLen)}},
"GhosttySelectionGestureGeometry": {unsafe.Sizeof(gestureGeometry{}), map[string]uintptr{"columns": 0, "cell_width": 4, "padding_left": 8, "screen_height": 12}},
"GhosttySurfacePosition": {unsafe.Sizeof(surfacePosition{}), map[string]uintptr{"x": 0, "y": 8}},
"GhosttySizeReportSize": {unsafe.Sizeof(sizeReport{}), map[string]uintptr{"rows": 0, "columns": 2, "cell_width": 4, "cell_height": 8}},
"GhosttyClipboardWrite": {unsafe.Sizeof(cw), map[string]uintptr{
"location": unsafe.Offsetof(cw.location), "contents": unsafe.Offsetof(cw.contents), "contents_len": unsafe.Offsetof(cw.contentsLen),
"name": unsafe.Offsetof(cw.name), "granted": unsafe.Offsetof(cw.granted), "ctx": unsafe.Offsetof(cw.ctx), "reply": unsafe.Offsetof(cw.reply),
}},
"GhosttyClipboardContent": {unsafe.Sizeof(cc), map[string]uintptr{"mime": 0, "data": unsafe.Offsetof(cc.data)}},
"GhosttyClipboardWriteReply": {unsafe.Sizeof(cwr), map[string]uintptr{"result": unsafe.Offsetof(cwr.result), "remember": unsafe.Offsetof(cwr.remember)}},
"GhosttyClipboardRead": {unsafe.Sizeof(cr), map[string]uintptr{
"location": unsafe.Offsetof(cr.location), "mimes": unsafe.Offsetof(cr.mimes), "mimes_len": unsafe.Offsetof(cr.mimesLen),
"list": unsafe.Offsetof(cr.list), "name": unsafe.Offsetof(cr.name), "granted": unsafe.Offsetof(cr.granted),
"can_remember": unsafe.Offsetof(cr.canRemember), "ctx": unsafe.Offsetof(cr.ctx), "reply": unsafe.Offsetof(cr.reply),
}},
"GhosttyClipboardReadReply": {unsafe.Sizeof(crr), map[string]uintptr{
"result": unsafe.Offsetof(crr.result), "contents": unsafe.Offsetof(crr.contents), "contents_len": unsafe.Offsetof(crr.contentsLen),
"available": unsafe.Offsetof(crr.available), "available_len": unsafe.Offsetof(crr.availableLen), "remember": unsafe.Offsetof(crr.remember),
}},
"GhosttyPaste": {unsafe.Sizeof(pa), map[string]uintptr{
"location": unsafe.Offsetof(pa.location), "source": unsafe.Offsetof(pa.source), "mimes": unsafe.Offsetof(pa.mimes),
"mimes_len": unsafe.Offsetof(pa.mimesLen), "reader": unsafe.Offsetof(pa.reader), "allow_unsafe": unsafe.Offsetof(pa.allowUnsafe),
}},
"GhosttyMimeReader": {unsafe.Sizeof(mimeReader{}), map[string]uintptr{"read": 0, "userdata": unsafe.Offsetof(mimeReader{}.userdata)}},
"GhosttyTerminalDesktopNotification": {unsafe.Sizeof(dn), map[string]uintptr{"title": unsafe.Offsetof(dn.title), "body": unsafe.Offsetof(dn.body)}},
"GhosttyTerminalProgressReport": {unsafe.Sizeof(pr), map[string]uintptr{"state": unsafe.Offsetof(pr.state), "progress": unsafe.Offsetof(pr.progress)}},
"GhosttyDeviceAttributes": {unsafe.Sizeof(da), map[string]uintptr{"primary": 0, "secondary": unsafe.Offsetof(da.deviceType), "tertiary": unsafe.Offsetof(da.unitID)}},
"GhosttyRenderStateRowId": {unsafe.Sizeof(RowID{}), map[string]uintptr{"bits": 0}},
"GhosttyFormatterTerminalOptions": {unsafe.Sizeof(fo), map[string]uintptr{
"emit": unsafe.Offsetof(fo.emit), "unwrap": unsafe.Offsetof(fo.unwrap), "trim": unsafe.Offsetof(fo.trim),
"extra": unsafe.Offsetof(fo.extra), "selection": unsafe.Offsetof(fo.selection),
}},
"GhosttyFormatterTerminalExtra": {unsafe.Sizeof(fo.extra), map[string]uintptr{"keyboard": unsafe.Offsetof(fo.extra.keyboard), "screen": unsafe.Offsetof(fo.extra.screen)}},
"GhosttyFormatterScreenExtra": {unsafe.Sizeof(fo.extra.screen), map[string]uintptr{"charsets": unsafe.Offsetof(fo.extra.screen.charsets)}},
}
}
+662
View File
@@ -0,0 +1,662 @@
package vt
import (
"bytes"
"encoding/base64"
"os"
"strings"
"testing"
"github.com/egoist/mygo/plugins/terminal/internal/library"
)
// loadLib loads the libghostty-vt of the terminal plugin, which it
// downloads into the user's cache when missing, or the one
// $MYGO_GHOSTTY_VT names; -short skips the tests then.
func loadLib(t *testing.T) {
t.Helper()
if testing.Short() && os.Getenv("MYGO_GHOSTTY_VT") == "" {
t.Skip("downloads libghostty-vt")
}
manifest, err := os.ReadFile("../../mygo-plugin.json")
if err != nil {
t.Fatal(err)
}
path, err := library.Find(manifest)
if err != nil {
t.Fatal(err)
}
if err := Load(path); err != nil {
t.Fatal(err)
}
}
func rowText(r *RenderState) []string {
var rows []string
r.Rows()
for r.NextRow() {
var b strings.Builder
for _, c := range r.RowCells() {
if c.Codepoint == 0 {
b.WriteByte(' ')
} else if c.Wide != SpacerTail {
b.WriteRune(c.Codepoint)
}
}
rows = append(rows, strings.TrimRight(b.String(), " "))
}
return rows
}
func TestTerminal(t *testing.T) {
loadLib(t)
var replies []string
var titled bool
term, err := NewTerminal(20, 5, Effects{
WritePTY: func(p []byte) { replies = append(replies, string(p)) },
TitleChanged: func() { titled = true },
})
if err != nil {
t.Fatal(err)
}
defer term.Free()
term.Write([]byte("Hello, \x1b[1;32mworld\x1b[0m!\r\nsecond line\x1b]2;the title\x07\x1b[6n"))
if want := []string{"\x1b[2;12R"}; strings.Join(replies, "") != want[0] {
t.Errorf("replies = %q, want %q", replies, want)
}
if !titled || term.Title() != "the title" {
t.Errorf("title = %q (changed %v)", term.Title(), titled)
}
r, err := NewRenderState()
if err != nil {
t.Fatal(err)
}
defer r.Free()
if err := r.Update(term); err != nil {
t.Fatal(err)
}
if cols, rows := r.Size(); cols != 20 || rows != 5 {
t.Errorf("size = %d×%d", cols, rows)
}
if got := rowText(r); got[0] != "Hello, world!" || got[1] != "second line" {
t.Errorf("rows = %q", got)
}
r.Rows()
r.NextRow()
cells := r.RowCells()
if cells[7].Style == 0 {
t.Fatal("w has the default style")
}
s := r.CellStyle(7)
if !s.Bold || s.FG != (Color{Kind: 1, Index: 2}) {
t.Errorf("style of w = %+v", s)
}
if got := term.Text(); got != "Hello, world!\nsecond line" {
t.Errorf("text = %q", got)
}
if c := r.Cursor(); !c.InView || c.X != 11 || c.Y != 1 {
t.Errorf("cursor = %+v", c)
}
}
func TestWideAndGraphemes(t *testing.T) {
loadLib(t)
term, _ := NewTerminal(10, 2, Effects{})
defer term.Free()
term.Write([]byte("\x1b[?2027h世👍🏽"))
r, _ := NewRenderState()
defer r.Free()
r.Update(term)
r.Rows()
r.NextRow()
cells := r.RowCells()
if cells[0].Codepoint != '世' || cells[0].Wide != WideChar || cells[1].Wide != SpacerTail {
t.Errorf("cells = %+v", cells[:2])
}
if !cells[2].Grapheme {
t.Fatalf("cell 2 = %+v", cells[2])
}
if got := string(r.CellGraphemes(2, nil)); got != "👍🏽" {
t.Errorf("graphemes = %q", got)
}
}
// The rows of a shell's prompt (OSC 133): where it starts, and those its
// input wraps onto, which the terminal and a render state tell alike.
func TestRowPrompt(t *testing.T) {
loadLib(t)
term, _ := NewTerminal(10, 5, Effects{})
defer term.Free()
term.Write([]byte("out\r\n\x1b]133;A\a$ \x1b]133;B\aecho hello world"))
want := []struct {
prompt RowPrompt
wrap bool
}{{NoPrompt, false}, {PromptStart, true}, {PromptContinuation, false}, {NoPrompt, false}}
r, _ := NewRenderState()
defer r.Free()
r.Update(term)
r.Rows()
for y, w := range want {
r.NextRow()
if p, wrap := term.Row(y); p != w.prompt || wrap != w.wrap {
t.Errorf("row %d is %d, wrapping %v; want %d, %v", y, p, wrap, w.prompt, w.wrap)
}
if p := r.RowPrompt(); p != w.prompt {
t.Errorf("render state's row %d is %d, want %d", y, p, w.prompt)
}
}
if p, _ := term.Row(99); p != NoPrompt {
t.Errorf("row 99 is %d", p)
}
}
func TestEncoders(t *testing.T) {
loadLib(t)
term, _ := NewTerminal(80, 24, Effects{})
defer term.Free()
k, err := NewKeyEncoder()
if err != nil {
t.Fatal(err)
}
defer k.Free()
k.Sync(term, false)
for _, c := range []struct {
ev KeyEvent
want string
}{
{KeyEvent{Action: KeyPress, Key: KeyEnter}, "\r"},
{KeyEvent{Action: KeyPress, Key: KeyC, Mods: ModCtrl, Unshifted: 'c'}, "\x03"},
{KeyEvent{Action: KeyPress, Key: KeyArrowUp}, "\x1b[A"},
{KeyEvent{Action: KeyPress, Key: KeyA, Text: "a", Unshifted: 'a'}, "a"},
{KeyEvent{Action: KeyPress, Key: KeyA, Mods: ModShift, Consumed: ModShift, Text: "A", Unshifted: 'a'}, "A"},
{KeyEvent{Action: KeyRelease, Key: KeyA, Unshifted: 'a'}, ""},
{KeyEvent{Action: KeyPress, Key: KeyEscape}, "\x1b"},
{KeyEvent{Action: KeyPress, Key: KeyF1}, "\x1bOP"},
} {
if got := string(k.Encode(c.ev)); got != c.want {
t.Errorf("Encode(%+v) = %q, want %q", c.ev, got, c.want)
}
}
term.Write([]byte("\x1b[?1h"))
k.Sync(term, false)
if got := string(k.Encode(KeyEvent{Action: KeyPress, Key: KeyArrowUp})); got != "\x1bOA" {
t.Errorf("up in cursor key mode = %q", got)
}
m, err := NewMouseEncoder()
if err != nil {
t.Fatal(err)
}
defer m.Free()
m.Sync(term, 800, 480, 10, 20, 0, 0, false)
if got := m.Encode(MousePress, ButtonLeft, 0, 5, 5); got != nil {
t.Errorf("press without tracking = %q", got)
}
term.Write([]byte("\x1b[?1000h\x1b[?1006h"))
m.Sync(term, 800, 480, 10, 20, 0, 0, false)
if got := string(m.Encode(MousePress, ButtonLeft, 0, 25, 45)); got != "\x1b[<0;3;3M" {
t.Errorf("press = %q", got)
}
if got := string(m.Encode(MouseRelease, ButtonLeft, 0, 25, 45)); got != "\x1b[<0;3;3m" {
t.Errorf("release = %q", got)
}
if got := string(EncodeFocus(true)); got != "\x1b[I" {
t.Errorf("focus = %q", got)
}
if got := string(EncodePaste("a\nb", false)); got != "a\rb" {
t.Errorf("paste = %q", got)
}
if got := string(EncodePaste("a\nb", true)); got != "\x1b[200~a\nb\x1b[201~" {
t.Errorf("bracketed paste = %q", got)
}
if PasteIsSafe("rm -rf /\n") || !PasteIsSafe("ls") {
t.Error("PasteIsSafe")
}
}
func TestSelection(t *testing.T) {
loadLib(t)
term, _ := NewTerminal(20, 3, Effects{})
defer term.Free()
term.Write([]byte("hello world\r\nsecond"))
g, err := NewGesture(500e6, 5)
if err != nil {
t.Fatal(err)
}
defer g.Free(term)
geo := Geometry{Columns: 20, CellWidth: 10, Height: 60}
a, _ := term.CellAt(0, 0)
g.Press(term, a, 2, 5, 1)
b, _ := term.CellAt(4, 0)
s, ok := g.Drag(term, b, 46, 5, geo, false)
if !ok {
t.Fatal("no selection")
}
term.SetSelection(&s)
g.Release(term, &b)
if text, ok := term.SelectionText(); !ok || text != "hello" {
t.Errorf("selection = %q, %v", text, ok)
}
// A double click selects the word.
c, _ := term.CellAt(7, 0)
g.Press(term, c, 72, 5, 600e6)
g.Release(term, &c)
s, ok = g.Press(term, c, 72, 5, 700e6)
if !ok {
t.Fatal("double click selected nothing")
}
term.SetSelection(&s)
if text, _ := term.SelectionText(); text != "world" {
t.Errorf("word = %q", text)
}
all, _ := term.SelectAll()
term.SetSelection(&all)
if text, _ := term.SelectionText(); text != "hello world\nsecond" {
t.Errorf("all = %q", text)
}
term.SetSelection(nil)
if _, ok := term.SelectionText(); ok {
t.Error("selection after clearing it")
}
}
func TestScrollback(t *testing.T) {
loadLib(t)
term, _ := NewTerminal(10, 3, Effects{})
defer term.Free()
for i := range 10 {
term.Write([]byte(strings.Repeat(string(rune('0'+i)), 3) + "\r\n"))
}
sb := term.Scrollbar()
if sb.Total != 11 || sb.Len != 3 || sb.Offset != 8 || !term.AtBottom() {
t.Errorf("scrollbar = %+v", sb)
}
term.ScrollBy(-2)
if term.AtBottom() || term.Scrollbar().Offset != 6 {
t.Errorf("after scrolling up: %+v", term.Scrollbar())
}
r, _ := NewRenderState()
defer r.Free()
r.Update(term)
if got := rowText(r); got[0] != "666" {
t.Errorf("rows = %q", got)
}
term.ScrollToBottom()
if !term.AtBottom() {
t.Error("not at the bottom")
}
term.Resize(5, 3, 10, 20)
if cols, rows := term.Size(); cols != 5 || rows != 3 {
t.Errorf("size = %d×%d", cols, rows)
}
}
// The keyboard's modes a Mirror passes on: modifyOtherKeys follows CSI > 4
// alone, not the pointer shape (OSC 22), and the Kitty keyboard flags
// their own sequences.
func TestKeyboardModes(t *testing.T) {
loadLib(t)
term, _ := NewTerminal(20, 3, Effects{})
defer term.Free()
if term.ModifyOtherKeys() {
t.Error("modifyOtherKeys on in a new terminal")
}
term.Write([]byte("\x1b]22;pointer\x1b\\"))
if term.MouseShape() != 3 || term.ModifyOtherKeys() {
t.Errorf("after OSC 22: shape %d, modifyOtherKeys %v", term.MouseShape(), term.ModifyOtherKeys())
}
term.Write([]byte("text\x1b[>4;2m"))
if !term.ModifyOtherKeys() {
t.Error("modifyOtherKeys off after CSI > 4 ; 2 m")
}
term.Write([]byte("\x1b[>4;1m"))
if term.ModifyOtherKeys() {
t.Error("modifyOtherKeys on after CSI > 4 ; 1 m")
}
term.Write([]byte("\x1b[>5u"))
if f := term.KittyKeyboardFlags(); f != 5 {
t.Errorf("kitty keyboard flags %d, want 5", f)
}
// A sequence split across writes sets it, with the Kitty protocol on
// as well; a reset of the key formats, and of the terminal, clears it.
term.Write([]byte("\x1b[>4"))
term.Write([]byte(";2m"))
if !term.ModifyOtherKeys() {
t.Error("modifyOtherKeys off after a split CSI > 4 ; 2 m")
}
for _, reset := range []string{"\x1b[>m", "\x1b[>4n", "\x1bc"} {
term.Write([]byte("\x1b[>4;2m" + reset))
if term.ModifyOtherKeys() {
t.Errorf("modifyOtherKeys on after %q", reset)
}
}
term.Write([]byte("\x1b[>4;2m"))
term.Reset()
if term.ModifyOtherKeys() {
t.Error("modifyOtherKeys on after Reset")
}
}
// A search finds text in the scrollback and on the screen, ignoring the
// case of ASCII letters; selecting goes from the newest match to older
// ones, scrolling to them, and the viewport's matches are where it shows.
func TestSearch(t *testing.T) {
loadLib(t)
term, _ := NewTerminal(20, 3, Effects{})
defer term.Free()
for i := range 10 {
line := "line"
if i%3 == 0 {
line = "an Error here"
}
term.Write([]byte(line + "\r\n"))
}
s, err := NewSearch(term)
if err != nil {
t.Fatal(err)
}
defer s.Free()
run := func() {
for range 1000 {
switch s.Tick() {
case SearchComplete:
return
case SearchFeedRequired:
s.Feed()
}
}
t.Fatal("the search never completed")
}
s.SetText("error")
run()
if n := s.Total(); n != 4 {
t.Fatalf("total = %d, want 4", n)
}
if _, ok := s.Selected(); ok {
t.Error("a match is selected before any was")
}
text := func() string {
m, ok := s.SelectedMatch()
if !ok {
return ""
}
term.SetSelection(&m)
got, _ := term.SelectionText()
term.SetSelection(nil)
return got
}
if !s.Select(false) {
t.Fatal("nothing to select")
}
if i, _ := s.Selected(); i != 0 || text() != "Error" {
t.Errorf("selected %d %q", i, text())
}
// The next, row 6, is above the screen: selecting it scrolls nothing,
// and its row is where to scroll.
s.Select(false)
m, _ := s.SelectedMatch()
a, _ := m.Ends()
row, ok := term.ScreenRow(a)
if i, _ := s.Selected(); i != 1 || !term.AtBottom() || !ok || row != 6 {
t.Errorf("selected %d at row %d (%v), at the bottom: %v", i, row, ok, term.AtBottom())
}
if _, _, shown := term.ViewportPoint(a); shown {
t.Error("a match above the viewport shows")
}
term.ScrollToRow(row)
s.Feed()
var shown int
for _, m := range s.ViewportMatches(nil) {
a, b := m.Ends()
x0, y0, ok0 := term.ViewportPoint(a)
x1, y1, ok1 := term.ViewportPoint(b)
if ok0 && ok1 && y0 < 3 {
shown++
if x0 != 3 || x1 != 7 || y0 != y1 {
t.Errorf("match at %d,%d–%d,%d", x0, y0, x1, y1)
}
}
}
if shown != 1 {
t.Errorf("%d matches show, want 1", shown)
}
s.Select(true)
s.Select(true)
if i, _ := s.Selected(); i != 3 {
t.Errorf("selected %d after wrapping back, want 3", i)
}
s.SetText("")
run()
if s.Total() != 0 {
t.Errorf("total = %d with no text", s.Total())
}
}
// A paste with mode 5522 set tells the program what the clipboard holds;
// the program's read with the event's password is granted and served in
// chunks; a terminal that does not answer a read stays silent.
func TestPasteEvent(t *testing.T) {
loadLib(t)
png := bytes.Repeat([]byte("\x89PNG\r\n\x1a\n0123456789"), 500) // over two chunks
var out bytes.Buffer
term, err := NewTerminal(80, 24, Effects{
WritePTY: func(p []byte) { out.Write(p) },
ClipboardRead: func(req ClipboardRead) (ClipboardReply, ClipboardAnswer) {
if !req.Granted {
return ClipboardReply{}, ClipboardRefused
}
return ClipboardReply{Contents: map[string][]byte{"image/png": png, "text/plain": []byte("hi")}}, ClipboardAnswered
},
})
if err != nil {
t.Fatal(err)
}
defer term.Free()
if term.PasteEvent([]string{"text/plain", "image/png"}) {
t.Fatal("an event without the mode")
}
term.Write([]byte("\x1b[?5522h"))
if !term.PasteEvent([]string{"text/plain", "image/png"}) {
t.Fatal("no event with the mode")
}
event := out.String()
out.Reset()
// ESC]5522;type=read:status=OK:pw=<b64>ESC\ ... DATA ... DONE
_, after, ok := strings.Cut(event, ":pw=")
if !ok || !strings.Contains(event, "status=DATA:mime=Lg==") || !strings.HasSuffix(event, "status=DONE:pw="+after[:strings.Index(after, "\x1b")]+"\x1b\\") {
t.Fatalf("event = %q", event)
}
pw := after[:strings.Index(after, "\x1b")]
listing, _ := base64.StdEncoding.DecodeString(event[strings.Index(event, "Lg==:pw="+pw+";")+len("Lg==:pw="+pw+";") : strings.Index(event, "\x1b\\\x1b]5522;type=read:status=DONE")])
if string(listing) != "text/plain image/png\n" {
t.Errorf("listing = %q", listing)
}
// The program reads the PNG with the password.
name := base64.StdEncoding.EncodeToString([]byte("Paste event"))
mime := base64.StdEncoding.EncodeToString([]byte("image/png"))
term.Write([]byte("\x1b]5522;type=read:pw=" + pw + ":name=" + name + ";" + mime + "\x1b\\"))
reply := out.String()
out.Reset()
if !strings.HasPrefix(reply, "\x1b]5522;type=read:status=OK\x1b\\") || !strings.HasSuffix(reply, "\x1b]5522;type=read:status=DONE\x1b\\") {
t.Fatalf("reply = %.80q…", reply)
}
var got []byte
for _, pkt := range strings.Split(reply, "\x1b\\") {
if _, data, ok := strings.Cut(pkt, "status=DATA:mime="+mime+";"); ok {
b, err := base64.StdEncoding.DecodeString(data)
if err != nil {
t.Fatal(err)
}
got = append(got, b...)
}
}
if !bytes.Equal(got, png) {
t.Errorf("read %d bytes, want %d", len(got), len(png))
}
// The password is used up: the same read again is not granted, and
// unanswered, which leaves the program nothing at all.
term.Write([]byte("\x1b]5522;type=read:pw=" + pw + ":name=" + name + ";" + mime + "\x1b\\"))
if out.Len() != 0 {
t.Errorf("an unanswered read wrote %q", out.String())
}
// A later query is answered as usual.
term.Write([]byte("\x1b[6n"))
if out.String() != "\x1b[1;1R" {
t.Errorf("after silence, the cursor report = %q", out.String())
}
// A read that writes no refusal (OSC 52's) does not silence the next.
term.Write([]byte("\x1b]52;c;?\x1b\\"))
if term.silent {
t.Error("an OSC 52 read left the terminal silent")
}
}
// A deferred read (ClipboardDeferred) holds the library's refusal back,
// and AnswerClipboard answers it, allowed or denied, with the selector,
// terminator and refusal the library wrote.
func TestDeferredClipboardRead(t *testing.T) {
loadLib(t)
var out bytes.Buffer
var deferred *DeferredClipboardRead
term, err := NewTerminal(80, 24, Effects{
WritePTY: func(p []byte) { out.Write(p) },
ClipboardRead: func(req ClipboardRead) (ClipboardReply, ClipboardAnswer) {
deferred = &DeferredClipboardRead{}
return ClipboardReply{Deferred: deferred}, ClipboardDeferred
},
})
if err != nil {
t.Fatal(err)
}
defer term.Free()
text := map[string][]byte{"text/plain": []byte("hello")}
for _, c := range []struct {
name string
read string
allow bool
contents map[string][]byte
want string
}{
{"allow c", "\x1b]52;c;?\x1b\\", true, text, "\x1b]52;c;aGVsbG8=\x1b\\"},
{"deny c", "\x1b]52;c;?\x1b\\", false, nil, "\x1b]52;c;\x1b\\"},
{"deny s bel", "\x1b]52;s;?\x07", false, nil, "\x1b]52;s;\x07"},
{"allow p", "\x1b]52;p;?\x1b\\", true, text, "\x1b]52;p;aGVsbG8=\x1b\\"},
{"allow empty", "\x1b]52;c;?\x1b\\", true, nil, "\x1b]52;c;\x1b\\"},
} {
out.Reset()
deferred = nil
term.Write([]byte(c.read))
if out.Len() != 0 {
t.Fatalf("%s: a deferred read wrote %q before it was answered", c.name, out.String())
}
if deferred == nil {
t.Fatalf("%s: the read was not deferred", c.name)
}
term.AnswerClipboard(deferred, c.allow, c.contents, nil)
if got := out.String(); got != c.want {
t.Errorf("%s: answered %q, want %q", c.name, got, c.want)
}
}
// A nil handle answers nothing.
out.Reset()
term.AnswerClipboard(nil, true, text, nil)
if out.Len() != 0 {
t.Errorf("a nil deferred read wrote %q", out.String())
}
}
// A deferred Kitty protocol read is answered exactly as the library would
// answer a reply: compare a read answered synchronously with the same read
// deferred and answered through AnswerClipboard, for an id, a listing,
// chunks, and a denial.
func TestDeferredClipboardReadKitty(t *testing.T) {
loadLib(t)
png := bytes.Repeat([]byte("\x89PNG\r\n\x1a\n0123456789"), 300) // over one 4096-byte chunk
contents := map[string][]byte{"image/png": png, "text/plain": []byte("hi")}
available := []string{"text/plain", "image/png"}
b64 := func(s string) string { return base64.StdEncoding.EncodeToString([]byte(s)) }
want := func(t *testing.T, read string, req func(ClipboardRead) (ClipboardReply, ClipboardAnswer)) string {
t.Helper()
var out bytes.Buffer
term, err := NewTerminal(80, 24, Effects{
WritePTY: func(p []byte) { out.Write(p) },
ClipboardRead: req,
})
if err != nil {
t.Fatal(err)
}
defer term.Free()
term.Write([]byte(read))
return out.String()
}
for _, c := range []struct {
name string
read string
reply ClipboardReply
deny bool
}{
{"plain", "\x1b]5522;type=read;" + b64("text/plain") + "\x1b\\", ClipboardReply{Contents: contents}, false},
{"id", "\x1b]5522;type=read:id=abc.123;" + b64("text/plain") + "\x1b\\", ClipboardReply{Contents: contents}, false},
{"listing", "\x1b]5522;type=read:id=9;" + b64("text/plain image/png .") + "\x1b\\", ClipboardReply{Contents: contents, Available: available}, false},
{"listing only", "\x1b]5522;type=read;Lg==\x1b\\", ClipboardReply{Available: available}, false},
{"primary", "\x1b]5522;type=read:loc=primary:id=x;dGV4dC9wbGFpbg==\x1b\\", ClipboardReply{Contents: contents}, false},
{"bel", "\x1b]5522;type=read:id=7;" + b64("text/plain") + "\x07", ClipboardReply{Contents: contents}, false},
{"deny", "\x1b]5522;type=read:id=d;" + b64("text/plain") + "\x1b\\", ClipboardReply{}, true},
} {
sync := want(t, c.read, func(req ClipboardRead) (ClipboardReply, ClipboardAnswer) {
return c.reply, ClipboardAnswered
})
var deferred *DeferredClipboardRead
out := &bytes.Buffer{}
term, err := NewTerminal(80, 24, Effects{
WritePTY: func(p []byte) { out.Write(p) },
ClipboardRead: func(req ClipboardRead) (ClipboardReply, ClipboardAnswer) {
deferred = &DeferredClipboardRead{}
return ClipboardReply{Deferred: deferred}, ClipboardDeferred
},
})
if err != nil {
t.Fatal(err)
}
term.Write([]byte(c.read))
if out.Len() != 0 {
t.Fatalf("%s: a deferred read wrote %q before it was answered", c.name, out.String())
}
term.AnswerClipboard(deferred, !c.deny, c.reply.Contents, c.reply.Available)
term.Free()
if got := out.String(); got != sync {
t.Errorf("%s: deferred %q, synchronous %q", c.name, got, sync)
}
if sync == "" {
t.Errorf("%s: the library answered nothing", c.name)
}
}
// A listing the clipboard has nothing for is still sent, as the
// library's own encoder writes it.
var listing *DeferredClipboardRead
out := &bytes.Buffer{}
term, err := NewTerminal(80, 24, Effects{
WritePTY: func(p []byte) { out.Write(p) },
ClipboardRead: func(req ClipboardRead) (ClipboardReply, ClipboardAnswer) {
listing = &DeferredClipboardRead{}
return ClipboardReply{Deferred: listing}, ClipboardDeferred
},
})
if err != nil {
t.Fatal(err)
}
term.Write([]byte("\x1b]5522;type=read;Lg==\x1b\\"))
term.AnswerClipboard(listing, true, nil, nil)
term.Free()
wantEmpty := "\x1b]5522;type=read:status=OK\x1b\\" +
"\x1b]5522;type=read:status=DATA:mime=Lg==\x1b\\" +
"\x1b]5522;type=read:status=DONE\x1b\\"
if got := out.String(); got != wantEmpty {
t.Errorf("an empty listing: %q, want %q", got, wantEmpty)
}
}
+195
View File
@@ -0,0 +1,195 @@
package terminal
import (
"runtime"
"github.com/egoist/mygo/ui"
)
// Action is what a key bound to it does (Keybind), as an action of
// Ghostty's keybind option.
type Action int
const (
// ActionNone unbinds a key, which then goes to the program, as
// Ghostty's unbind.
ActionNone Action = iota
// ActionIgnore takes the key and does nothing, as Ghostty's ignore.
ActionIgnore
// ActionCopy copies the selection, as copy_to_clipboard. It does
// something only with a selection, and when Performable it also lets
// go of it, so that the key's next press reaches the program, as
// Windows Terminal's Control+C.
ActionCopy
// ActionPaste pastes the clipboard, as paste_from_clipboard: as the
// view's Paste does (see Options.OnPaste). It does something only when
// the clipboard holds something.
ActionPaste
// ActionSelectAll selects the scrollback and the screen, as
// select_all.
ActionSelectAll
// ActionClearScreen clears the scrollback and the screen above the
// cursor's line, which moves to the top, as clear_screen (and Kitty's
// clear_terminal to_cursor). It does nothing on a full-screen
// program's screen (the alternate screen), which it would break.
ActionClearScreen
// ActionIncreaseFontSize, ActionDecreaseFontSize and
// ActionResetFontSize zoom a step in or out, or back to the font's
// size, as increase_font_size:1, decrease_font_size:1 and
// reset_font_size (see Options.OnZoom).
ActionIncreaseFontSize
ActionDecreaseFontSize
ActionResetFontSize
// ActionScrollPageUp, ActionScrollPageDown, ActionScrollToTop and
// ActionScrollToBottom scroll the scrollback, as scroll_page_up,
// scroll_page_down, scroll_to_top and scroll_to_bottom. They do
// nothing on a full-screen program's screen, which has none.
ActionScrollPageUp
ActionScrollPageDown
ActionScrollToTop
ActionScrollToBottom
)
// Keybind binds a key, with exactly Mods held, to an action, as a line of
// Ghostty's keybind option: the view does the action instead of sending
// the key to the program. Key follows the keyboard layout, as ui.Key
// does.
//
// Performable, as Ghostty's performable: prefix, takes the key only when
// the action does something: Control+C copies a selection, and without
// one goes on to the program, which it interrupts. A key the action leaves
// goes on as if unbound.
type Keybind struct {
Mods ui.Modifiers
Key ui.Key
Action Action
Performable bool
}
// DefaultKeybinds returns the keys a terminal binds unless
// Options.NoDefaultKeybinds, which are Ghostty's of the platform:
//
// - on macOS, Command+C copies and Command+V pastes, Command+A selects
// all, Command+K clears the screen, Command+= (and +) and Command+-
// zoom, and Command+0 zooms back; Command+Home, End, Page Up and
// Page Down scroll, as do Shift+Page Up and Page Down;
// - elsewhere, Control+Shift+C and Control+Insert copy, Control+Shift+V
// and Shift+Insert paste, Control+Shift+A selects all, Control+= (and
// +), Control+- and Control+0 zoom, and Shift+Page Up and Page Down
// scroll, as do Shift+Home and End on Linux;
// - on Windows, also Windows Terminal's: Control+C copies when there is a
// selection (performable), Control+V pastes when the clipboard holds
// something (performable), Control+Shift+K clears the screen, and
// Control+Shift+Home, End, Page Up and Page Down scroll.
//
// The keys that clear the screen and scroll are performable: a
// full-screen program, as an editor, gets them.
func DefaultKeybinds() []Keybind {
return defaultKeybinds(runtime.GOOS)
}
func defaultKeybinds(goos string) []Keybind {
var b []Keybind
bind := func(mods ui.Modifiers, key ui.Key, a Action) {
b = append(b, Keybind{Mods: mods, Key: key, Action: a})
}
performable := func(mods ui.Modifiers, key ui.Key, a Action) {
b = append(b, Keybind{Mods: mods, Key: key, Action: a, Performable: true})
}
scroll := func(mods ui.Modifiers) {
performable(mods, ui.KeyPageUp, ActionScrollPageUp)
performable(mods, ui.KeyPageDown, ActionScrollPageDown)
performable(mods, ui.KeyHome, ActionScrollToTop)
performable(mods, ui.KeyEnd, ActionScrollToBottom)
}
if goos == "darwin" {
cmd := ui.Super
bind(cmd, ui.KeyC, ActionCopy)
bind(cmd, ui.KeyV, ActionPaste)
bind(cmd, ui.KeyA, ActionSelectAll)
performable(cmd, ui.KeyK, ActionClearScreen)
bind(cmd, ui.KeyEqual, ActionIncreaseFontSize)
bind(cmd|ui.Shift, ui.KeyEqual, ActionIncreaseFontSize)
bind(cmd, ui.KeyMinus, ActionDecreaseFontSize)
bind(cmd, ui.Key0, ActionResetFontSize)
scroll(cmd)
performable(ui.Shift, ui.KeyPageUp, ActionScrollPageUp)
performable(ui.Shift, ui.KeyPageDown, ActionScrollPageDown)
return b
}
// The first key of an action is the one menus show.
bind(ui.Ctrl|ui.Shift, ui.KeyC, ActionCopy)
bind(ui.Ctrl|ui.Shift, ui.KeyV, ActionPaste)
bind(ui.Ctrl, ui.KeyInsert, ActionCopy)
bind(ui.Shift, ui.KeyInsert, ActionPaste)
bind(ui.Ctrl|ui.Shift, ui.KeyA, ActionSelectAll)
bind(ui.Ctrl, ui.KeyEqual, ActionIncreaseFontSize)
bind(ui.Ctrl|ui.Shift, ui.KeyEqual, ActionIncreaseFontSize)
bind(ui.Ctrl, ui.KeyMinus, ActionDecreaseFontSize)
bind(ui.Ctrl, ui.Key0, ActionResetFontSize)
if goos != "windows" {
scroll(ui.Shift)
return b
}
// Windows Terminal's, which leaves Shift+Home and End to the shell,
// as PowerShell selects with them.
performable(ui.Ctrl, ui.KeyC, ActionCopy)
performable(ui.Ctrl, ui.KeyV, ActionPaste)
performable(ui.Ctrl|ui.Shift, ui.KeyK, ActionClearScreen)
performable(ui.Shift, ui.KeyPageUp, ActionScrollPageUp)
performable(ui.Shift, ui.KeyPageDown, ActionScrollPageDown)
scroll(ui.Ctrl | ui.Shift)
return b
}
// keybinds returns the bindings of opts: its Keybinds over the defaults,
// each replacing those of its key, in order, the defaults first.
func keybinds(opts *Options) []Keybind {
var b []Keybind
if !opts.NoDefaultKeybinds {
b = DefaultKeybinds()
}
for _, k := range opts.Keybinds {
kept := b[:0]
for _, o := range b {
if o.Mods != k.Mods || o.Key != k.Key {
kept = append(kept, o)
}
}
b = kept
if k.Action != ActionNone {
b = append(b, k)
}
}
return b
}
// binding returns the binding of a key.
func (t *Terminal) binding(mods ui.Modifiers, key ui.Key) (Keybind, bool) {
for _, b := range t.binds {
if b.Mods == mods && b.Key == key {
return b, true
}
}
return Keybind{}, false
}
// shortcut returns the key a menu item of an action shows: its first
// binding that always takes the key, as Ghostty's menus show no
// performable one, else its first.
func (t *Terminal) shortcut(a Action) (Keybind, bool) {
var found Keybind
ok := false
for _, b := range t.binds {
if b.Action != a {
continue
}
if !b.Performable {
return b, true
}
if !ok {
found, ok = b, true
}
}
return found, ok
}
+87
View File
@@ -0,0 +1,87 @@
package terminal
import (
"unicode"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
"github.com/egoist/mygo/ui"
)
// keys maps MyGo's keys to Ghostty's, and to the character they type
// without modifiers, which MyGo's keys name (KeyA types an a).
var keys = map[ui.Key]struct {
key vt.Key
r rune
}{
ui.KeyEnter: {vt.KeyEnter, '\r'}, ui.KeyEscape: {vt.KeyEscape, 0}, ui.KeyBackspace: {vt.KeyBackspace, 0},
ui.KeyTab: {vt.KeyTab, '\t'}, ui.KeySpace: {vt.KeySpace, ' '}, ui.KeyDelete: {vt.KeyDelete, 0},
ui.KeyInsert: {vt.KeyInsert, 0}, ui.KeyHome: {vt.KeyHome, 0}, ui.KeyEnd: {vt.KeyEnd, 0},
ui.KeyPageUp: {vt.KeyPageUp, 0}, ui.KeyPageDown: {vt.KeyPageDown, 0},
ui.KeyLeft: {vt.KeyArrowLeft, 0}, ui.KeyRight: {vt.KeyArrowRight, 0}, ui.KeyUp: {vt.KeyArrowUp, 0}, ui.KeyDown: {vt.KeyArrowDown, 0},
ui.KeyMinus: {vt.KeyMinus, '-'}, ui.KeyEqual: {vt.KeyEqual, '='}, ui.KeyComma: {vt.KeyComma, ','},
ui.KeyPeriod: {vt.KeyPeriod, '.'}, ui.KeySlash: {vt.KeySlash, '/'}, ui.KeySemicolon: {vt.KeySemicolon, ';'},
ui.KeyQuote: {vt.KeyQuote, '\''}, ui.KeyBracketLeft: {vt.KeyBracketLeft, '['}, ui.KeyBracketRight: {vt.KeyBracketRight, ']'},
ui.KeyBackslash: {vt.KeyBackslash, '\\'}, ui.KeyBackquote: {vt.KeyBackquote, '`'}, ui.KeyContextMenu: {vt.KeyContextMenu, 0},
}
func init() {
for i := range 12 {
keys[ui.KeyF1+ui.Key(i)] = struct {
key vt.Key
r rune
}{vt.KeyF1 + vt.Key(i), 0}
}
for i := range 10 {
keys[ui.Key0+ui.Key(i)] = struct {
key vt.Key
r rune
}{vt.KeyDigit0 + vt.Key(i), '0' + rune(i)}
}
for i := range 26 {
keys[ui.KeyA+ui.Key(i)] = struct {
key vt.Key
r rune
}{vt.KeyA + vt.Key(i), 'a' + rune(i)}
}
}
// vtKey returns Ghostty's key for k, and the character it types without
// modifiers (0 for keys that type none).
func vtKey(k ui.Key) (vt.Key, rune) {
m := keys[k]
return m.key, m.r
}
// typesText reports whether a key types text, rather than moving or
// erasing: the text comes after it.
func typesText(k ui.Key) bool {
_, r := vtKey(k)
return r > ' ' || k == ui.KeySpace
}
// keyOfRune returns the key that types r, and whether it takes Shift, on
// a US keyboard, for text that came without its key, as on Linux.
func keyOfRune(r rune) (vt.Key, rune, bool) {
if r < 0x80 {
lower := unicode.ToLower(r)
for k, m := range keys {
if m.r == lower && m.r > ' ' || k == ui.KeySpace && r == ' ' {
return m.key, m.r, lower != r
}
}
if i := shifted[r]; i != 0 {
return keys[i].key, keys[i].r, true
}
}
return vt.KeyUnidentified, 0, false
}
// shifted are the keys of the symbols Shift types on a US keyboard.
var shifted = map[rune]ui.Key{
'!': ui.Key1, '@': ui.Key2, '#': ui.Key3, '$': ui.Key4, '%': ui.Key5, '^': ui.Key6, '&': ui.Key7, '*': ui.Key8,
'(': ui.Key9, ')': ui.Key0, '_': ui.KeyMinus, '+': ui.KeyEqual, '<': ui.KeyComma, '>': ui.KeyPeriod,
'?': ui.KeySlash, ':': ui.KeySemicolon, '"': ui.KeyQuote, '{': ui.KeyBracketLeft, '}': ui.KeyBracketRight,
'|': ui.KeyBackslash, '~': ui.KeyBackquote,
}
func vtMods(m ui.Modifiers) vt.Mods { return vt.Mods(m) } // the same bits
+56
View File
@@ -0,0 +1,56 @@
package terminal
import (
_ "embed"
"fmt"
"runtime"
"sync"
"github.com/egoist/mygo/plugins/terminal/internal/library"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
)
//go:generate go run ./internal/libbuild
// natives describes the builds of libghostty-vt this package binds, one
// per platform, which `mygo build` and `mygo dev` put into apps: the CLI
// reads this file from the package's directory.
//
//go:embed mygo-plugin.json
var natives []byte
var load struct {
once sync.Once
path string
err error
}
// Load loads libghostty-vt, once, from LibraryPath. New calls it; call it
// earlier to report a missing library before showing a terminal.
func Load() error {
load.once.Do(func() {
if !vt.Supported {
load.err = fmt.Errorf("terminal: not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
return
}
load.path, load.err = LibraryPath()
if load.err == nil {
load.err = vt.Load(load.path)
}
})
return load.err
}
// LibraryPath returns the libghostty-vt the terminal loads, the first of:
//
// - the file $MYGO_GHOSTTY_VT names;
// - the one among the app's resources (mygo.PathResources), where `mygo
// build` and `mygo dev` put it, signed with the app on macOS;
// - the one next to the executable;
// - the one in the user's cache, where the CLI downloads it
// (<cache>/mygo/natives/<sha256>/), which programs that are not
// packaged apps, as under `go run` and `go test`, download there when
// it is missing, checking its SHA-256.
//
// Packaged apps never download it: build them with the CLI.
func LibraryPath() (string, error) { return library.Find(natives) }
+264
View File
@@ -0,0 +1,264 @@
package terminal
import (
"regexp"
"strconv"
"strings"
"unicode"
"unicode/utf8"
)
// urlPattern finds the URLs programs print as text, which a Command+click
// opens as it does hyperlinks. A URL sends what is not ASCII encoded, so it
// ends at the first such character: the CJK text or full-width punctuation
// that often follows one without a space.
var urlPattern = regexp.MustCompile(`(?:(?:https?|ftp|file)://|mailto:)[^\s"'<>` + "`" + `\x00-\x1f\x7f-\x{10ffff}]+`)
// proseDelimiters end a path printed in Chinese or Japanese prose, which
// puts no space around it; a quoted path may hold them.
const proseDelimiters = ",。;:!?、()【】《》「」『』"
// pathToken finds what may be a file path programs print as text, unquoted:
// a run of anything but spaces, quotes and proseDelimiters.
var pathToken = regexp.MustCompile(`[^\s"'<>` + "`" + proseDelimiters + `]+`)
// pathInToken finds a path inside a token that is not one as a whole, as
// main.go:12 in grep's main.go:12:code, build/app.js in --out=build/app.js
// or /usr/bin in PATH=/usr/bin:/bin.
var pathInToken = regexp.MustCompile(`(?:(?:~|\.{1,2})?/[^\s:]+|[\p{L}\p{N}_.@+-]+(?:/[\p{L}\p{N}_.@+-]+)+/?)(?::\d+(?::\d+)?)?|[\p{L}\p{N}_@+-][\p{L}\p{N}_.@+-]*\.[\p{L}\p{N}_]+(?::\d+(?::\d+)?)?`)
// quotedPlace finds the place after a quoted path, as "main.py":12.
var quotedPlace = regexp.MustCompile(`^:\d+(?::\d+)?`)
// pathPlace finds the place in the file a path ends with: :line or
// :line:col (compilers, grep), (line,col) (TypeScript, MSBuild), or #Lline
// or #LlineCcol (GitHub).
var pathPlace = regexp.MustCompile(`:(\d+)(?::(\d+))?:?$|\((\d+)(?:,(\d+))?\)$|#L(\d+)(?:C(\d+))?$`)
// pathAt returns the file path of text at column col, as urlAt, or "":
// absolute, from ~, ./ or ../, with a slash, or a file name with an
// extension or a line; the place in the file is written path:line:col
// however it was printed, and a quoted path loses its quotes.
func pathAt(text []rune, cols []int, col int) (path string, x0, x1 int) {
s := string(text)
span := func(a, b int) (int, int, bool) {
start := utf8.RuneCountInString(s[:a])
end := start + utf8.RuneCountInString(s[a:b])
if end > start && end <= len(cols) && cols[start] <= col && col <= cols[end-1] {
return cols[start], cols[end-1] + 1, true
}
return 0, 0, false
}
// A quoted path first, as it may hold spaces and what the tokens below
// end at.
for i := 0; i < len(s); i++ {
a, b := quotedAt(s, i)
if b < 0 {
continue
}
p, pa, pb := pathOf(s[a:b])
if p == "" {
continue
}
if x0, x1, ok := span(a+pa, a+pb); ok {
return p, x0, x1
}
i = b - 1
}
for _, m := range pathToken.FindAllStringIndex(s, -1) {
tok := s[m[0]:m[1]]
if p, a, b := pathOf(tok); p != "" {
if x0, x1, ok := span(m[0]+a, m[0]+b); ok {
return p, x0, x1
}
continue
}
for _, n := range pathInToken.FindAllStringIndex(tok, -1) {
if p, a, b := pathOf(tok[n[0]:n[1]]); p != "" {
if x0, x1, ok := span(m[0]+n[0]+a, m[0]+n[0]+b); ok {
return p, x0, x1
}
}
}
}
return "", 0, 0
}
// quotedAt returns the bytes of s, a up to b, of a quoted run that opens at
// byte i and the place after it, or b < 0. A quote between letters or digits,
// as in don't, is an apostrophe and opens or closes nothing, and the inside
// of a quoted path neither starts nor ends with a space.
func quotedAt(s string, i int) (a, b int) {
q := s[i]
if q != '"' && q != '\'' || i > 0 && isAlnum(s[i-1]) {
return 0, -1
}
j := strings.IndexByte(s[i+1:], q)
if j < 0 {
return 0, -1
}
j += i + 1
inner := s[i+1 : j]
if inner == "" || strings.ContainsAny(inner, "\r\n") || strings.TrimSpace(inner) != inner {
return 0, -1
}
b = j + 1
b += len(quotedPlace.FindString(s[b:]))
if b < len(s) && isAlnum(s[b]) {
return 0, -1
}
return i, b
}
// isAlnum reports whether c is an ASCII letter or digit.
func isAlnum(c byte) bool {
return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9'
}
// pathOf returns the path a token of pathToken, or a quoted run, prints,
// and the bytes of the token it shows in, a up to b, or "".
func pathOf(tok string) (path string, a, b int) {
a, b = 0, len(tok)
quoted := tok[0] == '"' || tok[0] == '\''
if !quoted {
// Brackets and emphasis around a path are not part of it, nor is
// the call a path is the argument of, as write(notes.md); a bracket
// the path opens is, as icon_(copy).png.
a = len(tok) - len(strings.TrimLeft(tok, "([{*"))
// The name of an option or a variable the path is the value of,
// as --out=build/app.js or PATH=/usr/bin, is not part of it.
if i := strings.IndexByte(tok[a:], '='); i >= 0 && !strings.Contains(tok[a:a+i], "/") {
a += i + 1
}
b = a + len(balanced(tok[a:]))
if strings.HasSuffix(tok[a:b], ")") && !pathPlace.MatchString(tok[a:b]) {
if i := opening(tok[a:b]); i > 0 {
a, b = a+i+1, b-1
}
}
for b > a && strings.IndexByte(",;.!?]", tok[b-1]) >= 0 {
b--
}
if !pathPlace.MatchString(tok[a:b]) {
b = a + len(trimURL(tok[a:b]))
}
if b <= a {
return "", 0, 0
}
}
name, line, col := tok[a:b], 0, 0
if loc := pathPlace.FindStringSubmatchIndex(name); loc != nil {
place := name
name = place[:loc[0]]
for i := 2; i < len(loc); i += 4 {
if loc[i] >= 0 {
line, _ = strconv.Atoi(place[loc[i]:loc[i+1]])
if loc[i+2] >= 0 {
col, _ = strconv.Atoi(place[loc[i+2]:loc[i+3]])
}
break
}
}
if strings.HasSuffix(place, ":") {
b-- // the colon after main.go:12:3: ends a compiler's location
}
}
if quoted {
name = name[1 : len(name)-1]
}
if name == "" || strings.ContainsAny(name, ":\x00\r\n") ||
strings.IndexFunc(name, func(r rune) bool { return unicode.IsLetter(r) || unicode.IsDigit(r) }) < 0 {
return "", 0, 0
}
// Words are not paths: a name without a slash takes a letter, and an
// extension or a line, so that version 1.2.3 and 12:30 are neither.
if !strings.Contains(name, "/") {
dot := strings.LastIndexByte(name, '.')
if strings.IndexFunc(name, unicode.IsLetter) < 0 || line == 0 && (dot < 0 || dot == len(name)-1) {
return "", 0, 0
}
}
path = name
if line > 0 {
path += ":" + strconv.Itoa(line)
if col > 0 {
path += ":" + strconv.Itoa(col)
}
}
return path, a, b
}
// balanced returns s up to a closing bracket it did not open, as the ) of
// "(image.png)已保存".
func balanced(s string) string {
var depth [3]int
for i, r := range s {
if k := strings.IndexRune("([{", r); k >= 0 {
depth[k]++
} else if k := strings.IndexRune(")]}", r); k >= 0 {
if depth[k] == 0 {
return s[:i]
}
depth[k]--
}
}
return s
}
// opening returns the index of the ( that opens the ) s ends with, or -1.
func opening(s string) int {
depth := 0
for i := len(s) - 1; i >= 0; i-- {
switch s[i] {
case ')':
depth++
case '(':
if depth--; depth == 0 {
return i
}
}
}
return -1
}
// urlAt returns the URL of text, a row whose runes are in columns cols, at
// column col, and the columns it spans, x0 up to x1, or "".
func urlAt(text []rune, cols []int, col int) (url string, x0, x1 int) {
return matchAt(urlPattern, text, cols, col)
}
func matchAt(re *regexp.Regexp, text []rune, cols []int, col int) (string, int, int) {
s := string(text)
for _, m := range re.FindAllStringIndex(s, -1) {
u := trimURL(s[m[0]:m[1]])
if u == "" {
continue
}
start := len([]rune(s[:m[0]]))
end := start + len([]rune(u))
if start < len(cols) && cols[start] <= col && col <= cols[end-1] {
return u, cols[start], cols[end-1] + 1
}
}
return "", 0, 0
}
// trimURL trims what likely ends the sentence around a URL rather than the
// URL: punctuation, and closing brackets that the URL did not open.
func trimURL(u string) string {
for len(u) > 0 {
switch last := u[len(u)-1]; last {
case '.', ',', ';', ':', '!', '?':
u = u[:len(u)-1]
continue
case ')', ']', '}':
open := map[byte]string{')': "(", ']': "[", '}': "{"}[last]
if strings.Count(u, open) < strings.Count(u, string(last)) {
u = u[:len(u)-1]
continue
}
}
return u
}
return u
}
+61
View File
@@ -0,0 +1,61 @@
package terminal
import (
"strings"
"testing"
)
// Paths as compilers, GitHub and prose in Chinese print them, the place in
// the file written path:line:col however it was printed. Wide characters
// take two columns, as in a terminal.
func TestPathAtPlacesQuotesAndProse(t *testing.T) {
for _, c := range []struct{ row, at, want string }{
{"error: src/main.go:42:5: failed", "main", "src/main.go:42:5"},
{"at (./src/main.ts(12,3))", "main", "./src/main.ts:12:3"},
{"src/app.ts(12): error TS2304", "app", "src/app.ts:12"},
{"see ~/work/中文.go#L8C2", "中文", "~/work/中文.go:8:2"},
{"see src/app.go#L12 for it", "app", "src/app.go:12"},
{`File "/tmp/my project/中文.go":13:2`, "project", "/tmp/my project/中文.go:13:2"},
{`open "/tmp/my notes/a.md" now`, "notes", "/tmp/my notes/a.md"},
{`File '/usr/lib/x y.py', line 7`, "lib", "/usr/lib/x y.py"},
{"文件 src/日本.go:4 有错", "日本", "src/日本.go:4"},
{"已保存新版图标 (assets/branding/terminal-icon.png),使用新版", "terminal", "assets/branding/terminal-icon.png"},
{"terminal-icon.prompt.txt)也已保存。", "prompt", "terminal-icon.prompt.txt"},
{"已保存(assets/branding/中文.png),继续", "中文", "assets/branding/中文.png"},
{"见:src/main.go:42:5,错误", "main", "src/main.go:42:5"},
{"已保存 (assets/icon_(copy).png),继续", "icon", "assets/icon_(copy).png"},
{`文件 "assets/图标(新版),副本.png",已保存`, "新版", "assets/图标(新版),副本.png"},
{"(../README.md),", "README", "../README.md"},
{"Makefile:4", "Make", "Makefile:4"},
{"目录 /tmp/project/", "project", "/tmp/project/"},
{"main.go:0", "main", "main.go"},
{"src/a.go:12:code", "a.go", "src/a.go:12"},
{"--out=build/app.js", "app", "build/app.js"},
{"PATH=/usr/bin:/sbin", "usr", "/usr/bin"},
{"PATH=/usr/bin:/sbin", "sbin", "/sbin"},
{"PATH=/usr/bin:/sbin", "PATH", ""},
{"don't open src/a.go, it's broken", "src", "src/a.go"},
{"don't open src/a.go, it's broken", "open", ""},
{"don't open src/a.go, it's broken", "broken", ""},
{`say " a/b.go " twice`, "a/b", "a/b.go"},
{"meet at 12:30 today", "12", ""},
{"and / or", "/", ""},
{"已保存 (assets/x.png),继续", "保存", ""},
{"已保存 (assets/x.png),继续", ",", ""},
} {
text := []rune(c.row)
cols := make([]int, len(text))
x := 0
for i, r := range text {
cols[i] = x
x++
if r > 0x2fff {
x++
}
}
col := cols[len([]rune(c.row[:strings.Index(c.row, c.at)]))]
if got, _, _ := pathAt(text, cols, col); got != c.want {
t.Errorf("pathAt(%q at %q) = %q, want %q", c.row, c.at, got, c.want)
}
}
}
+102
View File
@@ -0,0 +1,102 @@
package terminal
import (
"strings"
"testing"
)
func TestURLAt(t *testing.T) {
row := "see https://example.com/a_(b)?q=1. and (http://x.org/y), mailto:me@x.org!"
text := []rune(row)
cols := make([]int, len(text))
for i := range cols {
cols[i] = i
}
for col, want := range map[int]string{
0: "",
4: "https://example.com/a_(b)?q=1",
20: "https://example.com/a_(b)?q=1",
33: "", // the period after it
40: "http://x.org/y",
58: "mailto:me@x.org",
} {
if got, _, _ := urlAt(text, cols, col); got != want {
t.Errorf("urlAt(%d) = %q, want %q", col, got, want)
}
}
}
// TestURLAtNotASCII: a URL ends where text that is not ASCII starts, as
// CJK or full-width punctuation after it with no space.
func TestURLAtNotASCII(t *testing.T) {
for row, want := range map[string]string{
"https://example.com/a的说明": "https://example.com/a",
"https://example.com/a,然后": "https://example.com/a",
"见https://example.com/a。": "https://example.com/a",
"(https://example.com/a)": "https://example.com/a",
"https://example.com/%E4%BD%A0": "https://example.com/%E4%BD%A0",
"mailto:me@x.org,谢谢": "mailto:me@x.org",
} {
text := []rune(row)
cols := make([]int, len(text))
for i := range cols {
cols[i] = i
}
col := len([]rune(row[:strings.Index(row, ":")]))
if got, _, _ := urlAt(text, cols, col); got != want {
t.Errorf("urlAt(%q) = %q, want %q", row, got, want)
}
}
}
func TestPathAt(t *testing.T) {
for _, c := range []struct {
row string
col int
want string
}{
{"Updated internal/app/embed.go:51 and more", 10, "internal/app/embed.go:51"},
{" ⎿ Read /Users/me/repo/main.go (12 lines)", 12, "/Users/me/repo/main.go"},
{"see ./notes/todo.txt.", 8, "./notes/todo.txt"},
{"open ~/Downloads/clip.mp4", 10, "~/Downloads/clip.mp4"},
{"main.go:250:3: undefined: x", 2, "main.go:250:3"},
{"(src/a.go)", 3, "src/a.go"},
{"write(notes.md)", 8, "notes.md"},
{"notes.md (new file +2)", 2, "notes.md"},
{"See notes.md.", 7, "notes.md"},
{"notes.md:2:3", 2, "notes.md:2:3"},
{"just words here", 5, ""},
{"version 1.2.3 ok", 9, ""},
} {
text := []rune(c.row)
cols := make([]int, len(text))
for i := range cols {
cols[i] = i
}
if got, _, _ := pathAt(text, cols, c.col); got != c.want {
t.Errorf("pathAt(%q, %d) = %q, want %q", c.row, c.col, got, c.want)
}
}
}
func TestPathAtSpan(t *testing.T) {
text := []rune("write(notes.md)")
cols := make([]int, len(text))
for i := range cols {
cols[i] = i
}
if path, x0, x1 := pathAt(text, cols, 8); path != "notes.md" || x0 != 6 || x1 != 14 {
t.Errorf("pathAt = %q %d..%d, want notes.md 6..14", path, x0, x1)
}
}
func TestURLAtSpan(t *testing.T) {
text := []rune("go to https://x.org/a. now")
cols := make([]int, len(text))
for i := range cols {
cols[i] = i
}
if url, x0, x1 := urlAt(text, cols, 10); url != "https://x.org/a" || x0 != 6 || x1 != 21 {
t.Errorf("urlAt = %q %d..%d, want https://x.org/a 6..21", url, x0, x1)
}
}
+893
View File
@@ -0,0 +1,893 @@
package terminal
import (
"bytes"
"encoding/base64"
"errors"
"fmt"
"slices"
"strconv"
"time"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
)
// Mirror frames what a terminal shows for another terminal to show, as a
// server that keeps a session's terminal sends its clients: Frame returns
// the VT sequences that bring a terminal showing the frames before to what
// this one shows now. The other terminal, as one whose Conn reads the
// frames, then shows this one's screen and scrollback cell for cell, with
// its cursor and the modes that change what it sends (the cursor keys',
// the keyboard protocols', the mouse's, bracketed paste) and the rows of
// a shell's prompt (OSC 133), and never lays out a program's output itself: it cannot come to show something else,
// as a terminal fed the program's output from a snapshot can.
//
// Frames draw rows where they are, and rows that scroll off pass through
// the other terminal's screen in order, so that its scrollback is this
// one's: rows this one's limit lets go of stay there, under its own
// limit. Soft wraps stay soft. The first frame, and a frame after the
// screen took another size, start the other terminal over. A frame does
// not come while a program holds a synchronized update (mode 2026), for up
// to a second, as the view's frames do not: Frame then reports that one
// is due.
//
// Programs' writes to the clipboard (OSC 52) go on to the other terminal
// of each Mirror, and their reads with ClipboardForward to one of them, the
// first to frame, for it to answer.
//
// Frames read the terminal as its view does, which takes the terminal's
// record of what changed since it last read it: a terminal a view shows
// too would not repaint all that changed. A Mirror is for a terminal no
// view shows, as a server's; many Mirrors of one terminal are fine.
type Mirror struct {
t *Terminal
closed bool
// started tells that a frame went; cols and rows are the size it
// drew, alt that it showed the alternate screen.
started bool
cols, rows int
alt bool
// ids are the identities of the rows the last frame showed, which
// rows keep as they scroll; sent is how each was drawn, and main the
// main screen's while the alternate screen shows.
ids []vt.RowID
sent, main [][]byte
// scrollback is how many rows the main screen's scrollback held at the
// last frame that showed the main screen.
scrollback int
// modes, colors, cursor and title are what the last frame set of them.
modes, colors, cursor, title string
// imgs are the images sent of the main and the alternate screens, and
// placement the last id of a placement made.
imgs [2]mirroredImages
placement uint32
// clipOut is what programs copied since the last frame, which each
// Mirror passes on.
clipOut []string
}
// NewMirror returns a Mirror of the terminal, whose first frame starts the
// other terminal over. Close frees it.
func (t *Terminal) NewMirror() (*Mirror, error) {
if !vt.Loaded() {
return nil, errors.New("terminal: libghostty-vt is not loaded")
}
m := &Mirror{t: t}
t.mu.Lock()
t.mirrors = append(t.mirrors, m)
t.mu.Unlock()
return m, nil
}
// Close frees the mirror.
func (m *Mirror) Close() {
t := m.t
t.mu.Lock()
defer t.mu.Unlock()
m.closed = true
m.clipOut = nil
t.mirrors = slices.DeleteFunc(t.mirrors, func(o *Mirror) bool { return o == m })
}
// Reset has the next frame start the other terminal over, as when another
// terminal shows the frames from now.
func (m *Mirror) Reset() {
m.t.mu.Lock()
m.started = false
m.t.mu.Unlock()
}
// Frame returns what brings the other terminal to what this one shows,
// nil when it shows it already; due reports that a frame is due later,
// as one a synchronized update holds back.
func (m *Mirror) Frame() (frame []byte, due bool) {
t := m.t
t.mu.Lock()
defer t.mu.Unlock()
if t.term == nil || m.closed {
return nil, false
}
if t.term.Mode(vt.ModeSyncOutput) && t.held && time.Since(t.heldSince) < time.Second {
return nil, true
}
var out bytes.Buffer
m.frame(&out)
return out.Bytes(), false
}
func (m *Mirror) frame(out *bytes.Buffer) {
t := m.t
term := t.term
cols, rows := term.Size()
alt := term.AltScreen()
scrollback := term.ScrollbackRows()
if !term.AtBottom() {
term.ScrollToBottom()
}
// A render state of its own, each time, copies the terminal whole: one
// kept would copy the rows the terminal marked changed, and the marks
// go to whatever render state reads them first, another Mirror's.
rs, err := vt.NewRenderState()
if err != nil {
return
}
defer rs.Free()
rs.Update(term)
ids := make([]vt.RowID, 0, rows)
screen := make([]line, 0, rows)
rs.Rows()
for y := 0; rs.NextRow(); y++ {
ids = append(ids, rs.RowID())
screen = append(screen, readLine(term, rs, y))
}
top := scrollback // the screen's first row, from the top of the scrollback
if alt {
top = 0
}
switch {
case !m.started || cols != m.cols || rows != m.rows:
m.restart(out, screen, alt, top)
case alt != m.alt && !alt && scrollback != m.scrollback:
// Rows went to the main screen's scrollback before its program
// took the alternate screen, which hid them: start over.
m.restart(out, screen, alt, top)
case alt != m.alt:
if alt {
out.WriteString("\x1b[?1049h")
m.main, m.sent = m.sent, make([][]byte, rows)
} else {
out.WriteString("\x1b[?1049l")
m.sent, m.main = m.main, nil
}
m.redraw(out, screen)
default:
scrolled := 0
if !alt {
scrolled = m.scrolled(ids, scrollback)
}
switch {
case scrolled < 0: // lost track: start over
m.restart(out, screen, alt, top)
case scrolled > 0:
// Rows went to the scrollback: they pass through the other
// screen's top in order, the screen's rows after them. A
// scrollback that holds fewer rows was cleared when none of
// those before them are left: one at its limit lets go of its
// oldest rows instead, which the other terminal keeps, its own
// limit taking them.
if scrollback < m.scrollback && scrollback <= scrolled {
out.WriteString("\x1b[3J")
}
m.write(out, append(m.lines(top-scrolled, top), screen...))
default:
if scrollback < m.scrollback {
out.WriteString("\x1b[3J") // the scrollback was cleared
}
m.redraw(out, screen)
}
}
m.started, m.cols, m.rows, m.alt, m.ids = true, cols, rows, alt, ids
if !alt {
m.scrollback = scrollback
}
m.images(out, term, alt, top, rows)
m.state(out, rs.Cursor())
}
// scrolled returns how many rows scrolled off the screen since the last
// frame, which ids are the rows of now, or -1 when it cannot tell.
func (m *Mirror) scrolled(ids []vt.RowID, scrollback int) int {
if len(ids) == 0 || len(m.ids) == 0 {
return -1
}
k := -1
for i, id := range m.ids {
if id == ids[0] {
k = i
break
}
}
grew := scrollback - m.scrollback
switch {
case k == 0 && grew > 0:
// The screen's rows kept their places, the scrollback grew under
// a full screen's worth of rows: more than a screen scrolled.
return grew
case k >= 0:
return k
}
// More than a screen scrolled: as many rows as are below the last
// frame's first row, now in the scrollback. The scrollback's growth
// tells it too, but for one at its limit, which lets go of rows as it
// takes others.
if n := scrolledPast(m.t.term, m.ids[0], scrollback); n > 0 {
return n
}
if grew > 0 {
return grew
}
return -1
}
// scrolledPast returns how many rows of the scrollback, which holds
// scrollback rows, are below the row id, from the bottom up, a screen's
// worth at a time, or -1 when it holds no such row. It leaves the viewport
// at the bottom.
func scrolledPast(term *vt.Terminal, id vt.RowID, scrollback int) int {
_, rows := term.Size()
defer term.ScrollToBottom()
for y := scrollback; y > 0; {
y = max(y-rows, 0)
term.ScrollToRow(y)
// A render state of its own, as readLines reads.
rs, err := vt.NewRenderState()
if err != nil {
return -1
}
rs.Update(term)
off := int(term.Scrollbar().Offset)
found := -1
rs.Rows()
for i := 0; rs.NextRow(); i++ {
if r := off + i; r < scrollback && found < 0 && rs.RowID() == id {
found = scrollback - r
}
}
rs.Free()
if found >= 0 {
return found
}
y = min(y, off)
}
return -1
}
// restart starts the other terminal over: its scrollback and screen, then
// this one's, row by row.
func (m *Mirror) restart(out *bytes.Buffer, screen []line, alt bool, top int) {
// Both screens' images go too, which frames send again: those sent by
// their ids, as deleting the placements that show (d=A) leaves those
// of the scrollback, which the other terminal keeps over its screen
// once the scrollback is cleared under them.
const noImages = "\x1b_Ga=d,d=A,q=2\x1b\\"
out.WriteString("\x1b[?1049h" + noImages)
m.deleteImages(out, &m.imgs[1])
out.WriteString("\x1b[?1049l" + noImages)
m.deleteImages(out, &m.imgs[0])
out.WriteString("\x1b[0m\x1b[H\x1b[2J\x1b[3J" + markOutput)
m.modes, m.cursor = "", ""
m.imgs = [2]mirroredImages{}
m.sent = make([][]byte, len(screen))
m.main = nil
if alt {
// The main screen of a full-screen program's terminal is not to be
// read: the other one's shows from when the program ends, which
// starts over again, as the other's main screen and scrollback are
// empty now.
m.scrollback = -1
out.WriteString("\x1b[?1049h")
m.redraw(out, screen)
return
}
m.write(out, append(m.lines(0, top), screen...))
}
// lines reads the rows of the scrollback from up to to, counted from its
// top.
func (m *Mirror) lines(from, to int) []line { return readLines(m.t.term, from, to) }
// readLines reads rows from up to to, counted from the top of the
// scrollback, a screen's worth at a time, through the viewport, which it
// leaves at the bottom; each with a render state of its own (see frame).
func readLines(term *vt.Terminal, from, to int) []line {
out := make([]line, 0, max(0, to-from))
if to <= from {
return out
}
_, rows := term.Size()
for y := from; y < to; {
term.ScrollToRow(y)
rs, err := vt.NewRenderState()
if err != nil {
break
}
rs.Update(term)
off := int(term.Scrollbar().Offset)
rs.Rows()
for i := 0; rs.NextRow(); i++ {
if r := off + i; r == from+len(out) && r < to {
out = append(out, readLine(term, rs, i))
}
}
rs.Free()
next := off + rows
if next <= y {
break
}
y = next
}
term.ScrollToBottom()
for len(out) < to-from {
out = append(out, line{}) // not to be read: drawn empty
}
return out
}
// write draws lines one after the other from the other screen's top, so
// that those before the screen's, its last rows, go to its scrollback, as
// they went to this one's.
func (m *Mirror) write(out *bytes.Buffer, lines []line) {
rows := len(m.sent)
screen := len(lines) - rows
// The first lines go over the other screen's rows, the others onto
// rows that scroll in, which have no mark.
was := func(i int) vt.RowPrompt {
if i < rows {
return keyPrompt(m.sent[i])
}
return vt.NoPrompt
}
for i := 1; i < min(rows, len(lines)); i++ {
if lines[i-1].wrap {
premark(out, i, lines[i], was(i))
}
}
out.WriteString("\x1b[H")
for i, l := range lines {
last := i == len(lines)-1
var next *line
if !last {
next = &lines[i+1]
}
k := m.row(out, l, next, i > 0 && lines[i-1].wrap, was(i))
if i >= screen {
m.sent[i-screen] = k
}
if !last && !l.wrap {
out.WriteString("\r\n")
}
}
}
// redraw draws again the rows of the screen that changed, and those of the
// soft-wrapped lines they are in, from their lines' first rows.
func (m *Mirror) redraw(out *bytes.Buffer, screen []line) {
rows := len(screen)
if len(m.sent) != rows {
m.sent = make([][]byte, rows)
}
for y := 0; y < rows; y++ {
if m.sent[y] != nil && bytes.Equal(screen[y].key(), m.sent[y]) {
continue
}
// From the first row of its line, which a soft wrap continues.
s := y
for s > 0 && screen[s-1].wrap {
s--
}
for r := s + 1; r < rows && screen[r-1].wrap; r++ {
premark(out, r, screen[r], keyPrompt(m.sent[r]))
}
fmt.Fprintf(out, "\x1b[%dH", s+1)
for first := s; s < rows; s++ {
var next *line
if s+1 < rows && screen[s].wrap {
next = &screen[s+1]
}
m.sent[s] = m.row(out, screen[s], next, s > first, keyPrompt(m.sent[s]))
if next == nil {
break
}
}
y = s
}
}
// row draws a line from the cursor's column 0: in full, clearing what was
// after it, or, soft wrapped into next, out to its last column for the
// other terminal to wrap it too. A row is cleared before it is drawn, but
// for one a soft wrap continues, cont, which starts with the cursor still
// at the end of the row before, waiting to wrap, which a clear would clear
// instead; with nothing on it, or for its mark to change, a blank wraps
// there first, which the row's text or the clear after takes. was is the
// mark of a shell's prompt the other row has (see mark). It returns what
// identifies how it drew it.
func (m *Mirror) row(out *bytes.Buffer, l line, next *line, cont bool, was vt.RowPrompt) []byte {
cols := m.t.size.cols
if c, _ := m.t.term.Size(); c > 0 {
cols = c
}
out.WriteString("\x1b[0m")
marked, after := false, ""
switch {
case !cont:
// Cleared whole, which also undoes a wrap it had.
out.WriteString("\x1b[2K")
marked = mark(out, l.prompt, was)
case len(l.vt) == 0 || l.prompt != was && !l.startsWide:
// The blank wraps the row before into this one, then goes; the
// row is marked from its first column.
out.WriteString(" \r")
marked = mark(out, l.prompt, was)
case l.prompt != was && l.prompt != vt.NoPrompt:
// A wide character the row before left its last column for
// wraps, not a blank: the row is marked after its text, as the
// cursor's column takes no mark there (premark clears one).
after, marked = markAfter[l.prompt], true
}
out.Write(l.vt)
out.WriteString(after)
out.WriteString("\x1b[0m")
if l.wrap && next != nil {
// Out to the last column, which the next character wraps from;
// short of it when a wide character did not fit there, for the
// other terminal to wrap it too.
to := cols
if l.spacerHead && next.startsWide {
to--
}
if l.end < to {
out.Write(bytes.Repeat([]byte{' '}, to-l.end))
}
} else if l.end < cols {
out.WriteString("\x1b[K")
}
if marked {
out.WriteString(markEnd)
}
return l.key()
}
// The marks of a shell's prompt (OSC 133) that a Mirror writes for the
// other terminal's rows to be marked as this one's are, for a click there
// to move the shell's cursor (see clickToMove). The other terminal marks a
// row a line feed or a soft wrap reaches while in a prompt as the prompt's
// continuation, and keeps a row's mark as the row is cleared or drawn
// over: each row a frame draws gets its mark, after which the other
// terminal is out of the prompt again (markEnd), as it is from the start.
const (
markPrompt = "\x1b]133;A\a"
markContinuation = "\x1b]133;A;k=c\a"
markOutput = "\x1b]133;C\a" // clears the row's mark at its first column
markEnd = "\x1b]133;D\a" // out of the prompt, the row's mark kept
)
// markAfter are the marks of a row from a column after its first, where
// markPrompt would start a line of its own.
var markAfter = [...]string{
vt.PromptStart: "\x1b]133;P\a",
vt.PromptContinuation: "\x1b]133;P;k=c\a",
}
// mark marks the other terminal's row, whose first column the cursor is
// on, as a prompt's start or continuation, or clears the mark it has, was;
// it reports whether the other terminal is in a prompt then.
func mark(out *bytes.Buffer, p, was vt.RowPrompt) bool {
switch {
case p == vt.PromptStart:
out.WriteString(markPrompt)
case p == vt.PromptContinuation:
out.WriteString(markContinuation)
case was != vt.NoPrompt:
out.WriteString(markOutput)
}
return p != vt.NoPrompt
}
// premark clears the mark of row y of the other screen, was, from its
// first column, before a soft wrap reaches it with a wide character, which
// keeps the mark, and a row with none (row marks the others).
func premark(out *bytes.Buffer, y int, l line, was vt.RowPrompt) {
if l.startsWide && len(l.vt) > 0 && l.prompt == vt.NoPrompt && was != vt.NoPrompt {
fmt.Fprintf(out, "\x1b[%dH%s", y+1, markOutput)
}
}
// line is a row of a terminal as a Mirror draws it.
type line struct {
// vt is its cells, from the first to the last that holds something,
// as VT sequences, each cell in its own style: an empty cell in none.
vt []byte
// end is how many columns hold something: text, the second half of a
// wide character, a style or a background.
end int
// wrap tells that it soft-wraps into the next row; spacerHead that a
// wide character that did not fit at its end went on to the next row;
// startsWide that it starts with a wide character.
wrap, spacerHead, startsWide bool
// prompt is how it belongs to a shell's prompt (OSC 133).
prompt vt.RowPrompt
}
// key identifies how the line shows: whether it wraps, its prompt's mark,
// then its cells.
func (l line) key() []byte {
w := byte(0)
if l.wrap {
w = 1
}
return append([]byte{w, byte(l.prompt)}, l.vt...)
}
// keyPrompt returns the prompt's mark of a line drawn as key, none for a
// row not drawn.
func keyPrompt(key []byte) vt.RowPrompt {
if len(key) < 2 {
return vt.NoPrompt
}
return vt.RowPrompt(key[1])
}
// readLine reads the row the render state's row iterator is on, row y of
// the viewport.
func readLine(term *vt.Terminal, rs *vt.RenderState, y int) line {
cells := rs.RowCells()
l := line{wrap: rs.RowWrapped(), prompt: rs.RowPrompt()}
for x, c := range cells {
if c.Codepoint != 0 || c.Grapheme || c.HasBackground || c.Style != 0 || c.Wide == vt.SpacerTail {
l.end = x + 1
}
}
if n := len(cells); n > 0 {
l.spacerHead = cells[n-1].Wide == vt.SpacerHead
l.startsWide = cells[0].Wide == vt.WideChar
}
var b bytes.Buffer
sgr, link := "\x1b[0m", ""
styles := map[uint16]string{}
var buf []rune
for x := 0; x < l.end; x++ {
c := cells[x]
if c.Wide == vt.SpacerTail || c.Wide == vt.SpacerHead {
continue
}
want := "\x1b[0m"
switch {
case c.HasBackground && c.Codepoint == 0 && !c.Grapheme:
// A cell without text that a program filled.
bg := vt.Color{Kind: 2, RGB: c.Background}
if c.Palette {
bg = vt.Color{Kind: 1, Index: c.Background.R}
}
want = vt.Style{BG: bg}.SGR()
case c.Style != 0:
s, ok := styles[c.Style]
if !ok {
s = rs.CellStyle(x).SGR()
styles[c.Style] = s
}
want = s
}
if want != sgr {
b.WriteString(want)
sgr = want
}
uri := ""
if c.Hyperlink {
if ref, ok := term.CellAt(x, y); ok {
uri = term.Hyperlink(ref)
}
}
if uri != link {
fmt.Fprintf(&b, "\x1b]8;;%s\x1b\\", uri)
link = uri
}
buf = buf[:0]
if c.Grapheme {
buf = rs.CellGraphemes(x, buf)
}
switch {
case len(buf) > 0:
for _, r := range buf {
b.WriteRune(r)
}
case c.Codepoint != 0:
b.WriteRune(c.Codepoint)
default:
b.WriteByte(' ')
}
}
if link != "" {
b.WriteString("\x1b]8;;\x1b\\")
}
if sgr != "\x1b[0m" {
b.WriteString("\x1b[0m")
}
l.vt = b.Bytes()
return l
}
// mirroredModes are the modes the other terminal takes: those that change
// what it sends, as the keys and the mouse, and how it draws. Those off
// go first: the mouse's events and format are one setting each, which
// setting one of their modes picks and resetting any sets back to none or
// X10's, as Ghostty does.
var mirroredModes = []vt.Mode{
vt.ModeCursorKeys, 66, // DECCKM, DECNKM (the keypad's)
67, 1035, 1036, 1039, // DECBKM (Backspace's), NumLock's keypad, Alt's ESC
vt.ModeFocusEvent, vt.ModeAltScroll, vt.ModeBracketedPaste, vt.ModeGraphemes,
9, 1000, 1002, 1003, 1005, 1006, 1015, 1016, // the mouse's
5, // DECSCNM, the screen in reverse video
}
// mouseEvents and mouseFormats are the mouse's modes of each of its two
// settings.
var (
mouseEvents = []vt.Mode{9, 1000, 1002, 1003}
mouseFormats = []vt.Mode{1005, 1006, 1015, 1016}
)
// mouseLast orders the modes on so that the mouse's in effect come last,
// for the other terminal to take the events and the format the terminal
// sends: the last of a setting's modes set picks it, and its others stay
// set, so that crossterm's 1015 then 1006, as herdr sets them, are SGR's
// and not URxvt's. off is a mode to reset after, when the modes on are
// none in effect: a reset of one picks none or X10's again, and leaves the
// others set. A mouse encoder tells which are in effect by what it sends.
func mouseLast(term *vt.Terminal, on []vt.Mode) (_ []vt.Mode, off vt.Mode) {
var events, formats int
for _, md := range on {
if slices.Contains(mouseEvents, md) {
events++
} else if slices.Contains(mouseFormats, md) {
formats++
}
}
if events == 0 {
return on, 0 // no events, of which the format is the format
}
e, err := vt.NewMouseEncoder()
if err != nil {
return on, 0
}
defer e.Free()
// Cells of 10 by 10 pixels, 300 of them across: X10's coordinates go
// up to 223, past which UTF-8's take two bytes.
sends := func(pressed bool, action vt.MouseAction, button int, x float32) []byte {
e.Sync(term, 3000, 100, 10, 10, 0, 0, pressed)
return e.Encode(action, button, 0, x, 5)
}
var event vt.Mode
switch {
case len(sends(false, vt.MouseMotion, vt.ButtonNone, 5)) > 0:
event = 1003
case len(sends(true, vt.MouseMotion, vt.ButtonLeft, 15)) > 0:
event = 1002
case len(sends(false, vt.MouseRelease, vt.ButtonLeft, 5)) > 0:
event = 1000
case len(sends(false, vt.MousePress, vt.ButtonLeft, 5)) > 0:
event = 9
}
on = moveLast(on, event, mouseEvents)
if event == 0 {
return on, mouseEventsOn(on)
}
if formats == 0 {
return on, 0
}
var format vt.Mode
switch b := sends(false, vt.MousePress, vt.ButtonLeft, 1505); {
case bytes.HasPrefix(b, []byte("\x1b[<")):
format = 1006
if bytes.Contains(b, []byte(";1505;")) {
format = 1016
}
case bytes.HasPrefix(b, []byte("\x1b[M")):
if len(b) > 6 {
format = 1005
}
case len(b) > 0:
format = 1015
}
on = moveLast(on, format, mouseFormats)
if format == 0 {
for _, md := range on {
if slices.Contains(mouseFormats, md) {
off = md
}
}
}
return on, off
}
// moveLast moves md to the end of the modes on, when it's on, or else
// none of the setting's modes.
func moveLast(on []vt.Mode, md vt.Mode, setting []vt.Mode) []vt.Mode {
if md == 0 || !slices.Contains(on, md) {
return on
}
on = slices.DeleteFunc(slices.Clone(on), func(o vt.Mode) bool { return o == md })
return append(on, md)
}
// mouseEventsOn returns a mouse's event mode among those on.
func mouseEventsOn(on []vt.Mode) vt.Mode {
for _, md := range on {
if slices.Contains(mouseEvents, md) {
return md
}
}
return 0
}
// programColors returns the sequences that set the colors programs set
// (OSC 4, 10, 11, 12) and reset the others, which the other terminal's
// own defaults then color.
func programColors(term *vt.Terminal) string {
set, def := term.Colors(false), term.Colors(true)
var b bytes.Buffer
osc := func(code string, c vt.RGB) {
fmt.Fprintf(&b, "\x1b]%s;rgb:%02x/%02x/%02x\x1b\\", code, c.R, c.G, c.B)
}
for _, c := range []struct {
code string
set, def vt.RGB
has, dhas bool
}{
{"10", set.Foreground, def.Foreground, set.HasForeground, def.HasForeground},
{"11", set.Background, def.Background, set.HasBackground, def.HasBackground},
{"12", set.Cursor, def.Cursor, set.HasCursor, def.HasCursor},
} {
if c.has && (!c.dhas || c.set != c.def) {
osc(c.code, c.set)
} else {
fmt.Fprintf(&b, "\x1b]1%s\x1b\\", c.code)
}
}
b.WriteString("\x1b]104\x1b\\")
for i := range set.Palette {
if set.Palette[i] != def.Palette[i] {
osc("4;"+strconv.Itoa(i), set.Palette[i])
}
}
return b.String()
}
// state sets the cursor, the modes and the title, where they changed, and
// passes on programs' uses of the clipboard.
func (m *Mirror) state(out *bytes.Buffer, c vt.Cursor) {
t := m.t
term := t.term
var modes bytes.Buffer
var on []vt.Mode
for _, md := range mirroredModes {
if term.Mode(md) {
on = append(on, md)
} else {
fmt.Fprintf(&modes, "\x1b[?%dl", md)
}
}
on, off := mouseLast(term, on)
for _, md := range on {
fmt.Fprintf(&modes, "\x1b[?%dh", md)
}
if off != 0 {
fmt.Fprintf(&modes, "\x1b[?%dl", off)
}
mok := 1
if term.ModifyOtherKeys() {
mok = 2
}
fmt.Fprintf(&modes, "\x1b[=%d;1u\x1b[>4;%dm", term.KittyKeyboardFlags(), mok)
if shape := term.MouseShape(); shape >= 0 && shape < len(shapeNames) {
fmt.Fprintf(&modes, "\x1b]22;%s\x1b\\", shapeNames[shape])
}
if s := modes.String(); s != m.modes {
out.WriteString(s)
m.modes = s
}
if colors := programColors(term); colors != m.colors {
out.WriteString(colors)
m.colors = colors
}
if title := term.Title(); title != m.title {
fmt.Fprintf(out, "\x1b]2;%s\x1b\\", title)
m.title = title
}
for _, text := range m.clipOut {
fmt.Fprintf(out, "\x1b]52;c;%s\x1b\\", base64.StdEncoding.EncodeToString([]byte(text)))
}
m.clipOut = nil
for _, primary := range t.clipForward {
sel := "c"
if primary {
sel = "p"
}
fmt.Fprintf(out, "\x1b]52;%s;?\x1b\\", sel)
}
t.clipForward = nil
x, y := term.Cursor()
var cur bytes.Buffer
// A cursor as this terminal's options make it, which programs left
// alone or reset, is the default of the other terminal too (DECSCUSR
// 0), which takes its own options': a client's Cursor shows.
shape := 0
if c.Style != vtCursor(t.opts.Cursor) || c.Blinking == t.opts.NoBlink {
shape = map[vt.CursorStyle]int{vt.CursorBlock: 2, vt.CursorUnderline: 4, vt.CursorBar: 6}[c.Style]
if shape == 0 {
shape = 2
}
if c.Blinking {
shape--
}
}
visible := "l"
if c.Visible {
visible = "h"
}
fmt.Fprintf(&cur, "\x1b[0m\x1b[%d;%dH\x1b[?25%s\x1b[%d q", y+1, x+1, visible, shape)
// After rows, the cursor goes back, though it did not move.
if s := cur.String(); s != m.cursor || out.Len() > 0 {
out.WriteString(s)
m.cursor = s
}
}
// shapeNames are the pointer shapes of OSC 22, in Ghostty's order.
var shapeNames = []string{"default", "context-menu", "help", "pointer", "progress", "wait", "cell", "crosshair",
"text", "vertical-text", "alias", "copy", "move", "no-drop", "not-allowed", "grab", "grabbing", "all-scroll",
"col-resize", "row-resize", "n-resize", "e-resize", "s-resize", "w-resize", "ne-resize", "nw-resize",
"se-resize", "sw-resize", "ew-resize", "ns-resize", "nesw-resize", "nwse-resize", "zoom-in", "zoom-out"}
// History returns what the terminal shows as rows of VT sequences, for a
// terminal that takes the session over, as after the program that wrote
// them ended: the scrollback and the screen down to the cursor's row, or
// to the last row with something on it when that is above, without the
// cursor and the modes. Fed to a terminal of the same width, it leaves the
// cursor below what it shows, for the next program to start under it, not
// over it. A full-screen program's screen has no history: History returns
// nothing while the alternate screen shows.
func (t *Terminal) History() []byte {
t.mu.Lock()
defer t.mu.Unlock()
term := t.term
if term == nil || term.AltScreen() {
return nil
}
cols, rows := term.Size()
sb := term.ScrollbackRows()
lines := readLines(term, 0, sb+rows)
_, y := term.Cursor()
end := min(sb+y, len(lines)-1) // the last line, down to the cursor's
for end >= 0 && lines[end].end == 0 {
end--
}
var out bytes.Buffer
for i, l := range lines[:end+1] {
out.Write(l.vt)
out.WriteString("\x1b[0m")
if l.wrap && i < end {
// Soft wrapped: on to the last column, for the next row to wrap.
to := cols
if l.spacerHead && lines[i+1].startsWide {
to--
}
if l.end < to {
out.Write(bytes.Repeat([]byte{' '}, to-l.end))
}
continue
}
out.WriteString("\r\n")
}
return out.Bytes()
}
+153
View File
@@ -0,0 +1,153 @@
package terminal
import (
"bytes"
"compress/zlib"
"encoding/base64"
"fmt"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
)
// imageKey is a placement of an image as a Mirror placed it in the other
// terminal: row counts from the top of the scrollback, so that it stays
// as the screen scrolls.
type imageKey struct {
img, id uint32
row, col, xoff, yoff int
cols, rows int
srcX, srcY, srcW, srcH, gr int
z int32
virtual bool
}
// mirroredImages are the images a Mirror sent of a screen, by id, at
// their generations, and the placements it made, with their ids in the
// other terminal.
type mirroredImages struct {
gens map[uint32]uint64
placed map[imageKey]uint32
}
// images brings the other terminal's images of the screen that shows to
// this one's (Kitty graphics): it sends the pixels of those placed, once
// for each generation, places what shows that it has not, and deletes
// what went. A placement whose top scrolled off before a frame saw it, as
// when a Mirror starts over, does not show there. top is the screen's
// first row from the top of the scrollback.
func (m *Mirror) images(out *bytes.Buffer, term *vt.Terminal, alt bool, top, rows int) {
st := &m.imgs[0]
if alt {
st = &m.imgs[1]
}
if st.gens == nil {
st.gens, st.placed = map[uint32]uint64{}, map[imageKey]uint32{}
}
seen := map[imageKey]bool{}
var place []imageKey
term.Placements(func(pl vt.Placement) {
if pl.Virtual {
// Placed by its id, which the placeholder cells name.
k := imageKey{img: pl.ImageID, id: pl.ID, cols: pl.ParamCols, rows: pl.ParamRows, z: pl.Z, virtual: true}
seen[k] = true
if _, ok := st.placed[k]; !ok {
place = append(place, k)
}
return
}
if !pl.Visible {
return
}
k := imageKey{
img: pl.ImageID, id: pl.ID, row: top + pl.Row, col: pl.Col, xoff: pl.XOffset, yoff: pl.YOffset,
cols: pl.ParamCols, rows: pl.ParamRows,
srcX: pl.ParamSrcX, srcY: pl.ParamSrcY, srcW: pl.ParamSrcW, srcH: pl.ParamSrcH, gr: max(pl.Rows, 1), z: pl.Z,
}
seen[k] = true
if _, ok := st.placed[k]; !ok && pl.Row >= 0 {
place = append(place, k)
}
})
// Images gone, or of new pixels, which the other terminal's placements
// of them may not survive: placed again where they show.
for id, gen := range st.gens {
g := term.ImageGeneration(id)
if g == gen {
continue
}
if g == 0 {
fmt.Fprintf(out, "\x1b_Ga=d,d=I,i=%d,q=2\x1b\\", id)
delete(st.gens, id)
}
for k := range st.placed {
if k.img == id {
delete(st.placed, k)
if g != 0 && seen[k] && (k.virtual || k.row >= top) {
place = append(place, k)
}
}
}
}
// Placements gone from where they would show; those that scrolled off
// stay, as they do here.
for k, id := range st.placed {
if !seen[k] && (k.virtual || k.row+k.gr > top && k.row < top+rows) {
fmt.Fprintf(out, "\x1b_Ga=d,d=i,i=%d,p=%d,q=2\x1b\\", k.img, id)
delete(st.placed, k)
}
}
for _, k := range place {
gen := term.ImageGeneration(k.img)
if gen == 0 {
continue
}
if st.gens[k.img] != gen {
img, ok := term.Image(k.img)
if !ok {
continue
}
sendImage(out, img)
st.gens[k.img] = gen
}
if k.virtual {
fmt.Fprintf(out, "\x1b_Ga=p,U=1,i=%d,p=%d,c=%d,r=%d,z=%d,q=2\x1b\\", k.img, k.id, k.cols, k.rows, k.z)
st.placed[k] = k.id
continue
}
m.placement++
fmt.Fprintf(out, "\x1b[%d;%dH\x1b_Ga=p,i=%d,p=%d,X=%d,Y=%d,x=%d,y=%d,w=%d,h=%d,c=%d,r=%d,z=%d,C=1,q=2\x1b\\",
k.row-top+1, k.col+1, k.img, m.placement, k.xoff, k.yoff, k.srcX, k.srcY, k.srcW, k.srcH, k.cols, k.rows, k.z)
st.placed[k] = m.placement
}
}
// deleteImages deletes from the other terminal the images sent of a
// screen, with their placements, wherever they are.
func (m *Mirror) deleteImages(out *bytes.Buffer, st *mirroredImages) {
for id := range st.gens {
fmt.Fprintf(out, "\x1b_Ga=d,d=I,i=%d,q=2\x1b\\", id)
}
}
// sendImage writes the sequences that transmit an image's pixels, as
// RGBA compressed (o=z), in chunks.
func sendImage(out *bytes.Buffer, img vt.Image) {
var z bytes.Buffer
w := zlib.NewWriter(&z)
w.Write(decoded(img).Pix)
w.Close()
data := base64.StdEncoding.EncodeToString(z.Bytes())
const chunk = 4096
for i := 0; i == 0 || i < len(data); i += chunk {
part := data[i:min(i+chunk, len(data))]
more := 0
if i+chunk < len(data) {
more = 1
}
if i == 0 {
fmt.Fprintf(out, "\x1b_Ga=t,f=32,o=z,s=%d,v=%d,i=%d,q=2,m=%d;%s\x1b\\", img.Width, img.Height, img.ID, more, part)
} else {
fmt.Fprintf(out, "\x1b_Gm=%d;%s\x1b\\", more, part)
}
}
}
+972
View File
@@ -0,0 +1,972 @@
package terminal
import (
"encoding/base64"
"fmt"
"math/rand/v2"
"os"
"strings"
"testing"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
"github.com/egoist/mygo/ui"
)
// mirrored is a terminal and another showing its Mirror's frames.
type mirrored struct {
t *testing.T
src *Terminal
dst *Terminal
m *Mirror
frames int
// pruned lets the other terminal keep rows the source's scrollback,
// at its limit, let go of: its rows end with the source's.
pruned bool
}
func newMirrored(t *testing.T, cols, rows int, o Options) *mirrored {
t.Helper()
o.Conn = newPipe()
src, err := New(o)
if err != nil {
t.Fatal(err)
}
dst, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
src.Resize(cols, rows)
dst.Resize(cols, rows)
m, err := src.NewMirror()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { m.Close(); src.Close(); dst.Close() })
x := &mirrored{t: t, src: src, dst: dst, m: m}
x.frame("start")
return x
}
// feed writes output to the source, then shows the frame and checks it.
func (x *mirrored) feed(label string, out string) {
x.t.Helper()
x.src.Feed([]byte(out))
x.frame(label)
}
func (x *mirrored) resize(cols, rows int) {
x.t.Helper()
x.src.Resize(cols, rows)
x.dst.Resize(cols, rows)
x.frame(fmt.Sprintf("resize %dx%d", cols, rows))
}
func (x *mirrored) frame(label string) {
x.t.Helper()
f, due := x.m.Frame()
if due {
return // a synchronized update holds it back: the next frame shows
}
x.dst.Feed(f)
x.frames++
x.same(label)
}
// same checks that the other terminal shows what the source does: every
// cell of its screen and scrollback, as the cell's text, style, colors,
// width and link, every row's wrap, the cursor and the modes.
func (x *mirrored) same(label string) {
x.t.Helper()
a, b := x.src, x.dst
a.mu.Lock()
b.mu.Lock()
defer a.mu.Unlock()
defer b.mu.Unlock()
ta, tb := a.term, b.term
fail := func(format string, args ...any) {
x.t.Helper()
x.t.Fatalf("%s (frame %d): %s", label, x.frames, fmt.Sprintf(format, args...))
}
if ta.AltScreen() != tb.AltScreen() {
fail("alt screen %v, mirrored %v", ta.AltScreen(), tb.AltScreen())
}
ca, ra := ta.Size()
if cb, rb := tb.Size(); ca != cb || ra != rb {
fail("size %dx%d, mirrored %dx%d", ca, ra, cb, rb)
}
if sa, sb := ta.ScrollbackRows(), tb.ScrollbackRows(); !ta.AltScreen() && sa != sb && !(x.pruned && sb > sa) {
fail("scrollback %d rows, mirrored %d", sa, sb)
}
rowsA, rowsB := cellRows(ta), cellRows(tb)
if x.pruned && len(rowsB) > len(rowsA) {
rowsB = rowsB[len(rowsB)-len(rowsA):]
}
if len(rowsA) != len(rowsB) {
fail("%d rows, mirrored %d", len(rowsA), len(rowsB))
}
for y := range rowsA {
if rowsA[y].cells != rowsB[y].cells {
fail("row %d (screen row %d) is\n %s\nmirrored\n %s", y, y-(len(rowsA)-ra), rowsA[y].cells, rowsB[y].cells)
}
// The screen's last row wraps into nothing: the other terminal
// cannot wrap its own without scrolling, and nothing follows to
// join, until the screen scrolls and the mirror writes it again.
if rowsA[y].wrap != rowsB[y].wrap && y != len(rowsA)-1 {
fail("row %d wraps %v, mirrored %v", y, rowsA[y].wrap, rowsB[y].wrap)
}
if rowsA[y].prompt != rowsB[y].prompt {
fail("row %d (screen row %d) is of a prompt %d, mirrored %d", y, y-(len(rowsA)-ra), rowsA[y].prompt, rowsB[y].prompt)
}
}
xa, ya := ta.Cursor()
if xb, yb := tb.Cursor(); xa != xb || ya != yb {
fail("cursor %d,%d, mirrored %d,%d", xa, ya, xb, yb)
}
for _, md := range append(mirroredModes, vt.ModeCursorVisible) {
if ta.Mode(md) != tb.Mode(md) {
fail("mode %d is %v, mirrored %v", md, ta.Mode(md), tb.Mode(md))
}
}
if ta.KittyKeyboardFlags() != tb.KittyKeyboardFlags() {
fail("kitty keyboard flags %d, mirrored %d", ta.KittyKeyboardFlags(), tb.KittyKeyboardFlags())
}
if ta.ModifyOtherKeys() != tb.ModifyOtherKeys() {
fail("modifyOtherKeys %v, mirrored %v", ta.ModifyOtherKeys(), tb.ModifyOtherKeys())
}
if ta.MouseShape() != tb.MouseShape() {
fail("pointer shape %d, mirrored %d", ta.MouseShape(), tb.MouseShape())
}
}
// cellRow is a row as its cells show: their text, styles, colors, widths
// and links, written out, whether it wraps, and how it belongs to a
// shell's prompt.
type cellRow struct {
cells string
wrap bool
prompt vt.RowPrompt
}
// cellRows reads every row of the scrollback and the screen, cell by cell,
// independently of what the mirror encodes: an empty cell and a plain
// space show the same, and so do a wide character's spacer at a row's end
// and a blank.
func cellRows(term *vt.Terminal) []cellRow {
rs, err := vt.NewRenderState()
if err != nil {
panic(err)
}
defer rs.Free()
_, rows := term.Size()
total := rows
if !term.AltScreen() {
total += term.ScrollbackRows()
}
var out []cellRow
for y := 0; y < total; {
term.ScrollToRow(y)
rs.Update(term)
off := int(term.Scrollbar().Offset)
rs.Rows()
for i := 0; rs.NextRow(); i++ {
if off+i != len(out) || len(out) >= total {
continue
}
cells := rs.RowCells()
var b strings.Builder
for x, c := range cells {
text := string(c.Codepoint)
if c.Grapheme {
text = string(rs.CellGraphemes(x, nil))
}
if c.Codepoint == 0 || c.Wide == vt.SpacerHead {
text = " "
}
if c.Wide == vt.SpacerTail {
text = ""
}
st := ""
if c.Style != 0 {
st = rs.CellStyle(x).SGR()
}
if c.HasBackground && c.Codepoint == 0 {
// A cell a program filled without text shows as a
// blank in its background.
if c.Palette {
st = vt.Style{BG: vt.Color{Kind: 1, Index: c.Background.R}}.SGR()
} else {
st = vt.Style{BG: vt.Color{Kind: 2, RGB: c.Background}}.SGR()
}
}
link := ""
if c.Hyperlink {
if ref, ok := term.CellAt(x, i); ok {
link = term.Hyperlink(ref)
}
}
wide := c.Wide
if wide == vt.SpacerHead {
wide = vt.Narrow
}
if text == " " && st == "\x1b[0m" {
st = ""
}
fmt.Fprintf(&b, "[%s|%q|%d|%s]", text, st, wide, link)
}
out = append(out, cellRow{cells: strings.TrimRight(trimBlankCells(b.String()), ""), wrap: rs.RowWrapped(), prompt: rs.RowPrompt()})
}
next := off + rows
if next <= y {
break
}
y = next
}
term.ScrollToBottom()
return out
}
// trimBlankCells drops the blank cells at a row's end, which show nothing.
func trimBlankCells(s string) string {
for strings.HasSuffix(s, `[ |""|0|]`) {
s = strings.TrimSuffix(s, `[ |""|0|]`)
}
return s
}
func lines(from, to int, prefix string) string {
var b strings.Builder
for i := from; i < to; i++ {
fmt.Fprintf(&b, "%s%d\r\n", prefix, i)
}
return b.String()
}
func TestMirrorScrolling(t *testing.T) {
loadLib(t)
x := newMirrored(t, 20, 6, Options{})
x.feed("a few lines", lines(0, 3, "line "))
x.feed("past the screen", lines(3, 9, "line "))
x.feed("a screen and more at once", lines(9, 40, "row "))
x.feed("one more", "last\r\n")
x.feed("styles", "\x1b[1;31mred\x1b[0m \x1b[48;5;4mbg\x1b[0m \x1b[38;2;10;20;30mrgb\x1b[0m\r\n")
x.feed("a link", "\x1b]8;;https://example.com\x1b\\link\x1b]8;;\x1b\\ after\r\n")
x.feed("wide characters", "你好世界 😄 ok\r\n")
x.feed("a wrapped line", strings.Repeat("abcdefghij", 5)+"\r\n")
x.feed("a wrapped line scrolling off", lines(0, 8, "after "))
x.feed("a wide character at the edge", strings.Repeat("x", 19)+"世"+"\r\n")
x.feed("a prompt without a newline", "$ ")
}
// The terminal showing the frames keeps the cursor its options make
// while programs leave the cursor alone, and takes one a program asks
// for, until the program resets it.
// The keyboard's modes go to the other terminal as the program sets them,
// and a pointer shape (OSC 22) does not turn modifyOtherKeys on there.
func TestMirrorKeyboardModes(t *testing.T) {
loadLib(t)
x := newMirrored(t, 20, 6, Options{})
x.feed("a pointer shape", "\x1b]22;pointer\x1b\\")
x.feed("modifyOtherKeys", "\x1b[>4;2m")
x.feed("kitty keyboard flags", "\x1b[>1u")
x.feed("modifyOtherKeys off", "\x1b[>4;1m\x1b[<u")
// The modes the keys' encoding takes from the terminal: Backspace's,
// NumLock's keypad and Alt's ESC.
x.feed("keys' modes", "\x1b[?67h\x1b[?1035h\x1b[?1036l\x1b[?1039l")
for _, md := range []vt.Mode{67, 1035, 1036, 1039} {
if a, b := x.src.term.Mode(md), x.dst.term.Mode(md); a != b {
t.Errorf("mode %d is %v, mirrored %v", md, a, b)
}
}
x.feed("keys' modes back", "\x1b[?67l\x1b[?1035l\x1b[?1036h\x1b[?1039h")
}
func TestMirrorCursorStyle(t *testing.T) {
loadLib(t)
src, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
dst, err := New(Options{Conn: newPipe(), Cursor: CursorBar, NoBlink: true})
if err != nil {
t.Fatal(err)
}
m, err := src.NewMirror()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { m.Close(); src.Close(); dst.Close() })
step := func(label, out string, style vt.CursorStyle, blink bool) {
t.Helper()
src.Feed([]byte(out))
f, _ := m.Frame()
dst.Feed(f)
dst.mu.Lock()
dst.rs.Update(dst.term)
c := dst.rs.Cursor()
dst.mu.Unlock()
if c.Style != style || c.Blinking != blink {
t.Errorf("%s: the cursor is style %d, blinking %v; want %d, %v", label, c.Style, c.Blinking, style, blink)
}
}
step("at the start", "$ ", vt.CursorBar, false)
step("a program's underline", "\x1b[3 q", vt.CursorUnderline, true)
step("a program's block", "\x1b[2 q", vt.CursorBlock, false)
step("reset", "\x1b[0 q", vt.CursorBar, false)
}
// Empty cells after a styled run stay empty: Claude Code's mascot, whose
// eyes are a black background, showed a black square where the cells
// after it took the background (libghostty's formatter wrote them as
// spaces in the run's style).
func TestMirrorGaps(t *testing.T) {
loadLib(t)
x := newMirrored(t, 40, 5, Options{})
x.feed("the mascot", "\x1b[38;2;215;119;87m \u2590\x1b[48;2;0;0;0m\u259b\u2588\u2588\u2588\u259b\u2588\x1b[12G\x1b[39m\x1b[49m\x1b[1mClaude\x1b[19GCode\x1b[22m\r\r\n")
x.feed("a background, then text further on", "\x1b[44mblue\x1b[0m\x1b[20Gplain\r\n")
x.feed("an erase in a background", "\x1b[41m\x1b[K\x1b[0m\x1b[10Gafter\r\n")
}
func TestMirrorEdits(t *testing.T) {
loadLib(t)
x := newMirrored(t, 20, 6, Options{})
x.feed("fill", lines(0, 10, "l"))
x.feed("overwrite a row", "\x1b[2;1Hchanged\x1b[K")
x.feed("insert lines", "\x1b[3;1H\x1b[2L")
x.feed("delete lines", "\x1b[2;1H\x1b[1M")
x.feed("a scrolling region", "\x1b[2;4r\x1b[4;1H"+lines(0, 5, "in region "))
x.feed("the region reset", "\x1b[r\x1b[6;1H")
x.feed("clear the screen", "\x1b[2J\x1b[H")
x.feed("after the clear", lines(0, 3, "new "))
x.feed("clear the scrollback", "\x1b[3J")
x.feed("after clearing the scrollback", lines(0, 9, "more "))
x.feed("modes", "\x1b[?1h\x1b[?2004h\x1b[?1000h\x1b[?1006h\x1b[?1004h\x1b[>1u\x1b[?25l")
x.feed("modes off", "\x1b[?1l\x1b[?2004l\x1b[?1000l\x1b[?1006l\x1b[<u\x1b[?25h")
}
func TestMirrorAltScreen(t *testing.T) {
loadLib(t)
x := newMirrored(t, 20, 6, Options{})
x.feed("history", lines(0, 10, "shell "))
x.feed("enter the alternate screen", "\x1b[?1049h\x1b[H\x1b[2Jfull screen\x1b[3;3Hthere")
x.feed("draw on it", "\x1b[5;1H"+strings.Repeat("-", 20))
x.feed("leave it", "\x1b[?1049l")
x.feed("after", "$ ls\r\n")
}
// A terminal that takes a Mirror's frames from while a full-screen program
// shows gets the main screen and its scrollback once the program ends.
func TestMirrorResetInAltScreen(t *testing.T) {
loadLib(t)
x := newMirrored(t, 20, 5, Options{})
x.feed("history", lines(0, 50, "x"))
x.feed("a full-screen program", "\x1b[?1049hfull screen")
x.m.Reset()
other, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { other.Close() })
other.Resize(20, 5)
x.dst = other
x.frame("another terminal")
x.feed("the program ends", "\x1b[?1049l")
}
func TestMirrorResize(t *testing.T) {
loadLib(t)
x := newMirrored(t, 20, 6, Options{})
x.feed("history", lines(0, 12, "line "))
x.feed("a long line", strings.Repeat("0123456789", 4)+"\r\n$ ")
x.resize(30, 8)
x.feed("after growing", "more\r\n")
x.resize(12, 5)
x.feed("after shrinking", lines(0, 3, "s"))
}
// The server's terminal clears as a window's ⌘K asks (Options.OnClear):
// the window shows the prompt at the top, and goes on showing what the
// shell draws there, through resizes.
func TestMirrorClearScreen(t *testing.T) {
loadLib(t)
x := newMirrored(t, 20, 6, Options{})
x.feed("history", lines(0, 12, "line ")+"~/dev\r\n$ ")
if !x.src.ClearScreen() {
t.Fatal("ClearScreen did not clear")
}
x.frame("cleared")
if got := strings.TrimSpace(x.dst.Text()); got != "$" {
t.Fatalf("the window shows %q after the clear", got)
}
x.feed("typing", "ls")
x.feed("the line repainted", "\r\x1b[K$ ls -la")
x.resize(30, 8)
x.resize(12, 5)
if got := strings.TrimSpace(x.dst.Text()); got != "$ ls -la" {
t.Errorf("the window shows %q after resizes", got)
}
x.feed("output after", "\r\n"+lines(0, 9, "out "))
x.src.ClearScrollback()
x.frame("scrollback cleared")
}
func TestMirrorScrollbackLimit(t *testing.T) {
loadLib(t)
x := newMirrored(t, 20, 5, Options{Scrollback: 1})
for i := range 40 {
x.feed(fmt.Sprintf("burst %d", i), lines(i*100, i*100+60, "x"))
}
}
// A scrollback at its limit lets go of its oldest rows as it takes new
// ones: the other terminal keeps its own, without starting over, whether
// a frame scrolls a row or more than a screen.
func TestMirrorScrollbackPruned(t *testing.T) {
loadLib(t)
x := newMirrored(t, 40, 5, Options{Scrollback: 64 << 10})
x.pruned = true
drops, n := 0, 0
prev := 0
for i := range 400 {
count := 1
if i%2 == 1 {
count = 23 // more than a screen
}
x.src.Feed([]byte(lines(n, n+count, "line abcdefghijklmnopqrstuvwxyz ")))
n += count
f, due := x.m.Frame()
if due {
t.Fatal("no frame")
}
if strings.Contains(string(f), "\x1b[3J") {
t.Fatalf("frame %d clears the other terminal's scrollback: %q", i, f[:min(len(f), 80)])
}
x.dst.Feed(f)
x.frames++
x.src.mu.Lock()
sb := x.src.term.ScrollbackRows()
x.src.mu.Unlock()
if sb < prev {
drops++
}
if sb < prev || i%25 == 0 {
// Reading every row of both terminals takes long: at the
// frames that let go of rows, and now and then.
x.same(fmt.Sprintf("frame %d", i))
}
prev = sb
}
if drops < 2 {
t.Fatalf("the scrollback let go of rows %d times, want at least 2", drops)
}
// A clear still clears the other terminal's scrollback.
x.pruned = false
x.feed("clear", "\x1b[3J")
x.feed("after the clear", lines(0, 12, "after "))
}
// Claude Code's output under a screen of history, fed in uneven pieces, as
// it reaches a server: the frames keep the cursor where it is, on its
// input line, not a row above.
func TestMirrorClaudeCode(t *testing.T) {
loadLib(t)
raw, err := os.ReadFile("testdata/claude-code.vt")
if err != nil {
t.Skip(err)
}
x := newMirrored(t, 120, 36, Options{})
x.feed("history", lines(1, 101, ""))
r := rand.New(rand.NewPCG(1, 2))
for i := 0; len(raw) > 0; i++ {
n := min(len(raw), 1+r.IntN(400))
x.feed(fmt.Sprintf("piece %d", i), string(raw[:n]))
raw = raw[n:]
}
}
// Thousands of random edits, of every kind the mirror follows, each frame
// checked.
func TestMirrorRandom(t *testing.T) {
loadLib(t)
for seed := uint64(1); seed <= 3; seed++ {
r := rand.New(rand.NewPCG(seed, 7))
x := newMirrored(t, 16, 6, Options{Scrollback: 2})
words := []string{"a", "hello", "世界", "😄", "\x1b[1;32mgreen\x1b[0m", "\x1b[48;5;3m \x1b[0m", "\x1b]8;;https://x.y\x1b\\ln\x1b]8;;\x1b\\", strings.Repeat("w", 21)}
ops := []func() string{
func() string { return words[r.IntN(len(words))] },
func() string { return "\r\n" },
func() string { return lines(0, 1+r.IntN(20), "r") },
func() string { return fmt.Sprintf("\x1b[%d;%dH", 1+r.IntN(6), 1+r.IntN(16)) },
func() string { return []string{"\x1b[K", "\x1b[1K", "\x1b[2K", "\x1b[J", "\x1b[1J"}[r.IntN(5)] },
func() string { return fmt.Sprintf("\x1b[%dL", 1+r.IntN(3)) },
func() string { return fmt.Sprintf("\x1b[%dM", 1+r.IntN(3)) },
func() string { return fmt.Sprintf("\x1b[%dS", 1+r.IntN(3)) },
func() string { return fmt.Sprintf("\x1b[%dT", 1+r.IntN(3)) },
func() string { return []string{"\x1b[2;5r", "\x1b[r"}[r.IntN(2)] },
func() string { return []string{"\x1b[?1049h", "\x1b[?1049l"}[r.IntN(2)] },
func() string {
return []string{"\x1b[?25l", "\x1b[?25h", "\x1b[?2004h", "\x1b[?1000h\x1b[?1006h", "\x1b[?1000l"}[r.IntN(5)]
},
func() string { return "\x1bM" }, // reverse index
}
for i := range 1000 {
var b strings.Builder
for range 1 + r.IntN(4) {
b.WriteString(ops[r.IntN(len(ops))]())
}
x.feed(fmt.Sprintf("seed %d op %d %q", seed, i, b.String()), b.String())
}
}
}
// The other terminal's rows are marked as the source's are as a shell's
// prompt (OSC 133), for Alt+click to move the shell's cursor there too:
// the prompt's first row, the rows its input wraps onto or that a prompt
// of many lines goes on over, and none of those its output takes, nor
// those drawn over a prompt, though the other terminal keeps a row's mark
// as it is cleared. Soft wraps stay soft.
func TestMirrorPrompts(t *testing.T) {
loadLib(t)
x := newMirrored(t, 20, 6, Options{})
const prompt, input, output = "\x1b]133;A\a", "\x1b]133;B\a", "\x1b]133;C\a"
x.feed("output", lines(0, 2, "out "))
f0 := x.frames
x.feed("a prompt", prompt+"$ "+input)
x.feed("typing", "echo hi")
x.feed("a command that wraps", strings.Repeat("x", 30))
x.feed("the line redrawn shorter", "\x1b[2A\r\x1b[J$ echo short")
x.feed("it wraps again", strings.Repeat("y", 20))
x.feed("it runs", "\r\n"+output+lines(0, 3, "ran ")+"\x1b]133;D;0\a")
x.feed("output that wraps", strings.Repeat("o", 25)+"\r\n")
x.feed("a prompt of two lines", prompt+"~/dev\r\n$ "+input+"ls")
x.feed("scrolling off", "\r\n"+output+lines(0, 8, "after "))
x.feed("the screen cleared", "\x1b[H\x1b[2J"+prompt+"$ "+input+strings.Repeat("z", 25))
x.feed("drawn over without a clear", "\x1b[H"+output+strings.Repeat("w", 30)+"\x1b[1G\x1b[3B")
x.feed("a prompt on a full-screen program's screen", "\x1b[?1049h\x1b[H"+prompt+"> "+input+"q")
x.feed("back", "\x1b[?1049l")
if f0 == x.frames {
t.Fatal("no frames")
}
// A terminal that takes the session over starts out of the prompt.
if h := string(x.src.History()); strings.Contains(h, "\x1b]133;") {
t.Errorf("History has prompt marks: %q", h)
}
x.m.Reset()
f, _ := x.m.Frame()
for _, mark := range []string{markPrompt, markContinuation} {
if !strings.Contains(string(f), mark) {
t.Errorf("a frame from the start has no %q", mark)
}
}
}
// Random output with a shell's prompts' marks among it.
func TestMirrorPromptsRandom(t *testing.T) {
loadLib(t)
for seed := uint64(1); seed <= 3; seed++ {
r := rand.New(rand.NewPCG(seed, 133))
x := newMirrored(t, 12, 5, Options{Scrollback: 2})
ops := []string{
"\x1b]133;A\a$ ", "\x1b]133;A;k=c\a> ", "\x1b]133;P;k=s\a", "\x1b]133;B\a", "\x1b]133;C\a", "\x1b]133;D;0\a",
"word", strings.Repeat("w", 15), "世界", "\r\n", "\r\x1b[K", "\x1b[J", "\x1b[2K", "\x1b[A", "\x1b[B", "\x1b[H", "\x1b[2J",
"\x1b[?1049h", "\x1b[?1049l", "\x1b[L", "\x1b[M",
}
for i := range 600 {
var b strings.Builder
for range 1 + r.IntN(4) {
b.WriteString(ops[r.IntN(len(ops))])
}
x.feed(fmt.Sprintf("seed %d op %d %q", seed, i, b.String()), b.String())
}
}
}
// Two windows mirror one terminal: each of them shows it all, though their
// reads take turns at the terminal.
func TestMirrorTwoWindows(t *testing.T) {
loadLib(t)
x := newMirrored(t, 30, 6, Options{})
other, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
defer other.Close()
other.Resize(30, 6)
m2, err := x.src.NewMirror()
if err != nil {
t.Fatal(err)
}
defer m2.Close()
second := &mirrored{t: t, src: x.src, dst: other, m: m2}
second.frame("start")
raw, _ := os.ReadFile("testdata/claude-code.vt")
steps := []string{lines(0, 4, "a"), "\x1b[2;1Hedit\x1b[K", lines(0, 12, "b"), "\x1b[44mbg\x1b[0m\x1b[20Gx", string(raw)}
for i, out := range steps {
x.feed(fmt.Sprintf("step %d, the first window", i), out)
second.frame(fmt.Sprintf("step %d, the second window", i))
}
}
// Programs' writes to the clipboard go to every Mirror's frames, their
// reads with ClipboardForward to one, and what no frame takes stays
// bounded.
func TestMirrorClipboard(t *testing.T) {
loadLib(t)
src, err := New(Options{Conn: newPipe(), ClipboardRead: ClipboardForward})
if err != nil {
t.Fatal(err)
}
defer src.Close()
src.Resize(20, 4)
m1, _ := src.NewMirror()
defer m1.Close()
m2, _ := src.NewMirror()
m1.Frame()
m2.Frame()
write := func(s string) string { return "\x1b]52;c;" + base64.StdEncoding.EncodeToString([]byte(s)) + "\x1b\\" }
src.Feed([]byte(write("copied") + "\x1b]52;c;?\x1b\\"))
f1, _ := m1.Frame()
f2, _ := m2.Frame()
for i, f := range []string{string(f1), string(f2)} {
if strings.Count(f, write("copied")) != 1 {
t.Errorf("frame of mirror %d has the write %d times: %q", i+1, strings.Count(f, write("copied")), f)
}
}
if n := strings.Count(string(f1)+string(f2), "\x1b]52;c;?\x1b\\"); n != 1 {
t.Errorf("the read went %d times, want once", n)
}
// A closed Mirror takes nothing, and what no frame takes is bounded.
m2.Close()
for i := range 100 {
src.Feed([]byte(write(fmt.Sprint(i)) + "\x1b]52;c;?\x1b\\"))
}
src.mu.Lock()
queued, forward, mirrors := len(src.clipOut), len(src.clipForward), len(src.mirrors)
src.mu.Unlock()
if queued > maxQueued || forward > maxQueued || mirrors != 1 {
t.Errorf("%d writes and %d reads queued, %d mirrors", queued, forward, mirrors)
}
f1, _ = m1.Frame()
if f := string(f1); strings.Count(f, "\x1b]52;c;") != 2*maxQueued || !strings.Contains(f, write("99")) {
t.Errorf("the frame passes on %d uses of the clipboard, want the last %d writes and reads", strings.Count(f, "\x1b]52;c;"), maxQueued)
}
}
// History is what shows, down to the cursor, with the cursor under it: a
// program's interface below the cursor, as an agent's status bar, goes.
func TestHistory(t *testing.T) {
loadLib(t)
src, _ := New(Options{Conn: newPipe()})
defer src.Close()
src.Resize(20, 6)
src.Feed([]byte(lines(0, 10, "line ") + strings.Repeat("abcdefghij", 3) + "\r\n\x1b[1;31mred\x1b[0m\r\n> input\r\nstatus bar\x1b[1A\x1b[3G"))
h := src.History()
dst, _ := New(Options{Conn: newPipe()})
defer dst.Close()
dst.Resize(20, 6)
dst.Feed(h)
text := dst.Text()
for _, want := range []string{"line 0", "line 9", strings.Repeat("abcdefghij", 3), "red", "> input"} {
if !strings.Contains(text, want) {
t.Errorf("history lost %q:\n%s", want, text)
}
}
if strings.Contains(text, "status bar") {
t.Errorf("history kept what was below the cursor:\n%s", text)
}
dst.mu.Lock()
x, y := dst.term.Cursor()
row, _ := dst.term.RowText(y)
dst.mu.Unlock()
if x != 0 || strings.TrimSpace(string(row)) != "" {
t.Errorf("the cursor is at %d on %q, not at the start of a row of its own", x, string(row))
}
// Soft wraps stay soft: the long line is one line.
if !strings.Contains(text, strings.Repeat("abcdefghij", 3)+"\n") {
t.Errorf("the wrapped line did not stay one line:\n%s", text)
}
alt, _ := New(Options{Conn: newPipe()})
defer alt.Close()
alt.Feed([]byte("\x1b[?1049hfull screen"))
if h := alt.History(); len(h) != 0 {
t.Errorf("history of a full-screen program: %q", h)
}
}
// The other terminal reports the mouse as the program asked the source
// to: setting a mouse mode picks the events or the format, and resetting
// one goes back to none or X10's whatever is set, so that the modes off
// come before those on.
func TestMirrorMouse(t *testing.T) {
loadLib(t)
for _, c := range []struct{ modes, press, drag string }{
{"\x1b[?1002h\x1b[?1006h", "\x1b[<0;3;4M", "\x1b[<32;6;4M"},
{"\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h", "\x1b[<35;3;4M\x1b[<0;3;4M", "\x1b[<32;6;4M"},
{"\x1b[?1000h", "\x1b[M #$", ""},
// crossterm's EnableMouseCapture, as herdr's: 1006 after 1015
// picks SGR.
{"\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1015h\x1b[?1006h", "\x1b[<35;3;4M\x1b[<0;3;4M", "\x1b[<32;6;4M"},
} {
src, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
conn := newPipe()
dst, err := New(Options{Conn: conn})
if err != nil {
t.Fatal(err)
}
m, err := src.NewMirror()
if err != nil {
t.Fatal(err)
}
tt := ui.NewTester(func(c *ui.Context) { View(c, dst).Fill().AutoFocus() }, 400, 200)
src.Feed([]byte(c.modes))
f, _ := m.Frame()
dst.Feed(f)
tt.Frame()
x, y := cellCenter(dst, 2, 3)
tt.Press(x, y)
if got := conn.take(dst); got != c.press {
t.Errorf("%q: press sent %q, want %q", c.modes, got, c.press)
}
x2, y2 := cellCenter(dst, 5, 3)
tt.Move(x2, y2)
if got := conn.take(dst); got != c.drag {
t.Errorf("%q: drag sent %q, want %q", c.modes, got, c.drag)
}
tt.Release(x2, y2)
m.Close()
src.Close()
dst.Close()
}
}
// The colors programs set (OSC 4, 10, 11, 12) show in the other terminal,
// as on the source's, and their reset gives back the other terminal's
// own: a TUI that sets the terminal's background, or a shell script its
// palette, showed none of it.
func TestMirrorColors(t *testing.T) {
loadLib(t)
src, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
dark := DarkTheme()
dst, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
m, err := src.NewMirror()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { m.Close(); src.Close(); dst.Close() })
src.UseTheme(LightTheme())
dst.UseTheme(dark)
step := func(label, out string, want vt.TermColors) {
t.Helper()
src.Feed([]byte(out))
f, _ := m.Frame()
dst.Feed(f)
dst.mu.Lock()
got := dst.term.Colors(false)
dst.mu.Unlock()
if got.Foreground != want.Foreground || got.Background != want.Background || got.HasCursor != want.HasCursor || got.Cursor != want.Cursor || got.Palette[1] != want.Palette[1] || got.Palette[200] != want.Palette[200] {
t.Errorf("%s: fg %v bg %v cursor %v palette 1 %v, 200 %v; want %v %v %v %v %v", label,
got.Foreground, got.Background, got.Cursor, got.Palette[1], got.Palette[200],
want.Foreground, want.Background, want.Cursor, want.Palette[1], want.Palette[200])
}
}
own := dst.term.Colors(true)
step("at the start", "", own)
set := own
set.Foreground, set.Background, set.Cursor, set.HasCursor = vt.RGB{R: 0x10, G: 0x20, B: 0x30}, vt.RGB{R: 0xfe, G: 0xdc, B: 0xba}, vt.RGB{R: 0xff}, true
set.Palette[1], set.Palette[200] = vt.RGB{B: 0xff}, vt.RGB{G: 0x80}
step("set", "\x1b]10;#102030\x07\x1b]11;#fedcba\x07\x1b]12;#ff0000\x07\x1b]4;1;#0000ff;200;#008000\x07", set)
step("reset", "\x1b]110\x07\x1b]111\x07\x1b]112\x07\x1b]104\x07", own)
}
// The images programs place (Kitty graphics) show in the other terminal
// where they show here, sent once, scrolling as the rows do, and go when
// deleted: grok's preview of a pasted image showed nothing in a window of
// a server's session.
func TestMirrorImages(t *testing.T) {
loadLib(t)
src, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
dst, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
m, err := src.NewMirror()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { m.Close(); src.Close(); dst.Close() })
src.ResizePixels(40, 10, 8, 16)
dst.ResizePixels(40, 10, 8, 16)
frame := func() string {
f, _ := m.Frame()
dst.Feed(f)
return string(f)
}
frame()
placements := func(term *Terminal) []vt.Placement {
term.mu.Lock()
defer term.mu.Unlock()
var out []vt.Placement
term.term.Placements(func(p vt.Placement) {
if p.Visible {
p.ID = 0 // the other terminal's are the Mirror's
out = append(out, p)
}
})
return out
}
same := func(label string) {
t.Helper()
a, b := placements(src), placements(dst)
if len(a) == 0 && label != "deleted" {
t.Errorf("%s: nothing placed here", label)
}
if fmt.Sprint(a) != fmt.Sprint(b) {
t.Errorf("%s: the other terminal places %+v, want %+v", label, b, a)
}
}
src.Feed([]byte("\x1b[3;5H" + kittyImage(9, 16, 32, ui.RGB(255, 0, 0), ",C=1") + "after"))
if f := frame(); !strings.Contains(f, "a=t") {
t.Fatalf("the image's pixels were not sent: %q", f)
}
same("placed")
dst.mu.Lock()
img, ok := dst.term.Image(9)
dst.mu.Unlock()
if !ok || img.Width != 16 || img.Height != 32 || img.Pixels[0] != 255 || img.Pixels[1] != 0 {
t.Errorf("the other terminal's image is %v, %+v", ok, img)
}
if f := frame(); strings.Contains(f, "_G") {
t.Errorf("a frame with nothing new sent images again: %q", f)
}
src.Feed([]byte("\x1b[10;1H\n\n\n"))
if f := frame(); strings.Contains(f, "_G") {
t.Errorf("scrolling sent images again: %q", f)
}
same("scrolled")
src.Feed([]byte("\x1b_Ga=d,d=I,i=9,q=2\x1b\\"))
frame()
same("deleted")
if p := placements(dst); len(p) != 0 {
t.Errorf("the other terminal still places %+v", p)
}
}
// Images whose placements scrolled off go from the other terminal too when
// a Mirror starts it over: Pi, as it starts a new session, deletes its
// images and clears the screen and the scrollback, and the images it had
// placed stayed over the new session's text.
func TestMirrorImagesStartOver(t *testing.T) {
loadLib(t)
src, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
dst, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
m, err := src.NewMirror()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { m.Close(); src.Close(); dst.Close() })
src.ResizePixels(40, 10, 8, 16)
dst.ResizePixels(40, 10, 8, 16)
frame := func() {
f, _ := m.Frame()
dst.Feed(f)
}
frame()
placed := func(term *Terminal) int {
term.mu.Lock()
defer term.mu.Unlock()
n := 0
term.term.Placements(func(vt.Placement) { n++ })
return n
}
src.Feed([]byte("\x1b[2;1H" + kittyImage(9, 16, 32, ui.RGB(255, 0, 0), ",C=1")))
frame()
src.Feed([]byte("\x1b[10;1H" + strings.Repeat("\n", 20)))
frame()
if placed(dst) != 1 {
t.Fatalf("the other terminal places %d images, want 1", placed(dst))
}
src.Feed([]byte("\x1b_Ga=d,d=I,i=9,q=2\x1b\\\x1b[2J\x1b[H\x1b[3Jnew session"))
frame()
if n := placed(dst); n != 0 {
t.Errorf("the other terminal still places %d images", n)
}
}
// The other terminal sends the mouse's events in the format the terminal
// would, whatever order the program set and reset their modes in: the
// last of a setting's modes picks it, and the others stay set.
func TestMirrorMouseOrder(t *testing.T) {
loadLib(t)
for _, modes := range []string{
"\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1015h\x1b[?1006h",
"\x1b[?1003h\x1b[?1000h\x1b[?1006h\x1b[?1015h",
"\x1b[?1002h\x1b[?1003h\x1b[?1003l",
"\x1b[?1000h\x1b[?1016h\x1b[?1006h",
"\x1b[?1000h\x1b[?1006h\x1b[?1016h",
"\x1b[?1000h\x1b[?1015h\x1b[?1005h",
"\x1b[?1000h\x1b[?1005h\x1b[?1006h\x1b[?1006l",
"\x1b[?9h\x1b[?1000h\x1b[?9h\x1b[?1006h",
} {
src, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
dst, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
m, err := src.NewMirror()
if err != nil {
t.Fatal(err)
}
src.Feed([]byte(modes))
f, _ := m.Frame()
dst.Feed(f)
sends := func(term *vt.Terminal) string {
var out []string
for _, ev := range []struct {
pressed bool
action vt.MouseAction
button int
x float32
}{
{false, vt.MouseMotion, vt.ButtonNone, 5},
{false, vt.MousePress, vt.ButtonLeft, 1505},
{true, vt.MouseMotion, vt.ButtonLeft, 15},
{false, vt.MouseRelease, vt.ButtonLeft, 25},
} {
e, err := vt.NewMouseEncoder()
if err != nil {
t.Fatal(err)
}
e.Sync(term, 3000, 100, 10, 10, 0, 0, ev.pressed)
out = append(out, string(e.Encode(ev.action, ev.button, 0, ev.x, 5)))
e.Free()
}
return fmt.Sprintf("%q", out)
}
if got, want := sends(dst.term), sends(src.term); got != want {
t.Errorf("%q: the other terminal sends %s, want %s", modes, got, want)
}
m.Close()
src.Close()
dst.Close()
}
}
+40
View File
@@ -0,0 +1,40 @@
{
"libraries": [
{
"files": {
"darwin-amd64": {
"name": "libghostty-vt.dylib",
"sha256": "421e98d2683b39555209c59395655b4a217da0382e7669c92f6dff3949832664",
"url": "https://github.com/egoist/mygo/releases/download/libghostty-vt-befcdfd2c3a1/libghostty-vt-darwin-amd64.dylib"
},
"darwin-arm64": {
"name": "libghostty-vt.dylib",
"sha256": "6f385d3221f8c776ba40530db9baf8c71478907897959849896eeb0ddbf16b41",
"url": "https://github.com/egoist/mygo/releases/download/libghostty-vt-befcdfd2c3a1/libghostty-vt-darwin-arm64.dylib"
},
"linux-amd64": {
"name": "libghostty-vt.so",
"sha256": "9dcd8af0de67778a561f436cb673a9fb1738be8fa00849dad49606baed1e57d7",
"url": "https://github.com/egoist/mygo/releases/download/libghostty-vt-befcdfd2c3a1/libghostty-vt-linux-amd64.so"
},
"linux-arm64": {
"name": "libghostty-vt.so",
"sha256": "fb163f8f123206956751f1c4f0303b40899513b7dc171a8ab8d85ba7cd541bc0",
"url": "https://github.com/egoist/mygo/releases/download/libghostty-vt-befcdfd2c3a1/libghostty-vt-linux-arm64.so"
},
"windows-amd64": {
"name": "ghostty-vt.dll",
"sha256": "53e8e2dd979702e8f2c48107af19be5a76efc2e88eb7cf1097218e899665da41",
"url": "https://github.com/egoist/mygo/releases/download/libghostty-vt-befcdfd2c3a1/libghostty-vt-windows-amd64.dll"
},
"windows-arm64": {
"name": "ghostty-vt.dll",
"sha256": "de56a362f12cce8be38e883ffc8aec90a890e0574eb73aac6e833a60fda26064",
"url": "https://github.com/egoist/mygo/releases/download/libghostty-vt-befcdfd2c3a1/libghostty-vt-windows-arm64.dll"
}
},
"name": "libghostty-vt",
"source": "https://github.com/ghostty-org/ghostty/tree/befcdfd2c3a1cb24d9ec886e93c95b2b5daa7028"
}
]
}
File diff suppressed because it is too large. Load diff
+445
View File
@@ -0,0 +1,445 @@
package terminal
import (
"errors"
"fmt"
"os/exec"
"slices"
"strings"
"time"
"unicode"
"unicode/utf8"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
"github.com/egoist/mygo/transfer"
)
// notTakenAfter is how long after a paste's offer is written OnPasteStatus
// tells that the program did not read it: long enough for a program far
// away, over SSH, to read it.
var notTakenAfter = 5 * time.Second
// Paste pastes text, as PasteData does: bracketed when the program asks
// (mode 2004), so that it does not run as commands as it would typed, or
// offered to a program that reads the clipboard itself (mode 5522), which
// reads it as text/plain.
func (t *Terminal) Paste(text string) {
if text != "" {
t.PasteData(transfer.TextData(text))
}
}
// PasteData pastes data, as the paste keys paste the clipboard. A program
// that reads the clipboard itself (mode 5522, the Kitty clipboard
// protocol, as programs that take images do) is offered d's formats as
// MIME types (a file list as text/uri-list) and reads those it wants,
// even over SSH; any other gets d's text (transfer.Text), bracketed when
// it asks (mode 2004). With no text but other formats, as only an image,
// a program that asks for bracketed pastes gets an empty one, as VS
// Code's terminal sends, and any other nothing.
//
// The terminal keeps a snapshot of d until the program reads it or
// another paste comes, and answers only that read: other terminals showing
// the same program, as other windows on a session, stay silent. A
// representation made with transfer.Lazy is read only when the program
// asks for it, on a goroutine of the terminal while it processes the
// program's output: its provider must not call the terminal nor wait on
// the main thread.
func (t *Terminal) PasteData(d transfer.Data) {
t.pasteData(d, nil)
}
// pasteOffer is what a paste offered a program that reads the clipboard
// itself.
type pasteOffer struct {
data transfer.Data
mimes []string
}
// offerMIME returns the MIME type a paste offers format as, or "" for a
// format the protocol does not carry: one of MyGo's own, or no MIME type.
func offerMIME(f transfer.Format) string {
if f == transfer.FileList {
return string(transfer.URIList)
}
m := string(f)
if !strings.Contains(m, "/") || strings.ContainsAny(m, " \t") || strings.HasPrefix(m, "application/x-mygo-") {
return ""
}
return m
}
func newOffer(d transfer.Data) *pasteOffer {
o := &pasteOffer{data: d}
for _, f := range d.Formats() {
if m := offerMIME(f); m != "" && !slices.Contains(o.mimes, m) {
o.mimes = append(o.mimes, m)
}
}
return o
}
// read reads what the offer has of a MIME type.
func (o *pasteOffer) read(mime string) []byte {
if !slices.Contains(o.mimes, mime) {
return nil
}
return readFormat(o.data, mime)
}
// readFormat reads what data holds of a MIME type, as the protocols
// carry it: a file list answers text/uri-list.
func readFormat(d transfer.Data, mime string) []byte {
b, err := d.Read(transfer.Format(mime))
if errors.Is(err, transfer.ErrFormat) && mime == string(transfer.URIList) {
b, err = d.Read(transfer.FileList)
}
if err != nil {
return nil
}
return b
}
// pasteData pastes d; held are the formats the clipboard held when the
// view read only some of them, which tell whether a paste of no text had
// something else.
func (t *Terminal) pasteData(d transfer.Data, held []transfer.Format) {
o := newOffer(d.Snapshot())
if held == nil {
held = o.data.Formats()
}
t.mu.Lock()
if t.term == nil {
t.mu.Unlock()
return
}
var data []byte
var status PasteStatus = -1
if len(o.mimes) > 0 && t.term.PasteEvent(o.mimes) {
// The event went to the input queue; the offer waits for the
// program's read.
t.offer = o
status = PasteOffered
} else {
text, _ := o.data.Read(transfer.Text)
bracketed := t.term.Mode(vt.ModeBracketedPaste)
switch {
case len(text) > 0:
data = vt.EncodePaste(string(text), bracketed)
case !slices.ContainsFunc(held, func(f transfer.Format) bool { return f != transfer.Text }):
case bracketed:
// An empty bracketed paste, as VS Code's terminal sends, which
// programs that take images, as Claude Code, read as a paste
// of what the clipboard holds and read it themselves.
data = []byte("\x1b[200~\x1b[201~")
default:
status = PasteNoText
}
}
t.term.ScrollToBottom()
t.mu.Unlock()
t.Send(data)
t.redraw()
if status < 0 {
return
}
// Once what the paste sent is written, from the queue's goroutine as
// the other statuses.
t.in.pushDone(nil, func() {
t.pasteStatus(PasteProgress{Status: status})
if status != PasteOffered {
return
}
time.AfterFunc(notTakenAfter, func() {
t.mu.Lock()
waiting := t.offer == o
t.mu.Unlock()
if waiting {
t.pasteStatus(PasteProgress{Status: PasteNotTaken})
}
})
})
}
func (t *Terminal) pasteStatus(p PasteProgress) {
if on := t.opts.OnPasteStatus; on != nil {
on(p)
}
}
// clipboardRequest is a program's read of the clipboard that waits for
// the main thread: t.mu guards it (the reader queues it, a frame takes it
// and answers it, and Allow and Deny set answer from any goroutine).
type clipboardRequest struct {
t *Terminal
deferred *vt.DeferredClipboardRead
mimes []string
list bool
primary bool
ask bool // the app is asked before it is answered
text string
// answer is 0 until Allow (1) or Deny (2), the first of which wins;
// asked tells that Options.OnClipboardRequest was called with it.
answer int8
asked bool
}
// clipboardRead answers a program's read of the clipboard. What a paste
// offered the program is answered as it was; a read with a password that
// this terminal cannot grant is left to the terminal the paste was made
// in, which stays silent otherwise; and other reads follow
// Options.ClipboardRead: refused, or answered with the clipboard read on
// the main thread (ClipboardDeferred), which may first ask the app.
// t.mu is held.
func (t *Terminal) clipboardRead(req vt.ClipboardRead) (vt.ClipboardReply, vt.ClipboardAnswer) {
o := t.offer
if req.Granted && o != nil {
t.offer = nil
reply := vt.ClipboardReply{Contents: map[string][]byte{}}
for _, mime := range req.Mimes {
if b := o.read(mime); len(b) > 0 {
reply.Contents[mime] = b
}
}
if req.List {
reply.Available = slices.Clone(o.mimes)
}
// The reply, encoded, comes to WritePTY as this returns.
t.replying = len(reply.Contents) > 0
return reply, vt.ClipboardAnswered
}
if req.CanRemember {
// The read carries a paste event's password, which this terminal
// does not know: it is another window's paste follow-up, and the
// terminal that pasted answers it. Staying silent keeps this one
// from answering twice.
return vt.ClipboardReply{}, vt.ClipboardRefused
}
if t.opts.ClipboardRead == ClipboardForward {
// Silent, as a read another terminal answers: an OSC 52 read goes
// on with a Mirror's next frame.
if len(req.Mimes) == 1 && req.Mimes[0] == "text/plain" && !req.List {
t.clipForward = queue(t.clipForward, req.Primary)
t.redraw()
}
return vt.ClipboardReply{}, vt.ClipboardRefused
}
if t.opts.ClipboardRead == ClipboardDeny {
// A policy denial is the answer — the library writes an empty
// OSC 52 reply, or EPERM for OSC 5522 — so it goes through the
// replied path, not ClipboardRefused, which keeps the terminal
// silent for another window to answer.
return vt.ClipboardReply{}, vt.ClipboardAnswered
}
r := &clipboardRequest{
t: t,
deferred: &vt.DeferredClipboardRead{},
mimes: slices.Clone(req.Mimes),
list: req.List,
primary: req.Primary,
ask: t.opts.ClipboardRead == ClipboardAsk,
}
if r.ask && req.List && len(req.Mimes) == 0 {
// A read of the types available is served without asking, as
// Kitty does.
r.ask = false
}
t.clipReads = append(t.clipReads, r)
t.redraw()
return vt.ClipboardReply{Deferred: r.deferred}, vt.ClipboardDeferred
}
// maxQueued bounds what programs' uses of the clipboard queue for a frame
// to take, which none may take, as a server's terminal no window shows:
// the latest are kept.
const maxQueued = 16
// queue appends v to q, which keeps maxQueued at most.
func queue[T any](q []T, v T) []T {
if len(q) >= maxQueued {
q = append(q[:0], q[len(q)-maxQueued+1:]...)
}
return append(q, v)
}
// sendReply queues a paste's reply in pieces, each telling how far it went
// once written, which a slow link makes worth watching; t.mu is held.
func (t *Terminal) sendReply(p []byte) {
total, sent := int64(len(p)), int64(0)
// Told from the queue's goroutine, as the pieces are: here the
// terminal is locked, which OnPasteStatus may need.
t.in.pushDone(nil, func() {
t.pasteStatus(PasteProgress{Status: PasteSending, Total: total})
})
for len(p) > 0 {
n := min(len(p), 64<<10)
piece := append([]byte(nil), p[:n]...)
p = p[n:]
sent += int64(n)
status, done := PasteSending, sent
if len(p) == 0 {
status = PasteSent
}
t.in.pushDone(piece, func() {
t.pasteStatus(PasteProgress{Status: status, Sent: done, Total: total})
})
}
}
// readsClipboard reports whether the program reads the clipboard itself
// (mode 5522), as a paste then offers it all the clipboard holds.
func (t *Terminal) readsClipboard() bool {
t.mu.Lock()
defer t.mu.Unlock()
return t.term != nil && t.term.Mode(vt.ModePasteEvents)
}
// dropFiles pastes the paths of files dropped on the terminal, as Ghostty
// does: each quoted for the program's shell, spaces between them, so that
// a shell takes them as arguments and an agent as files it attaches. A
// program that reads the clipboard itself (mode 5522) is offered them as a
// file list too, when the paths make one.
func (t *Terminal) dropFiles(paths []string) {
if len(paths) == 0 {
return
}
escaped := make([]string, len(paths))
for i, p := range paths {
escaped[i] = t.quoting.quote(p)
}
text := transfer.Bytes(transfer.Text, []byte(strings.Join(escaped, " ")))
d, err := transfer.FileData(paths...)
if err != nil {
t.PasteData(transfer.New(transfer.NewItem(text)))
return
}
items := d.Items()
first, _ := items[0].Read(transfer.FileList)
items[0] = transfer.NewItem(transfer.Bytes(transfer.FileList, first), transfer.Bytes(transfer.URIList, first), text)
t.PasteData(transfer.New(items...))
}
// quoting is how a shell takes a path as one argument, whatever it holds.
type quoting int
const (
// quotePOSIX: a backslash before each character a POSIX shell, or
// fish, would read otherwise, as Ghostty escapes them; a path with
// control characters, as a newline, which would end the command, is
// quoted as $'…', where they are escapes.
quotePOSIX quoting = iota
// quotePowerShell: single quotes, in which PowerShell expands nothing,
// unlike its double quotes ($(…), $var and `), each single quote in the
// path doubled. A POSIX shell takes them too.
quotePowerShell
// quoteCmd: double quotes, in which cmd.exe reads & | < > ^ as text.
quoteCmd
)
// quotingFor returns the quoting of the shell a terminal runs, by the
// program's name: PowerShell's, cmd.exe's or a POSIX shell's, and for
// another program on Windows PowerShell's, the shell the terminal runs
// when given none (command), elsewhere a POSIX shell's. A Conn's program, which the terminal does not know, takes the
// platform's.
func quotingFor(goos string, program string) quoting {
name := program
if i := strings.LastIndexAny(name, `/\`); i >= 0 {
name = name[i+1:]
}
name = strings.TrimSuffix(strings.ToLower(name), ".exe")
switch {
case name == "pwsh" || name == "powershell":
return quotePowerShell
case name == "cmd":
return quoteCmd
case slices.Contains([]string{"sh", "bash", "zsh", "fish", "dash", "ksh", "mksh"}, name):
return quotePOSIX
case goos == "windows":
if program == "" {
// No program: the default shell, PowerShell where there is one.
if _, err := exec.LookPath("pwsh.exe"); err == nil {
return quotePowerShell
}
if _, err := exec.LookPath("powershell.exe"); err == nil {
return quotePowerShell
}
return quoteCmd
}
return quotePowerShell
}
return quotePOSIX
}
// quote quotes a path for the shell.
func (q quoting) quote(path string) string {
switch q {
case quotePowerShell:
if !strings.ContainsFunc(path, plainPathRune) && path != "" {
return path
}
var b strings.Builder
b.WriteByte('\'')
for _, r := range path {
b.WriteRune(r)
// PowerShell's single quotes: ' and the curly ones, ‘ ’ ‚ ‛,
// which a file name may hold.
if r == '\'' || r == '\u2018' || r == '\u2019' || r == '\u201a' || r == '\u201b' {
b.WriteRune(r)
}
}
b.WriteByte('\'')
return b.String()
case quoteCmd:
if strings.ContainsAny(path, " \t&()[]{}^=;!'+,`~|<>") {
return `"` + path + `"`
}
return path
}
if strings.ContainsFunc(path, func(r rune) bool { return r == utf8.RuneError || unicode.IsControl(r) }) {
return ansiCQuote(path)
}
var b strings.Builder
for _, r := range path {
if strings.ContainsRune("\\ ()[]{}<>\"'`!#$&;|*?\t", r) {
b.WriteByte('\\')
}
b.WriteRune(r)
}
return b.String()
}
// plainPathRune reports whether r is not one that PowerShell takes as a
// path's own unquoted: a letter, a digit or one of _ - . : \ /.
func plainPathRune(r rune) bool {
switch {
case 'a' <= r && r <= 'z', 'A' <= r && r <= 'Z', '0' <= r && r <= '9':
return false
}
return !strings.ContainsRune(`_-.:\/`, r)
}
// ansiCQuote quotes s as bash, zsh and ksh's $'…': control characters and
// bytes that are not UTF-8 as \xHH, a backslash and a single quote
// escaped. A shell without it, as fish, reads it as something other than
// the path, never as a command.
func ansiCQuote(s string) string {
var b strings.Builder
b.WriteString("$'")
for i := 0; i < len(s); {
r, n := utf8.DecodeRuneInString(s[i:])
switch {
case r == utf8.RuneError && n <= 1 || unicode.IsControl(r):
for _, c := range []byte(s[i : i+n]) {
fmt.Fprintf(&b, "\\x%02x", c)
}
case r == '\\' || r == '\'':
b.WriteByte('\\')
b.WriteRune(r)
default:
b.WriteString(s[i : i+n])
}
i += n
}
b.WriteByte('\'')
return b.String()
}
+209
View File
@@ -0,0 +1,209 @@
package terminal
import (
"slices"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
"github.com/egoist/mygo/ui"
)
// placeholder is the character of a cell that shows part of an image
// placed virtually (Kitty graphics' Unicode placeholders), as yazi shows
// its previews: the cell's foreground color is the image's id, its
// underline color the placement's, and its combining marks the row and
// column of the image it shows.
const placeholder = 0x10eeee
// holderRun is a run of placeholder cells of a row, from column x for w
// columns, that show one row of a virtual placement of an image, from
// cell row, col of it.
type holderRun struct {
x, w int
image, placement uint32
row, col int
high int // the image id's high byte, -1 when left out
}
// holderCell is what a placeholder cell says: row, col and high are -1
// when it leaves them out.
type holderCell struct {
image, placement uint32 // image's low 24 bits
row, col, high int
}
// readHolder reads a placeholder cell of a style and combining marks.
// Marks not in the table count as left out, as in Kitty and Ghostty.
func readHolder(s vt.Style, marks []rune) holderCell {
h := holderCell{image: colorID(s.FG), placement: colorID(s.UnderlineColor), row: -1, col: -1, high: -1}
if len(marks) > 0 {
h.row = diacritic(marks[0])
}
if len(marks) > 1 {
h.col = diacritic(marks[1])
}
if len(marks) > 2 {
if d := diacritic(marks[2]); d < 256 {
h.high = d
}
}
return h
}
// colorID is the id a color gives: a palette index, or 24 bits of RGB.
func colorID(c vt.Color) uint32 {
switch c.Kind {
case 1:
return uint32(c.Index)
case 2:
return uint32(c.RGB.R)<<16 | uint32(c.RGB.G)<<8 | uint32(c.RGB.B)
}
return 0
}
// addHolder adds a placeholder cell at column x to the row's runs: it
// continues the run to its left when it is of the same image and
// placement and leaves out what would continue it, or says the same, and
// starts a run otherwise, at row and column 0 of what it leaves out.
func addHolder(runs []holderRun, x int, h holderCell) []holderRun {
if n := len(runs); n > 0 {
r := &runs[n-1]
if r.x+r.w == x && r.image&0xffffff == h.image && r.placement == h.placement &&
(h.row < 0 || h.row == r.row) && (h.col < 0 || h.col == r.col+r.w) && (h.high < 0 || h.high == r.high) {
r.w++
return runs
}
}
r := holderRun{x: x, w: 1, image: h.image, placement: h.placement, row: max(h.row, 0), col: max(h.col, 0), high: h.high}
if h.high >= 0 {
r.image |= uint32(h.high) << 24
}
return append(runs, r)
}
// virtualImage is a virtual placement of an image, which placeholder
// cells show: cols and rows are the cells the image fits in, 0 for those
// its size takes.
type virtualImage struct {
id uint32
bmp *ui.Bitmap
imgW, imgH int
cols, rows int
layer int
}
// virtualFor returns the virtual placement that placeholders of an image
// and placement show: placement's, or for 0 the image's of the lowest id.
func (v *view) virtualFor(image, placement uint32) (virtualImage, bool) {
var best virtualImage
found := false
for _, vi := range v.virtual[image] {
if placement != 0 {
if vi.id == placement {
return vi, true
}
continue
}
if !found || vi.id < best.id {
best, found = vi, true
}
}
return best, found
}
// holderRegion returns the part of a virtual placement's image that a run
// of placeholders shows, src in the image's pixels, and where it goes, dst
// from the run's top left in device pixels: the image fits the
// placement's cells, centered, as in Ghostty. ok is false when the run
// shows none of it.
func holderRegion(h holderRun, vi virtualImage, cw, ch int) (src, dst ui.Rect, ok bool) {
cols, rows := vi.cols, vi.rows
if rows <= 0 {
rows = (vi.imgH + ch - 1) / ch
}
if cols <= 0 {
cols = (vi.imgW + cw - 1) / cw
}
if cols <= 0 || rows <= 0 || vi.imgW <= 0 || vi.imgH <= 0 {
return src, dst, false
}
iw, ih := float32(vi.imgW), float32(vi.imgH)
pw, ph := float32(cols*cw), float32(rows*ch)
scale := min(pw/iw, ph/ih)
img := ui.Rect{X: (pw - iw*scale) / 2, Y: (ph - ih*scale) / 2, W: iw * scale, H: ih * scale}
run := ui.Rect{X: float32(h.col * cw), Y: float32(h.row * ch), W: float32(h.w * cw), H: float32(ch)}
x0, y0 := max(img.X, run.X), max(img.Y, run.Y)
x1, y1 := min(img.X+img.W, run.X+run.W), min(img.Y+img.H, run.Y+run.H)
if x1 <= x0 || y1 <= y0 {
return src, dst, false
}
src = ui.Rect{X: (x0 - img.X) / scale, Y: (y0 - img.Y) / scale, W: (x1 - x0) / scale, H: (y1 - y0) / scale}
dst = ui.Rect{X: x0 - run.X, Y: y0 - run.Y, W: x1 - x0, H: y1 - y0}
return src, dst, true
}
// drawHolders draws what placeholder cells show of the virtual
// placements of a layer, within grid.
func (v *view) drawHolders(p *ui.Painter, layer int, ox, oy float32, grid ui.Rect) {
s := v.scale
for y := range v.lines {
for _, h := range v.lines[y].holders {
vi, ok := v.virtualFor(h.image, h.placement)
if !ok || vi.layer != layer {
continue
}
src, dst, ok := holderRegion(h, vi, v.cellW, v.cellH)
if !ok {
continue
}
dst.X = ox + (float32(h.x*v.cellW)+dst.X)/s
dst.Y = oy + (float32(y*v.cellH)+dst.Y)/s
dst.W, dst.H = dst.W/s, dst.H/s
p.Clip(grid, 0, func() { p.ImageRegion(vi.bmp, src, dst, ui.ImageOptions{}) })
}
}
}
// diacritic returns the number a combining mark stands for in a
// placeholder's row, column or id, -1 for none.
func diacritic(r rune) int {
i, ok := slices.BinarySearch(diacritics, r)
if !ok {
return -1
}
return i
}
// diacritics are the combining marks of the numbers from 0, Kitty's
// rowcolumn-diacritics.txt.
var diacritics = []rune{
0x0305, 0x030d, 0x030e, 0x0310, 0x0312, 0x033d, 0x033e, 0x033f, 0x0346, 0x034a,
0x034b, 0x034c, 0x0350, 0x0351, 0x0352, 0x0357, 0x035b, 0x0363, 0x0364, 0x0365,
0x0366, 0x0367, 0x0368, 0x0369, 0x036a, 0x036b, 0x036c, 0x036d, 0x036e, 0x036f,
0x0483, 0x0484, 0x0485, 0x0486, 0x0487, 0x0592, 0x0593, 0x0594, 0x0595, 0x0597,
0x0598, 0x0599, 0x059c, 0x059d, 0x059e, 0x059f, 0x05a0, 0x05a1, 0x05a8, 0x05a9,
0x05ab, 0x05ac, 0x05af, 0x05c4, 0x0610, 0x0611, 0x0612, 0x0613, 0x0614, 0x0615,
0x0616, 0x0617, 0x0657, 0x0658, 0x0659, 0x065a, 0x065b, 0x065d, 0x065e, 0x06d6,
0x06d7, 0x06d8, 0x06d9, 0x06da, 0x06db, 0x06dc, 0x06df, 0x06e0, 0x06e1, 0x06e2,
0x06e4, 0x06e7, 0x06e8, 0x06eb, 0x06ec, 0x0730, 0x0732, 0x0733, 0x0735, 0x0736,
0x073a, 0x073d, 0x073f, 0x0740, 0x0741, 0x0743, 0x0745, 0x0747, 0x0749, 0x074a,
0x07eb, 0x07ec, 0x07ed, 0x07ee, 0x07ef, 0x07f0, 0x07f1, 0x07f3, 0x0816, 0x0817,
0x0818, 0x0819, 0x081b, 0x081c, 0x081d, 0x081e, 0x081f, 0x0820, 0x0821, 0x0822,
0x0823, 0x0825, 0x0826, 0x0827, 0x0829, 0x082a, 0x082b, 0x082c, 0x082d, 0x0951,
0x0953, 0x0954, 0x0f82, 0x0f83, 0x0f86, 0x0f87, 0x135d, 0x135e, 0x135f, 0x17dd,
0x193a, 0x1a17, 0x1a75, 0x1a76, 0x1a77, 0x1a78, 0x1a79, 0x1a7a, 0x1a7b, 0x1a7c,
0x1b6b, 0x1b6d, 0x1b6e, 0x1b6f, 0x1b70, 0x1b71, 0x1b72, 0x1b73, 0x1cd0, 0x1cd1,
0x1cd2, 0x1cda, 0x1cdb, 0x1ce0, 0x1dc0, 0x1dc1, 0x1dc3, 0x1dc4, 0x1dc5, 0x1dc6,
0x1dc7, 0x1dc8, 0x1dc9, 0x1dcb, 0x1dcc, 0x1dd1, 0x1dd2, 0x1dd3, 0x1dd4, 0x1dd5,
0x1dd6, 0x1dd7, 0x1dd8, 0x1dd9, 0x1dda, 0x1ddb, 0x1ddc, 0x1ddd, 0x1dde, 0x1ddf,
0x1de0, 0x1de1, 0x1de2, 0x1de3, 0x1de4, 0x1de5, 0x1de6, 0x1dfe, 0x20d0, 0x20d1,
0x20d4, 0x20d5, 0x20d6, 0x20d7, 0x20db, 0x20dc, 0x20e1, 0x20e7, 0x20e9, 0x20f0,
0x2cef, 0x2cf0, 0x2cf1, 0x2de0, 0x2de1, 0x2de2, 0x2de3, 0x2de4, 0x2de5, 0x2de6,
0x2de7, 0x2de8, 0x2de9, 0x2dea, 0x2deb, 0x2dec, 0x2ded, 0x2dee, 0x2def, 0x2df0,
0x2df1, 0x2df2, 0x2df3, 0x2df4, 0x2df5, 0x2df6, 0x2df7, 0x2df8, 0x2df9, 0x2dfa,
0x2dfb, 0x2dfc, 0x2dfd, 0x2dfe, 0x2dff, 0xa66f, 0xa67c, 0xa67d, 0xa6f0, 0xa6f1,
0xa8e0, 0xa8e1, 0xa8e2, 0xa8e3, 0xa8e4, 0xa8e5, 0xa8e6, 0xa8e7, 0xa8e8, 0xa8e9,
0xa8ea, 0xa8eb, 0xa8ec, 0xa8ed, 0xa8ee, 0xa8ef, 0xa8f0, 0xa8f1, 0xaab0, 0xaab2,
0xaab3, 0xaab7, 0xaab8, 0xaabe, 0xaabf, 0xaac1, 0xfe20, 0xfe21, 0xfe22, 0xfe23,
0xfe24, 0xfe25, 0xfe26, 0x10a0f, 0x10a38, 0x1d185, 0x1d186, 0x1d187, 0x1d188, 0x1d189,
0x1d1aa, 0x1d1ab, 0x1d1ac, 0x1d1ad, 0x1d242, 0x1d243, 0x1d244,
}
+130
View File
@@ -0,0 +1,130 @@
package terminal
import (
"bytes"
"encoding/base64"
"fmt"
"strings"
"testing"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
"github.com/egoist/mygo/ui"
)
// halves returns the Kitty graphics sequence that transmits a w×h image,
// its top half red and its bottom half blue, with more keys.
func halves(id, w, h int, keys string) string {
var px bytes.Buffer
for y := range h {
c := []byte{255, 0, 0, 255}
if y >= h/2 {
c = []byte{0, 0, 255, 255}
}
px.Write(bytes.Repeat(c, w))
}
return fmt.Sprintf("\x1b_Ga=T,f=32,s=%d,v=%d,i=%d,q=2%s;%s\x1b\\", w, h, id, keys, base64.StdEncoding.EncodeToString(px.Bytes()))
}
// Placeholder cells (Kitty graphics' Unicode placeholders, U+10EEEE)
// show their parts of the image placed virtually, by the image's id in
// their foreground color and the row and column in their combining
// marks, which the cells after the first may leave out: yazi shows its
// previews so, and showed tofu (kero#228).
func TestPlaceholders(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe(), Theme: LightTheme()})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 400, 200)
tt.Frame()
at := func(col, row int) ui.Color {
x, y := cellCenter(term, col, row)
c := tt.Image().RGBAAt(int(x*term.v.scale), int(y*term.v.scale))
return ui.RGB(c.R, c.G, c.B)
}
red, blue := ui.RGB(255, 0, 0), ui.RGB(0, 0, 255)
bg := LightTheme().Background
const p = "\U0010EEEE"
row0, row1, col2 := "̅", "̍", "̎"
// Image 7, four cells by two, placed virtually in four by two.
term.Feed([]byte(halves(7, 4*term.v.cellW, 2*term.v.cellH, ",U=1,c=4,r=2")))
// Its first row at row 1, column 2, then its second; the cells after
// the first of a row take their row and column from it.
term.Feed([]byte("\x1b[2;3H\x1b[38;5;7m" + p + row0 + row0 + strings.Repeat(p, 3) +
"\x1b[3;3H" + p + row1 + strings.Repeat(p, 3) +
// Its third column of its second row alone, at row 5.
"\x1b[5;1H" + p + row1 + col2 + "\x1b[0m"))
tt.Frame()
for _, c := range []struct {
col, row int
want ui.Color
}{
{2, 1, red}, {5, 1, red}, {2, 2, blue}, {5, 2, blue},
{1, 1, bg}, {6, 1, bg}, {2, 3, bg},
{0, 4, blue}, {1, 4, bg},
} {
if got := at(c.col, c.row); got != c.want {
t.Errorf("cell %d,%d is %v, want %v", c.col, c.row, got, c.want)
}
}
// Placeholders of an image without a virtual placement show nothing.
term.Feed([]byte("\x1b[7;1H\x1b[38;5;9m" + p + p + "\x1b[0m"))
tt.Frame()
if got := at(0, 6); got != bg {
t.Errorf("a placeholder of no placement is %v, want %v", got, bg)
}
}
// The other terminal of a Mirror gets the virtual placements, by their
// ids, and the placeholder cells that show them, and drops a placement
// when the program deletes it: yazi's previews in a server's session.
func TestMirrorPlaceholders(t *testing.T) {
loadLib(t)
src, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
dst, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
m, err := src.NewMirror()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { m.Close(); src.Close(); dst.Close() })
src.ResizePixels(40, 10, 8, 16)
dst.ResizePixels(40, 10, 8, 16)
frame := func() string {
f, _ := m.Frame()
dst.Feed(f)
return string(f)
}
frame()
virtual := func(term *Terminal) []string {
term.mu.Lock()
defer term.mu.Unlock()
var out []string
term.term.Placements(func(p vt.Placement) {
if p.Virtual {
out = append(out, fmt.Sprintf("i=%d p=%d c=%d r=%d", p.ImageID, p.ID, p.ParamCols, p.ParamRows))
}
})
return out
}
src.Feed([]byte(halves(5, 16, 32, ",U=1,p=3,c=2,r=2") + "\x1b[38;5;5m\x1b[58;5;3m\U0010EEEE̅\U0010EEEE\x1b[0m"))
frame()
if a, b := virtual(src), virtual(dst); len(a) != 1 || fmt.Sprint(a) != fmt.Sprint(b) {
t.Errorf("the other terminal places %v virtually, want %v", b, a)
}
if f := frame(); strings.Contains(f, "_G") {
t.Errorf("a frame with nothing new sent images again: %q", f)
}
src.Feed([]byte("\x1b_Ga=d,d=i,i=5,p=3,q=2\x1b\\"))
frame()
if b := virtual(dst); len(b) != 0 {
t.Errorf("the other terminal still places %v virtually", b)
}
}
+128
View File
@@ -0,0 +1,128 @@
package terminal
import (
"math"
"strings"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
)
// promptRow is a row of the shell's prompt and its input, as clickToMove
// counts the characters the shell's cursor moves over: the column of each
// of its runes, how many columns its text takes (blanks after it are not
// the input's), and whether it soft-wraps into the next row.
type promptRow struct {
cols []int
end int
wrap bool
}
// newPromptRow makes a promptRow of a row's text and columns, as
// vt.Terminal.RowText returns them.
func newPromptRow(text []rune, cols []int, wrap bool) promptRow {
r := promptRow{cols: cols, wrap: wrap}
for i, c := range text {
if c != ' ' {
r.end = cols[i] + 1
}
}
return r
}
// clickToMove moves the shell's cursor to the cell clicked on the input of
// its prompt, as Ghostty and kitty do on Alt+click, by sending the arrow
// keys that the shell moves its cursor by, and reports whether the click
// was there. The shell marks its prompt with OSC 133 (shell integration):
// the input is on the cursor's row of the prompt and the rows the prompt
// goes on over, above and below it. It does nothing on the alternate
// screen, nor while the view shows the scrollback. t.mu is held.
func (v *view) clickToMove(col, row int) bool {
term := v.t.term
cx, cy := term.Cursor()
if term.AltScreen() || !term.AtBottom() {
return false
}
if p, _ := term.Row(cy); p == vt.NoPrompt {
return false
}
_, n := term.Size()
top, bottom := cy, cy
for top > 0 {
if p, _ := term.Row(top); p != vt.PromptContinuation {
break
}
top--
}
for bottom+1 < n {
if p, _ := term.Row(bottom + 1); p != vt.PromptContinuation {
break
}
bottom++
}
if row < top || row > bottom {
return false
}
rows := make([]promptRow, 0, bottom-top+1)
for y := top; y <= bottom; y++ {
text, cols := term.RowText(y)
_, wrap := term.Row(y)
rows = append(rows, newPromptRow(text, cols, wrap))
}
v.t.Send(promptArrows(rows, cx, cy-top, col, row-top, term.Mode(vt.ModeCursorKeys)))
return true
}
// promptArrows returns the arrow keys that move the shell's cursor from
// column cx of rows[cy] to column col of rows[row]: Left or Right as many
// times as there are characters between, counted over the rows between as
// the shell holds them, a row's text and the line break after it unless it
// soft-wraps (its blanks then too). A click past the end of a row's text
// moves to its end and no further, as a Right arrow at the end of the input
// would accept a shell's suggestion (zsh-autosuggestions, fish). The arrows
// are the application's (ESC O) when the shell set DECCKM, the normal ones
// (CSI) otherwise.
func promptArrows(rows []promptRow, cx, cy, col, row int, application bool) []byte {
// end returns how many columns of row y the shell's text takes: all
// when it wraps, and up to the cursor on the cursor's row, where
// blanks typed before it are text.
end := func(y int) int {
switch r := rows[y]; {
case r.wrap:
return math.MaxInt
case y == cy:
return max(r.end, cx)
default:
return r.end
}
}
// offset counts the characters before column x of row y.
offset := func(x, y int) int {
n := 0
for i := range y {
for _, c := range rows[i].cols {
if c < end(i) {
n++
}
}
if !rows[i].wrap {
n++ // the line break
}
}
for _, c := range rows[y].cols {
if c < min(x, end(y)) {
n++
}
}
return n
}
steps := offset(col, row) - offset(cx, cy)
key := "C"
if steps < 0 {
key, steps = "D", -steps
}
intro := "\x1b["
if application {
intro = "\x1bO"
}
return []byte(strings.Repeat(intro+key, steps))
}
+163
View File
@@ -0,0 +1,163 @@
package terminal
import (
"strings"
"testing"
"github.com/egoist/mygo/ui"
)
// rowsOf returns the rows of a prompt as a terminal of 10 columns shows
// them, a "+" ending those that soft-wrap.
func rowsOf(lines ...string) []promptRow {
rows := make([]promptRow, len(lines))
for i, l := range lines {
l, wrap := strings.CutSuffix(l, "+")
text := []rune(l + strings.Repeat(" ", 10-len(l)))
cols := make([]int, len(text))
for x := range cols {
cols[x] = x
}
rows[i] = newPromptRow(text, cols, wrap)
}
return rows
}
func TestPromptArrows(t *testing.T) {
for _, c := range []struct {
name string
rows []promptRow
cx, cy, col, row int
application bool
want string
}{
{"left on the row", rowsOf("$ echo hi"), 9, 0, 4, 0, false, "\x1b[D\x1b[D\x1b[D\x1b[D\x1b[D"},
{"right on the row", rowsOf("$ echo hi"), 2, 0, 4, 0, false, "\x1b[C\x1b[C"},
{"on the cursor", rowsOf("$ echo hi"), 4, 0, 4, 0, false, ""},
{"application cursor keys", rowsOf("$ echo hi"), 9, 0, 7, 0, true, "\x1bOD\x1bOD"},
// Past the end of the text: to its end, and no further.
{"past the end", rowsOf("$ echo hi"), 2, 0, 9, 0, false, strings.Repeat("\x1b[C", 7)},
{"past the end at the end", rowsOf("$ echo hi"), 9, 0, 9, 0, false, ""},
// Blanks typed before the cursor are the input's.
{"typed blanks", rowsOf("$ ab"), 7, 0, 4, 0, false, strings.Repeat("\x1b[D", 3)},
// Over the rows a command wraps onto, their every column.
{"up a wrap", rowsOf("$ echo he+", "llo worl+", "d"), 1, 2, 7, 0, false, strings.Repeat("\x1b[D", 14)},
{"down a wrap", rowsOf("$ echo he+", "llo worl+", "d"), 7, 0, 1, 2, false, strings.Repeat("\x1b[C", 14)},
{"down a wrap past the end", rowsOf("$ echo he+", "llo worl+", "d"), 7, 0, 6, 2, false, strings.Repeat("\x1b[C", 14)},
{"onto a wrapped row's end", rowsOf("$ echo he+", "llo worl+", "d"), 1, 2, 9, 1, false, "\x1b[D\x1b[D"},
// A line break is a character, the blanks after its text none.
{"up a line break", rowsOf("$ abc", "de"), 1, 1, 3, 0, false, strings.Repeat("\x1b[D", 4)},
{"down a line break", rowsOf("$ abc", "de"), 3, 0, 2, 1, false, strings.Repeat("\x1b[C", 5)},
} {
if got := string(promptArrows(c.rows, c.cx, c.cy, c.col, c.row, c.application)); got != c.want {
t.Errorf("%s: sent %q, want %q", c.name, got, c.want)
}
}
}
// Alt+click on the input of a shell's prompt (OSC 133) moves its cursor
// there, with arrow keys, and selects nothing; elsewhere it does nothing.
func TestAltClickMovesTheCursor(t *testing.T) {
loadLib(t)
conn := newPipe()
term, err := New(Options{Conn: conn})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill().AutoFocus() }, 400, 200)
tt.Frame()
term.mu.Lock()
cols, _ := term.term.Size()
term.mu.Unlock()
// A command that wraps onto a second row, the cursor 3 characters
// before its end.
command := "echo " + strings.Repeat("x", cols)
term.Feed([]byte("out\r\n\x1b]133;A\a$ \x1b]133;B\a" + command + "\x1b[3D"))
tt.Frame()
click := func(col, row int) string {
t.Helper()
x, y := cellCenter(term, col, row)
tt.ClickAtWith(ui.Alt, x, y)
return conn.take(term)
}
cx := (2+len(command))%cols - 3
if got, want := click(2, 1), strings.Repeat("\x1b[D", len(command)-3); got != want {
t.Errorf("Alt+click on the input's start sent %q, want %q", got, want)
}
if got, want := click(cols-1, 2), "\x1b[C\x1b[C\x1b[C"; got != want {
t.Errorf("Alt+click past the input's end sent %q, want %q", got, want)
}
if got := click(cx, 2); got != "" {
t.Errorf("Alt+click on the cursor sent %q", got)
}
term.mu.Lock()
text, selected := term.term.SelectionText()
term.mu.Unlock()
if selected {
t.Errorf("Alt+click selected %q", text)
}
// Outside the input: the output above, the rows below.
if got := click(1, 0); got != "" {
t.Errorf("Alt+click on the output sent %q", got)
}
if got := click(1, 3); got != "" {
t.Errorf("Alt+click below the input sent %q", got)
}
// Cursor keys in the application's mode, which the shell set.
term.Feed([]byte("\x1b[?1h"))
if got := click(cx-1, 2); got != "\x1bOD" {
t.Errorf("Alt+click with DECCKM sent %q", got)
}
term.Feed([]byte("\x1b[?1l"))
// A click without Alt selects as ever.
x, y := cellCenter(term, 2, 1)
tt.ClickAt(x, y)
if got := conn.take(term); got != "" {
t.Errorf("a click sent %q", got)
}
// Not while the view shows the scrollback, where the rows are others
// than the cursor's: below, a prompt whose input wraps, its first row
// where the cursor's shows once scrolled back a row.
term.Feed([]byte("\x1b]133;C\a" + strings.Repeat("\r\n", 30) + "\x1b]133;A\a$ \x1b]133;B\a" + command))
term.mu.Lock()
_, cy := term.term.Cursor()
term.term.ScrollBy(-1)
term.mu.Unlock()
tt.Frame()
if got := click(2, cy); got != "" {
t.Errorf("Alt+click on the scrollback sent %q", got)
}
term.mu.Lock()
term.term.ScrollToBottom()
term.mu.Unlock()
tt.Frame()
if got, want := click(2, cy-1), strings.Repeat("\x1b[D", len(command)); got != want {
t.Errorf("Alt+click at the bottom again sent %q, want %q", got, want)
}
// Not on a full-screen program's screen.
term.Feed([]byte("\x1b[?1049h\x1b[H\x1b]133;A\a$ \x1b]133;B\aecho hi"))
tt.Frame()
if got := click(2, 0); got != "" {
t.Errorf("Alt+click on the alternate screen sent %q", got)
}
}
// A shell that does not mark its prompt gets no arrows.
func TestAltClickWithoutShellIntegration(t *testing.T) {
loadLib(t)
conn := newPipe()
term, err := New(Options{Conn: conn})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill().AutoFocus() }, 400, 200)
term.Feed([]byte("$ echo hello"))
tt.Frame()
x, y := cellCenter(term, 2, 0)
tt.ClickAtWith(ui.Alt, x, y)
if got := conn.take(term); got != "" {
t.Errorf("Alt+click sent %q", got)
}
}
+169
View File
@@ -0,0 +1,169 @@
package terminal
import (
"fmt"
"image"
"slices"
"testing"
"github.com/egoist/mygo/ui"
)
// rowGlyphs returns where each row's first glyph is, nil for a row without
// text: a row made again has its glyphs elsewhere.
func rowGlyphs(term *Terminal) []*ui.Glyph {
term.mu.Lock()
defer term.mu.Unlock()
var out []*ui.Glyph
for _, l := range term.v.lines {
var g *ui.Glyph
if len(l.runs) > 0 && len(l.runs[0].glyphs) > 0 {
g = &l.runs[0].glyphs[0]
}
out = append(out, g)
}
return out
}
// Rows a program scrolls are taken from the last frame, not made again:
// a log printing a line at a time makes one row a frame.
func TestScrolledRowsKept(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 400, 200)
for i := range 30 {
term.Feed(fmt.Appendf(nil, "\x1b[3%dmline %d\x1b[0m \x1b[1mbold\x1b[0m\r\n", i%7+1, i))
}
tt.Frame()
for step := range 3 {
before := rowGlyphs(term)
term.Feed(fmt.Appendf(nil, "\x1b[32mline %d\x1b[0m\r\n", 30+step))
tt.Frame()
after := rowGlyphs(term)
rows := len(after)
if rows < 4 || len(before) != rows {
t.Fatalf("%d rows, then %d", len(before), rows)
}
// Each row shows what the row below it did, but the last two: the
// new line and the cursor's empty row.
for y := range rows - 2 {
if after[y] == nil || after[y] != before[y+1] {
t.Errorf("step %d: row %d was made again rather than taken from row %d", step, y, y+1)
}
}
if g := after[rows-2]; g == nil || slices.Contains(before, g) {
t.Errorf("step %d: the new line's row was not made", step)
}
}
}
// Whatever rows a frame takes from the last, it draws what making every
// row again draws: rows rewritten in place with the same text but other
// colors, styles, backgrounds or combining marks, rows moved by
// scrolling, inserting and scroll regions, under a selection, a search
// and a palette that changes.
func TestTakenRowsDrawAsMade(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 500, 300)
check := func(step string) {
t.Helper()
tt.Frame()
got := clone(tt.Image())
// Without the last frame's rows, every row is made again.
term.mu.Lock()
term.v.lines = nil
term.mu.Unlock()
tt.Frame()
if want := tt.Image(); !slices.Equal(got.Pix, want.Pix) {
t.Errorf("%s: the frame differs from one whose rows were all made again", step)
}
}
// A steady cursor: a blinking one shows by the clock once a click
// focuses the terminal.
term.Feed([]byte("\x1b[2 q"))
for i := range 20 {
term.Feed(fmt.Appendf(nil, "\x1b[3%d;4%dm%02d\x1b[0m same \x1b[1mbold\x1b[0m \x1b[4munder\x1b[0m 漢字 👍🏽 café │─\r\n", i%7+1, (i+3)%8, i%3))
}
check("filled")
term.Feed([]byte("\x1b[32mone more\x1b[0m\r\n"))
check("scrolled a line")
// The same text in place, but otherwise.
for _, s := range []string{
"\x1b[3;1H\x1b[35m00\x1b[0m same",
"\x1b[3;1H\x1b[35;1m00\x1b[0m same",
"\x1b[3;1H\x1b[35;3m00\x1b[0m same",
"\x1b[3;1H\x1b[35;4:3m00\x1b[0m same",
"\x1b[3;1H\x1b[35;9m00\x1b[0m same",
"\x1b[3;1H\x1b[35;7m00\x1b[0m same",
"\x1b[3;1H\x1b[38;5;200m00\x1b[0m same",
"\x1b[3;1H\x1b[38;2;10;200;30m00\x1b[0m same",
"\x1b[4;1H\x1b[44m\x1b[K\x1b[0m",
"\x1b[4;1H\x1b[45m\x1b[K\x1b[0m",
"\x1b[4;1H\x1b[48;2;1;2;3m\x1b[K\x1b[0m",
"\x1b[5;1Hcafé\x1b[K",
"\x1b[5;1Hcafè\x1b[K",
"\x1b[5;1Hcafe\x1b[K",
"\x1b[5;1H漢字\x1b[K",
"\x1b[5;1Hab字\x1b[K",
"\x1b[5;1Hab\x1b[8mcd\x1b[0m\x1b[K",
"\x1b[5;1Habcd\x1b[K",
} {
term.Feed([]byte(s))
check(fmt.Sprintf("rewrote %q", s))
}
// A row rewritten to show what the row below it, which stays as it
// is, shows: it takes that row's last frame, and the row below keeps
// its own.
term.Feed([]byte("\x1b[3;1Hfirst\x1b[K\x1b[4;1Hsecond\x1b[K\x1b[10;1H"))
check("wrote two rows")
term.Feed([]byte("\x1b[10;1Hx\x1b[10;1H"))
tt.Frame()
term.Feed([]byte("\x1b[3;1Hthird\x1b[K\x1b[10;1H"))
tt.Frame() // the frame before, whose rows the next one's slots hold
term.Feed([]byte("\x1b[3;1Hsecond\x1b[K\x1b[10;1H"))
check("copied the row below")
// Rows that show the same, many times over, then one of them not.
term.Feed([]byte("\x1b[30;1H\r\nsame\r\nsame\r\nsame\r\n"))
check("repeated a row")
term.Feed([]byte("\x1b[2A\x1b[33msame\x1b[0m\x1b[2B\r\nsame\r\n"))
check("recolored a repeated row")
// Rows moved by inserting, deleting and scrolling a region.
term.Feed([]byte("\x1b[3;1H\x1b[2L"))
check("inserted rows")
term.Feed([]byte("\x1b[2;1H\x1b[M"))
check("deleted a row")
term.Feed([]byte("\x1b[4;9r\x1b[9;1H\nregion\n\x1b[r"))
check("scrolled a region")
// A selection, which moves with its text.
x0, y0 := cellCenter(term, 1, 2)
x1, y1 := cellCenter(term, 12, 5)
tt.Press(x0, y0)
tt.Move(x1, y1)
tt.Release(x1, y1)
check("selected")
term.Feed([]byte("\x1b[30;1H\r\nmore\r\n"))
check("scrolled the selection")
tt.ClickAt(x0, y0)
check("unselected")
term.Search("same")
check("searched")
term.Feed([]byte("\x1b]4;2;rgb:ff/00/00\x07\x1b]4;44;rgb:00/ff/00\x07"))
check("changed the palette")
term.Feed([]byte("\x1b[2J\x1b[H\x1b[31mafter\x1b[0m clearing\r\n"))
check("cleared")
}
func clone(m *image.RGBA) *image.RGBA {
c := *m
c.Pix = slices.Clone(m.Pix)
return &c
}
+231
View File
@@ -0,0 +1,231 @@
package terminal
import (
"time"
"github.com/egoist/mygo/plugins/terminal/internal/vt"
)
// SearchStatus is how a search of the terminal goes (Terminal.Search,
// Options.OnSearch).
type SearchStatus struct {
// Text is what the search looks for: "" when none goes.
Text string
// Total counts the matches found so far, on the screen that shows: a
// full-screen program's, or the main screen's with its scrollback.
// Selected is the selected match's place among them, 1 the newest, as
// a find bar's "1 of 3"; 0 when none is.
Total, Selected int
// Searching tells that the search has more of the scrollback to go
// through: Total may grow.
Searching bool
}
// search is the terminal's search, while one goes; t.mu guards it.
type search struct {
s *vt.Search
// pick selects the newest match once one is found, as a search
// starts.
pick bool
status SearchStatus
}
// searchBudget bounds what a frame spends going through the scrollback; a
// search of more goes on in the frames after it.
const searchBudget = 4 * time.Millisecond
// Search searches the screen and the scrollback for text, as Ghostty's
// find does, and highlights the matches (Theme.Search) as they are found,
// following the output that comes; the newest match is selected and
// shown, scrolling to it. Matching is exact but for the case of ASCII
// letters, which it ignores. Searching for the text searched already keeps
// the selected match; "" ends the search, as EndSearch. A view drives the
// search, which goes on in the frames that show the terminal.
func (t *Terminal) Search(text string) {
if text == "" {
t.EndSearch()
return
}
t.mu.Lock()
if t.term == nil {
t.mu.Unlock()
return
}
f := &t.find
if f.s == nil {
s, err := vt.NewSearch(t.term)
if err != nil {
t.mu.Unlock()
return
}
f.s = s
}
if f.status.Text != text {
f.s.SetText(text)
f.status, f.pick = SearchStatus{Text: text, Searching: true}, true
}
t.mu.Unlock()
t.redraw()
}
// SearchNext selects the next match of the search toward older output, up
// the screen and into the scrollback, wrapping around past the oldest, and
// unless it shows scrolls it to the middle of the view, clear of a find bar
// over an edge; SearchPrevious goes the other way.
func (t *Terminal) SearchNext() { t.selectMatch(false) }
func (t *Terminal) SearchPrevious() { t.selectMatch(true) }
func (t *Terminal) selectMatch(back bool) {
t.mu.Lock()
if f := &t.find; f.s != nil && t.term != nil {
// A match picked by hand is the one to keep.
f.pick = false
f.s.Select(back)
f.show(t.term)
f.update()
}
t.mu.Unlock()
t.redraw()
}
// EndSearch ends the search, and its highlights.
func (t *Terminal) EndSearch() {
t.mu.Lock()
ended := t.find.s != nil
t.endSearch()
t.mu.Unlock()
if ended {
t.redraw()
}
}
// endSearch frees the search; t.mu is held.
func (t *Terminal) endSearch() {
if t.find.s != nil {
t.find.s.Free()
}
t.find = search{}
}
// SearchStatus returns how the search goes.
func (t *Terminal) SearchStatus() SearchStatus {
t.mu.Lock()
defer t.mu.Unlock()
return t.find.status
}
// show scrolls the selected match to the middle of the viewport unless
// all of it shows, as browsers do, rather than to an edge, where an app's
// find bar may cover it; t.mu is held.
func (f *search) show(term *vt.Terminal) {
m, ok := f.s.SelectedMatch()
if !ok {
return
}
a, b := m.Ends()
_, rows := term.Size()
_, y0, ok0 := term.ViewportPoint(a)
_, y1, ok1 := term.ViewportPoint(b)
if ok0 && ok1 && y0 < rows && y1 < rows {
return
}
if y, ok := term.ScreenRow(a); ok {
term.ScrollToRow(y - rows/2)
}
}
// drive goes on with the search for a frame, and reports whether it has
// more to go through; t.mu is held.
func (f *search) drive(term *vt.Terminal) bool {
if f.s == nil {
return false
}
f.s.Feed()
deadline := time.Now().Add(searchBudget)
for st := f.s.Tick(); st != vt.SearchComplete; st = f.s.Tick() {
if st == vt.SearchFeedRequired {
f.s.Feed()
}
if time.Now().After(deadline) {
break
}
}
if f.pick && f.s.Total() > 0 {
f.pick = false
f.s.Select(false)
f.show(term)
}
f.update()
return f.status.Searching
}
// update reads the status of the search; t.mu is held.
func (f *search) update() {
st := SearchStatus{Text: f.status.Text, Total: f.s.Total(), Searching: f.s.Status() != vt.SearchComplete}
if i, ok := f.s.Selected(); ok {
st.Selected = i + 1
}
f.status = st
}
// matchSpan is a match's cells in a row of the viewport, x0 to x1
// inclusive.
type matchSpan struct {
y, x0, x1 int
selected bool
}
// viewportMatches returns the cells of the matches the viewport shows, in
// spans' memory, rows rows tall and cols wide; t.mu is held.
func (t *Terminal) viewportMatches(spans []matchSpan, buf []vt.Selection, cols, rows int) ([]matchSpan, []vt.Selection) {
spans = spans[:0]
f := &t.find
if f.s == nil || f.status.Total == 0 {
return spans, buf
}
// The matches as of the terminal now.
f.s.Feed()
buf = f.s.ViewportMatches(buf)
// The cells of a match in the viewport: one that wraps in from above
// it starts at its top left, and one that wraps on below it ends at
// its bottom right.
cells := func(m *vt.Selection) (c [4]int, shows bool) {
a, b := m.Ends()
x0, y0, ok0 := t.term.ViewportPoint(a)
x1, y1, ok1 := t.term.ViewportPoint(b)
switch {
case !ok0 && !ok1:
return c, false
case !ok0:
x0, y0 = 0, 0
case !ok1:
x1, y1 = cols-1, rows-1
}
return [4]int{x0, y0, x1, y1}, y0 < rows
}
var sel [4]int
selOK := false
if m, ok := f.s.SelectedMatch(); ok {
sel, selOK = cells(&m)
}
for i := range buf {
c, shows := cells(&buf[i])
if !shows {
continue
}
x0, y0, x1, y1 := c[0], c[1], c[2], c[3]
selected := selOK && sel == c
// A match that wraps takes the rows it goes through.
for y := y0; y <= min(y1, rows-1); y++ {
s := matchSpan{y, 0, cols - 1, selected}
if y == y0 {
s.x0 = x0
}
if y == y1 {
s.x1 = x1
}
spans = append(spans, s)
}
}
return spans, buf
}
+160
View File
@@ -0,0 +1,160 @@
package terminal
import (
"fmt"
"strings"
"testing"
"time"
"github.com/egoist/mygo/ui"
)
func TestShiftClickExtendsSelection(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe(), CopyOnSelect: CopyOnSelectClipboard})
if err != nil {
t.Fatal(err)
}
defer term.Close()
term.Feed([]byte("hello world\r\nsecond line\r\nthird line"))
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill().AutoFocus() }, 400, 200)
x, y := cellCenter(term, 0, 0)
tt.Press(x-2, y)
x, y = cellCenter(term, 4, 0)
tt.Move(x+2, y)
tt.Release(x+2, y)
if got := tt.Clipboard(); got != "hello" {
t.Fatalf("initial selection = %q", got)
}
for _, step := range []struct {
col, row int
want string
}{
{5, 1, "hello world\nsecond"},
{9, 2, "hello world\nsecond line\nthird line"},
{2, 0, "hel"},
} {
x, y = cellCenter(term, step.col, step.row)
tt.ClickAtWith(ui.Shift, x, y)
if got := tt.Clipboard(); got != step.want {
t.Errorf("Shift-click (%d,%d) copied %q, want %q", step.col, step.row, got, step.want)
}
tt.SetClipboard("sentinel")
tt.Command("copy")
if got := tt.Clipboard(); got != step.want {
t.Errorf("Copy after Shift-click = %q, want %q", got, step.want)
}
}
}
func TestShiftClickKeepsSelectionAnchor(t *testing.T) {
loadLib(t)
for _, mode := range []string{"reverse", "word", "line", "copy off", "output", "mouse tracking"} {
t.Run(mode, func(t *testing.T) {
term, err := New(Options{Conn: newPipe()})
if err != nil {
t.Fatal(err)
}
defer term.Close()
term.Feed([]byte("hello world\r\nsecond line\r\nthird line"))
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill().AutoFocus() }, 400, 200)
x, y := cellCenter(term, 0, 0)
want := "hello world\nsecond"
switch mode {
case "reverse":
x, y = cellCenter(term, 4, 1)
tt.Press(x+2, y)
x, y = cellCenter(term, 0, 1)
tt.Move(x-2, y)
tt.Release(x-2, y)
want = "hello world\nsecon"
case "word", "line":
clicks := 2
if mode == "line" {
clicks = 3
}
for range clicks {
tt.ClickAt(x, y)
}
default:
tt.Press(x-2, y)
x, y = cellCenter(term, 4, 0)
tt.Move(x+2, y)
tt.Release(x+2, y)
}
if mode == "output" {
term.Feed([]byte("\r\nmore output"))
tt.Frame()
}
if mode == "mouse tracking" {
term.Feed([]byte("\x1b[?1000h\x1b[?1006h"))
}
x, y = cellCenter(term, 5, 1)
if mode == "reverse" {
x, y = cellCenter(term, 0, 0)
}
tt.SetClipboard("untouched")
tt.ClickAtWith(ui.Shift, x, y)
if got := tt.Clipboard(); got != "untouched" {
t.Errorf("copy-on-select disabled: clipboard = %q", got)
}
tt.Command("copy")
if got := tt.Clipboard(); got != want {
t.Errorf("extended selection = %q, want %q", got, want)
}
term.Feed([]byte("\x1b[?1000l\x1b[?1006l"))
// An ordinary click clears the selection. Shift-click must not
// revive the previous selection's anchor after it is gone.
x, y = cellCenter(term, 3, 2)
tt.ClickAt(x, y)
x, y = cellCenter(term, 8, 2)
tt.ClickAtWith(ui.Shift, x, y)
tt.SetClipboard("untouched")
tt.Command("copy")
if got := tt.Clipboard(); got != "untouched" {
t.Errorf("Shift-click revived a cleared selection: %q", got)
}
})
}
}
func TestShiftClickDragAutoscroll(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe(), CopyOnSelect: CopyOnSelectClipboard})
if err != nil {
t.Fatal(err)
}
defer term.Close()
for row := range 40 {
term.Feed(fmt.Appendf(nil, "row%02d\r\n", row))
}
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill().AutoFocus() }, 400, 200)
term.mu.Lock()
term.term.ScrollToTop()
term.mu.Unlock()
tt.Frame()
x, y := cellCenter(term, 0, 0)
tt.Press(x-2, y)
x, y = cellCenter(term, 4, 0)
tt.Move(x+2, y)
tt.Release(x+2, y)
if got := tt.Clipboard(); got != "row00" {
t.Fatalf("initial selection = %q", got)
}
v := term.v
x, y = cellCenter(term, 4, 1)
// A held Shift-click, followed by dragging beyond the bottom edge.
// Use the view's real input handler so the button remains pressed.
v.input(ui.InputEvent{Kind: ui.InputPointerDown, Mods: ui.Shift, X: x, Y: y})
v.input(ui.InputEvent{Kind: ui.InputPointerMove, X: x, Y: 240})
tt.Frame()
tt.Advance(120 * time.Millisecond)
v.input(ui.InputEvent{Kind: ui.InputPointerUp, X: x, Y: 240})
got := tt.Clipboard()
if !strings.HasPrefix(got, "row00\nrow01\n") || !strings.Contains(got, fmt.Sprintf("row%02d", v.rows)) {
t.Errorf("drag did not keep the anchor and scroll to another row: %q", got)
}
if v.selecting || v.ticking {
t.Error("release left selection dragging or autoscroll active")
}
}
+166
View File
@@ -0,0 +1,166 @@
package terminal
import (
"os"
"path/filepath"
"strings"
)
// Ghostty's C API preserves prompts by default. zsh instead redraws the
// whole prompt on SIGWINCH; the final C leaves the initial screen unmarked.
const promptRedraw = "\x1b]133;A;redraw=1\a\x1b]133;C\a"
func zshEnvironment(env []string) ([]string, string, error) {
dir, err := os.MkdirTemp("", "mygo-zsh-")
if err != nil {
return nil, "", err
}
if err := os.WriteFile(filepath.Join(dir, ".zshenv"), []byte(zshIntegration), 0o600); err != nil {
os.RemoveAll(dir)
return nil, "", err
}
clean := make([]string, 0, len(env)+1)
var original string
var hadOriginal bool
for _, entry := range env {
if value, ok := strings.CutPrefix(entry, "ZDOTDIR="); ok {
original, hadOriginal = value, true
} else if !strings.HasPrefix(entry, "MYGO_TERMINAL_ZDOTDIR=") {
clean = append(clean, entry)
}
}
if hadOriginal {
clean = append(clean, "MYGO_TERMINAL_ZDOTDIR="+original)
}
return append(clean, "ZDOTDIR="+dir), dir, nil
}
// Restore ZDOTDIR before sourcing any user configuration. Install hooks at
// the first precmd, after startup files and prompt themes have loaded. P10k
// emits its own markers when asked, including asynchronous prompt updates.
const zshIntegration = `if (( ${+MYGO_TERMINAL_ZDOTDIR} )); then
export ZDOTDIR=$MYGO_TERMINAL_ZDOTDIR
unset MYGO_TERMINAL_ZDOTDIR
else
unset ZDOTDIR
fi
[[ ! -r ${ZDOTDIR-$HOME}/.zshenv ]] || source -- "${ZDOTDIR-$HOME}/.zshenv"
[[ -o interactive ]] || return
typeset -gi __p9k_force_term_shell_integration=1
_mygo_mark_prompt() {
local code=$?
emulate -L zsh
if ! zle; then
printf '\e]133;D;%d\a' $code
fi
[[ -o promptpercent ]] || return
local start=$'%{\e]133;A;cl=line;redraw=1\a%}' input=$'%{\e]133;B\a%}'
local continuation=$'%{\e]133;P;k=s\a%}'
if [[ $PS1 != *$'\e]133;'* ]]; then
PS1=$start${PS1//$'\n'/$'\n'$continuation}$input
fi
[[ $PS2 == *$'\e]133;'* ]] || PS2=$continuation$PS2$input
}
_mygo_command_start() {
printf '\e]133;C\a'
}
_mygo_install_marks() {
emulate -L zsh
autoload -Uz add-zsh-hook
add-zsh-hook -d precmd _mygo_install_marks
add-zsh-hook precmd _mygo_mark_prompt
add-zsh-hook preexec _mygo_command_start
_mygo_mark_prompt
}
typeset -ga precmd_functions
precmd_functions+=(_mygo_install_marks)
`
// Track only OSC 133, across read boundaries. Other control strings are
// opaque and OSC payloads are bounded; a TUI's text must not mark a prompt.
type promptTracker struct {
state byte
body []byte
length int
atPrompt bool
}
func (p *promptTracker) feed(data []byte) {
for _, b := range data {
if b == 0x18 || b == 0x1a { // CAN / SUB
p.state, p.length = 0, 0
p.body = p.body[:0]
continue
}
switch p.state {
case 0:
if b == 0x1b {
p.state = 1
}
case 1:
p.escape(b)
case 2:
p.length++
switch b {
case 7:
p.finish()
p.state = 0
case 0x1b:
p.state = 3
default:
if p.length <= 64 {
p.body = append(p.body, b)
}
}
case 3:
if b == '\\' {
p.finish()
p.state = 0
} else {
p.escape(b) // ESC aborted the previous OSC.
}
case 4:
if b == 0x1b {
p.state = 5
}
case 5:
if b == '\\' {
p.state = 0
} else if b != 0x1b {
p.state = 4
}
}
}
}
func (p *promptTracker) escape(b byte) {
p.state = 0
switch b {
case ']':
p.state, p.length, p.body = 2, 0, p.body[:0]
case 'P', '_', '^', 'X': // DCS, APC, PM, SOS
p.state = 4
case 'c': // RIS
p.atPrompt = false
case 0x1b:
p.state = 1
}
}
func (p *promptTracker) finish() {
if p.length > 64 {
return
}
mark, ok := strings.CutPrefix(string(p.body), "133;")
if !ok || mark == "" || len(mark) > 1 && mark[1] != ';' {
return
}
switch mark[0] {
case 'A', 'B', 'I', 'N', 'P':
p.atPrompt = true
case 'C', 'D':
p.atPrompt = false
}
}
@@ -0,0 +1,252 @@
package terminal
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/egoist/mygo/internal/wait"
)
func TestShellIntegrationMarkedPromptResize(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe(), ShellIntegration: true})
if err != nil {
t.Fatal(err)
}
defer term.Close()
term.Resize(100, 20)
term.Feed([]byte("history\r\n\x1b]133;A\a\r\n\x1b[Aresize-prompt\x1b[90Gclock\r\n> pending-command\x1b]133;B\a"))
// The rows stay, shrink by one, grow or shrink by more.
for _, size := range [][2]int{{80, 20}, {100, 19}, {40, 18}, {120, 24}, {80, 23}, {60, 23}} {
cols, rows := size[0], size[1]
term.Resize(cols, rows)
want := "history\nresize-prompt" + strings.Repeat(" ", cols-18) + "clock\n> pending-command"
if got := term.Text(); got != "history" {
t.Fatalf("at %dx%d, the prompt was left: %q", cols, rows, got)
}
term.Feed([]byte(fmt.Sprintf("\r\x1b[A\x1b]133;A\aresize-prompt\x1b[%dGclock\r\n> pending-command\x1b]133;B\a", cols-4)))
if got := term.Text(); got != want {
t.Fatalf("at %dx%d: %q", cols, rows, got)
}
}
term.Feed([]byte("\x1b]133;C\a\r\n"))
output := strings.Repeat("long command output ", 20)
term.Feed([]byte(output))
term.Resize(40, 10)
term.Resize(120, 30)
if got := term.Text(); !strings.Contains(got, strings.TrimSpace(output)) {
t.Fatalf("resizing command output lost text: %q", got)
}
}
func TestShellIntegrationPreservesAlternateScreen(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe(), ShellIntegration: true})
if err != nil {
t.Fatal(err)
}
defer term.Close()
term.Resize(100, 20)
term.Feed([]byte("\x1b]133;A\aprompt\x1b]133;B\a\x1b[?1049halt-program"))
term.Resize(40, 20)
if got := term.Text(); !strings.Contains(got, "alt-program") {
t.Fatalf("prompt tracking cleared a full-screen program: %q", got)
}
}
func TestShellIntegrationOtherShells(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("runs sleep")
}
loadLib(t)
term, err := New(Options{Command: []string{"sleep", "60"}, ShellIntegration: true})
if err != nil {
t.Fatal(err)
}
defer term.Close()
if term.shellDir != "" {
t.Fatal("a program other than zsh was configured")
}
// Its own marks don't make it redraw its prompt on a resize: the
// prompt stays, as without ShellIntegration.
term.Feed([]byte("\x1b]133;A\aprompt\x1b]133;B\a"))
term.Resize(40, 24)
if got := term.Text(); got != "prompt" {
t.Fatalf("the prompt of a program other than zsh was cleared: %q", got)
}
}
func TestShellIntegrationUserStartup(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("requires zsh")
}
zsh, err := exec.LookPath("zsh")
if err != nil {
t.Skip("zsh is not installed")
}
for _, custom := range []bool{false, true} {
t.Run(fmt.Sprint(custom), func(t *testing.T) {
home := t.TempDir()
config := home
env := []string{"HOME=" + home, "PATH=" + os.Getenv("PATH"), "TERM=xterm-256color"}
if custom {
config = t.TempDir()
env = append(env, "ZDOTDIR="+config)
}
for _, name := range []string{".zshenv", ".zprofile", ".zshrc", ".zlogin"} {
if err := os.WriteFile(filepath.Join(config, name), []byte("print -r -- startup-"+name+"\n"), 0o600); err != nil {
t.Fatal(err)
}
}
env, dir, err := zshEnvironment(env)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
cmd := exec.CommandContext(wait.Context(t), zsh, "-lic", `print -r -- restored:${+ZDOTDIR}:${ZDOTDIR-unset}:${+MYGO_TERMINAL_ZDOTDIR}`)
cmd.Env = env
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("zsh startup: %v: %s", err, output)
}
for _, name := range []string{".zshenv", ".zprofile", ".zshrc", ".zlogin"} {
if strings.Count(string(output), "startup-"+name) != 1 {
t.Fatalf("startup file %s did not run exactly once: %q", name, output)
}
}
want := "restored:0:unset:0"
if custom {
want = "restored:1:" + config + ":0"
}
if !strings.Contains(string(output), want) {
t.Fatalf("ZDOTDIR was not restored: %q", output)
}
})
}
}
func TestShellIntegrationPromptTracker(t *testing.T) {
var p promptTracker
for _, part := range []string{"\x1b]13", "3;A;redraw=1\x1b", "\\prompt\x1b]133;B\a"} {
p.feed([]byte(part))
}
if !p.atPrompt {
t.Fatal("fragmented prompt was missed")
}
for _, data := range []string{"\x1b]2;title\a", "\x1b]133;Command\a", "\x1bP\x1b]133;C\a\x1b\\"} {
p.feed([]byte(data))
if !p.atPrompt {
t.Fatalf("unrelated or opaque control data changed prompt state: %q", data)
}
}
p.feed([]byte("\x1b]133;C\a"))
if p.atPrompt {
t.Fatal("command output was marked as a prompt")
}
p.feed([]byte("\x1b]133;A;" + strings.Repeat("x", 1024) + "\a"))
if p.atPrompt || len(p.body) > 64 {
t.Fatal("oversized OSC was retained or accepted")
}
p.feed([]byte("\x1b]133;A\x18ignored\a"))
if p.atPrompt {
t.Fatal("canceled OSC was accepted")
}
p.feed([]byte("\x1b]133;A\a\x1bc"))
if p.atPrompt {
t.Fatal("terminal reset retained prompt state")
}
p.feed([]byte("\x1b]133;N\a"))
if !p.atPrompt {
t.Fatal("a new command's prompt was missed")
}
}
func TestShellIntegrationZshResize(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("requires a Unix zsh PTY")
}
zsh, err := exec.LookPath("zsh")
if err != nil {
t.Skip("zsh is not installed")
}
loadLib(t)
config := filepath.Join(t.TempDir(), "user config")
if err := os.MkdirAll(config, 0o700); err != nil {
t.Fatal(err)
}
files := map[string]string{
".zshenv": "export STARTUP_ENV=loaded\nprint -r -- startup-env:$ZDOTDIR:$NO_COLOR\n",
".zshrc": "setopt promptsubst\nPROMPT=$'resize-prompt:${COLUMNS}${(l:COLUMNS-24:)}clock\\n> '\nRPROMPT=right-prompt\n",
}
for name, content := range files {
if err := os.WriteFile(filepath.Join(config, name), []byte(content), 0o600); err != nil {
t.Fatal(err)
}
}
t.Setenv("SHELL", zsh)
term, err := New(Options{ShellIntegration: true, Env: []string{"ZDOTDIR=" + config, "NO_COLOR=user-preference"}})
if err != nil {
t.Fatal(err)
}
defer term.Close()
term.Resize(100, 24)
wait.Until(t, "initial zsh prompt", func() bool { return strings.Contains(term.Text(), "right-prompt") })
if got := term.Text(); strings.Count(got, "startup-env:") != 1 || !strings.Contains(got, config+":user-preference") {
t.Fatalf("user startup/environment not preserved: %q", got)
}
term.Send([]byte("echo pending-command"))
wait.Until(t, "pending input", func() bool { return strings.Contains(term.Text(), "echo pending-command") })
for _, cols := range []int{40, 120, 60, 100, 40} {
term.Resize(cols, 24)
wait.Until(t, fmt.Sprintf("zsh redraw at %d columns", cols), func() bool {
text := term.Text()
return strings.Contains(text, fmt.Sprintf("resize-prompt:%d", cols)) && strings.Contains(text, "echo pending-command")
})
if got := term.Text(); strings.Count(got, "resize-prompt:") != 1 {
t.Fatalf("prompt duplicated at %d columns: %q", cols, got)
}
}
for name, want := range files {
got, err := os.ReadFile(filepath.Join(config, name))
if err != nil || string(got) != want {
t.Fatal("shell integration modified user startup files")
}
}
dir := term.shellDir
term.Close()
wait.For(t, "zsh exit", term.Done())
if _, err := os.Stat(dir); !os.IsNotExist(err) {
t.Fatalf("temporary shell configuration was not removed: %v", err)
}
}
func TestShellIntegrationCloseBeforeStart(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("requires zsh")
}
zsh, err := exec.LookPath("zsh")
if err != nil {
t.Skip("zsh is not installed")
}
loadLib(t)
t.Setenv("SHELL", zsh)
t.Setenv("HOME", t.TempDir())
term, err := New(Options{ShellIntegration: true})
if err != nil {
t.Fatal(err)
}
dir := term.shellDir
term.Close()
wait.For(t, "unstarted terminal close", term.Done())
if dir == "" {
t.Fatal("zsh integration was not configured")
}
if _, err := os.Stat(dir); !os.IsNotExist(err) {
t.Fatalf("temporary configuration leaked before start: %v", err)
}
}
+42
View File
@@ -0,0 +1,42 @@
package terminal
import (
"testing"
"time"
"github.com/egoist/mygo/ui"
)
// A program that starts a synchronized update and writes nothing more, its
// cursor hidden, has the update shown after a second all the same: the view
// asks for the frame that lets it go, as no blink, output or input will.
func TestSynchronizedUpdateShowsAfterASecondWithoutOutput(t *testing.T) {
loadLib(t)
term, err := New(Options{Conn: newPipe(), NoBlink: true})
if err != nil {
t.Fatal(err)
}
defer term.Close()
tt := ui.NewTester(func(c *ui.Context) { View(c, term).Fill() }, 400, 200)
term.Feed([]byte("\x1b[?25lbefore\x1b[?2026hafter"))
tt.Frame()
held := func() bool {
term.mu.Lock()
defer term.mu.Unlock()
return term.held
}
if !held() {
t.Fatal("the synchronized update did not hold the screen")
}
// The second has gone by, as far as paint's clock tells; the Tester's
// runs only the frames asked for.
term.mu.Lock()
term.rmu.Lock()
term.heldSince = time.Now().Add(-2 * time.Second)
term.rmu.Unlock()
term.mu.Unlock()
tt.Advance(2 * time.Second)
if held() {
t.Fatal("a synchronized update with no more output stayed held: no frame came to let it go")
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,12 @@
78[?25h[?25l[?2004h[?2031h[?1004h[<u[>5u[>4;2m]11;?[>0q[?u]7501;?[?2026$p_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\[?1016$p[>4m[<u[?1004l[?2031l[?2004l[?2004h[?2031h[?1004h[<u[>5u[>4;2m]7501;state=idle:app=claude-code]0;Claude Code]9;4;0;[?2026h ▐▛███▛█ClaudeCodev2.1.304
▝▜██████▀Opus5.5(1Mcontext)withmediumeffort·ClaudeFoo
 ▝▝▝▝~/dev
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ Try"howdoIloganerror?"
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
⏵⏵automodeon (shift+tabtocycle)·←foragents◐medium·/effort
[?25h[?2026l[?2026h[?25l 1 agent
[?25h[?2026l[>0q[?2026$p[?2026h[?25l 
[?25h[?2026l
+107
View File
@@ -0,0 +1,107 @@
package terminal
import (
"github.com/egoist/mygo/plugins/terminal/internal/vt"
"github.com/egoist/mygo/ui"
)
// Theme is the colors of a terminal, which programs may change (OSC 4,
// 10, 11, 12) until the terminal resets. GhosttyTheme returns Ghostty's
// themes.
type Theme struct {
Foreground, Background ui.Color
// Cursor colors the cursor: the foreground when zero. CursorText
// colors the text under a block cursor: the background when zero.
Cursor, CursorText ui.Color
// Selection highlights the selected text: the foreground, a third
// opaque, when zero. SelectionText colors the selected text: its own
// colors when zero.
Selection, SelectionText ui.Color
// Search highlights the matches of a search (Terminal.Search) and
// SearchText colors their text, as Ghostty's search-background and
// search-foreground; SearchSelected and SearchSelectedText the selected
// match, as search-selected-background and search-selected-foreground.
// Ghostty's colors when zero: a light amber and a light orange, under
// black text.
Search, SearchText, SearchSelected, SearchSelectedText ui.Color
// Palette holds the 16 colors of programs: black, red, green, yellow,
// blue, magenta, cyan and white, then their bright kinds.
Palette [16]ui.Color
}
// DarkTheme returns the colors of terminals in dark windows: the window's
// background and text, with Visual Studio Code's palette.
func DarkTheme() *Theme {
ut := ui.DarkTheme()
return &Theme{
Foreground: ut.Text, Background: ut.Background,
Palette: [16]ui.Color{
ui.Hex("#000000"), ui.Hex("#cd3131"), ui.Hex("#0dbc79"), ui.Hex("#e5e510"),
ui.Hex("#2472c8"), ui.Hex("#bc3fbc"), ui.Hex("#11a8cd"), ui.Hex("#e5e5e5"),
ui.Hex("#666666"), ui.Hex("#f14c4c"), ui.Hex("#23d18b"), ui.Hex("#f5f543"),
ui.Hex("#3b8eea"), ui.Hex("#d670d6"), ui.Hex("#29b8db"), ui.Hex("#ffffff"),
},
}
}
// LightTheme returns the colors of terminals in light windows: the
// window's background and text, with Visual Studio Code's palette.
func LightTheme() *Theme {
ut := ui.LightTheme()
return &Theme{
Foreground: ut.Text, Background: ut.Background,
Palette: [16]ui.Color{
ui.Hex("#000000"), ui.Hex("#cd3131"), ui.Hex("#00bc00"), ui.Hex("#949800"),
ui.Hex("#0451a5"), ui.Hex("#bc05bc"), ui.Hex("#0598bc"), ui.Hex("#555555"),
ui.Hex("#666666"), ui.Hex("#cd3131"), ui.Hex("#14ce14"), ui.Hex("#b5ba00"),
ui.Hex("#0451a5"), ui.Hex("#bc05bc"), ui.Hex("#0598bc"), ui.Hex("#a5a5a5"),
},
}
}
var themes = [2]*Theme{LightTheme(), DarkTheme()}
func defaultTheme(dark bool) *Theme {
if dark {
return themes[1]
}
return themes[0]
}
// dark reports whether the theme's background is dark.
func (th *Theme) dark() bool {
b := th.Background
return 299*int(b.R)+587*int(b.G)+114*int(b.B) < 128*1000
}
// palette returns the 256 colors of the theme: its 16, the 6×6×6 cube and
// the 24 grays of xterm.
func (th *Theme) palette() *[256]vt.RGB {
var p [256]vt.RGB
for i, c := range th.Palette {
p[i] = rgb(c)
}
levels := [6]uint8{0, 95, 135, 175, 215, 255}
for i := range 216 {
p[16+i] = vt.RGB{R: levels[i/36], G: levels[i/6%6], B: levels[i%6]}
}
for i := range 24 {
v := uint8(8 + 10*i)
p[232+i] = vt.RGB{R: v, G: v, B: v}
}
return &p
}
// apply makes the theme the terminal's defaults.
func (th *Theme) apply(t *vt.Terminal) {
var cursor *vt.RGB
if th.Cursor.A > 0 {
c := rgb(th.Cursor)
cursor = &c
}
t.SetColors(rgb(th.Foreground), rgb(th.Background), cursor, th.palette())
}
func rgb(c ui.Color) vt.RGB { return vt.RGB{R: c.R, G: c.G, B: c.B} }
func color(c vt.RGB) ui.Color { return ui.RGB(c.R, c.G, c.B) }
File diff suppressed because it is too large. Load diff