Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158// Package sample provides canned VT output for exercising the renderer.package sample
import ( "fmt" "strings")
// Output returns VT output that exercises the renderer: palette and// true colours, text attributes, wide characters and box drawing.func Output() []byte { var b strings.Builder w := func(format string, args ...any) { fmt.Fprintf(&b, format, args...) }
w("\x1b[1m100gex\x1b[0m: libghostty-vt rendered with Gio\r\n\r\n")
w("16 colours: ") for i := 0; i < 8; i++ { w("\x1b[%dm %d \x1b[0m", 40+i, i) } w("\r\n ") for i := 0; i < 8; i++ { w("\x1b[%dm %d \x1b[0m", 100+i, i+8) } w("\r\n\r\n")
w("Foreground: ") for i := 0; i < 8; i++ { w("\x1b[%dmcolour%d\x1b[0m ", 30+i, i) } w("\r\n\r\n")
w("256 colours: ") for i := 16; i < 52; i++ { w("\x1b[48;5;%dm ", i) } w("\x1b[0m\r\n")
w("True colour: ") for i := 0; i < 72; i++ { r := 255 - i*255/71 g := i * 255 / 71 w("\x1b[48;2;%d;%d;128m ", r, g) } w("\x1b[0m\r\n\r\n")
w("Attributes: \x1b[1mbold\x1b[0m \x1b[3mitalic\x1b[0m \x1b[1;3mbold italic\x1b[0m ") w("\x1b[2mfaint\x1b[0m \x1b[7minverse\x1b[0m \x1b[4munderline (not drawn yet)\x1b[0m\r\n\r\n")
w("Wide: 日本語のテキスト | 한국어 | 中文 | emoji 🙂👻\r\n\r\n")
w("Box drawing: ┌────────┬────────┐\r\n") w(" │ left │ right │\r\n") w(" └────────┴────────┘\r\n\r\n")
w("\x1b[32m$\x1b[0m ") return []byte(b.String())}
// Styled returns VT output that fills a screen of cols by rows with the// most a renderer can be asked to draw: every cell has a character, a// true colour of its own in front and behind, and a mix of bold and// italic. Each row is placed with a cursor move, so nothing wraps or// scrolls.func Styled(cols, rows int) []byte { var b strings.Builder b.WriteString("\x1b[H\x1b[2J") const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}[]()<>=+-*/;:" for y := 0; y < rows; y++ { fmt.Fprintf(&b, "\x1b[%d;1H", y+1) for x := 0; x < cols; x++ { i := y*cols + x attr := "22;23" switch i % 4 { case 1: attr = "1;23" case 2: attr = "22;3" } fmt.Fprintf(&b, "\x1b[%s;38;2;%d;%d;%d;48;2;%d;%d;%dm%c", attr, (x*7)%256, (y*11)%256, (i*13)%256, 255-(x*5)%256, 255-(y*3)%256, (i*17)%256, chars[i%len(chars)]) } } b.WriteString("\x1b[0m") return []byte(b.String())}
// Plain returns VT output that fills a screen of cols by rows with text in// the default colours, as a busy log or source file does: words of// varying length, every row full.func Plain(cols, rows int) []byte { var b strings.Builder b.WriteString("\x1b[H\x1b[2J") words := []string{"func", "return", "err", "nil", "if", "for", "range", "layout", "context", "image.Point", "gtx", ":=", "{", "}", "(", ")", "100gex", "pane"} for y := 0; y < rows; y++ { fmt.Fprintf(&b, "\x1b[%d;1H", y+1) n := 0 for i := y; n < cols; i++ { w := words[i%len(words)] + " " if n+len(w) > cols { w = strings.Repeat(".", cols-n) } b.WriteString(w) n += len(w) } } return []byte(b.String())}
// Code returns VT output that fills a screen of cols by rows as an editor// showing highlighted source does: the colour changes every word or so, a// cursor line has a background of its own, and a status line along the// bottom has coloured segments.func Code(cols, rows int) []byte { var b strings.Builder b.WriteString("\x1b[H\x1b[2J") tokens := []struct{ sgr, text string }{ {"38;5;129", "func"}, {"39", "(u *UI)"}, {"38;5;33", "layout"}, {"39", "(gtx layout.Context)"}, {"38;5;129", "return"}, {"38;5;28", `"a string"`}, {"39", "err"}, {"38;5;166", "42"}, {"3;38;5;244", "// a comment here"}, {"39", ":="}, {"38;5;129", "if"}, {"39", "{ }"}, } for y := 0; y < rows; y++ { fmt.Fprintf(&b, "\x1b[%d;1H", y+1) switch { case y == rows-1: // The status line: a few segments with backgrounds. for n, i := 0, 0; n < cols; i++ { seg := []string{" NORMAL ", " main ", " internal/ui/ui.go ", " utf-8 ", " 42:7 "}[i%5] if n+len(seg) > cols { seg = seg[:cols-n] } fmt.Fprintf(&b, "\x1b[0;1;38;5;%d;48;5;%dm%s", 255-i%3, 54+i%5*12, seg) n += len(seg) } default: bg := "49" if y == rows/2 { bg = "48;5;189" // the cursor line } fmt.Fprintf(&b, "\x1b[0;%s;38;5;245m%4d ", bg, y+1) n := 5 for i := y; n < cols; i++ { t := tokens[i%len(tokens)] w := t.text + " " if n+len(w) > cols { w = w[:cols-n] } fmt.Fprintf(&b, "\x1b[0;%s;%sm%s", bg, t.sgr, w) n += len(w) } } } b.WriteString("\x1b[0m") return []byte(b.String())}