Support Ghostty 1.4, version 1.0.2
The built-in schema now describes Ghostty 1.4.0: 212 options, the new choices of copy-on-select, window-padding-balance = equal, number limits that also take "unlimited", and categories for the new options. genschema reads Ghostty's compatibility table, so old names and values Ghostty still accepts are no longer reported as errors: a renamed key such as scrollback-limit is shown in yellow and renamed in place with enter, a replaced option names its successors, and old values such as copy-on-select = true are accepted with a note. Theme previews expand ~/ like Ghostty 1.4 and only look where Ghostty looks for user themes. Theme names with parentheses of their own keep them. A live test checks every ghostty command against the installed Ghostty. Docs and screenshots updated for 1.4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fb5602452a
commit
df261910c5
26 files changed
+920
-132
No files matched your search
@@ -110,9 +110,11 @@ func (g *Ghostty) Themes() ([]string, error) {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
// Lines look like "Dracula (resources)" or "Mine (user)".
|
||||
if i := strings.LastIndex(line, " ("); i > 0 && strings.HasSuffix(line, ")") {
|
||||
line = line[:i]
|
||||
// Lines look like "Dracula (resources)" or "Mine (user)". Only these
|
||||
// two are cut off: names such as "Black Metal (Bathory)" have
|
||||
// parentheses of their own.
|
||||
for _, loc := range []string{" (resources)", " (user)"} {
|
||||
line = strings.TrimSuffix(line, loc)
|
||||
}
|
||||
if !seen[line] {
|
||||
seen[line] = true
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package ghostty
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestLiveGhostty runs every command ghosttyconf uses against the installed
|
||||
// Ghostty and checks that the output is still understood. It is meant for a
|
||||
// new Ghostty release and only runs when asked for:
|
||||
//
|
||||
// GHOSTTYCONF_LIVE_TEST=1 go test -run Live -v ./internal/ghostty
|
||||
func TestLiveGhostty(t *testing.T) {
|
||||
if os.Getenv("GHOSTTYCONF_LIVE_TEST") == "" {
|
||||
t.Skip("set GHOSTTYCONF_LIVE_TEST=1 to run against the installed Ghostty")
|
||||
}
|
||||
g, err := Find(os.Getenv("GHOSTTYCONF_GHOSTTY"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if g.Version == "" {
|
||||
t.Fatal("+version: no version found")
|
||||
}
|
||||
t.Logf("Ghostty %s at %s", g.Version, g.Bin)
|
||||
|
||||
docs, err := g.DefaultsWithDocs()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{"\nfont-family = ", "\nkeybind = ", "\n# "} {
|
||||
if !strings.Contains(docs, want) {
|
||||
t.Errorf("+show-config --default --docs: no %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
themes, err := g.Themes()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(themes) < 100 || !slices.Contains(themes, "Catppuccin Mocha") {
|
||||
t.Errorf("+list-themes: %d themes, Catppuccin Mocha missing or too few", len(themes))
|
||||
}
|
||||
for _, name := range themes {
|
||||
if strings.HasSuffix(name, " (resources)") || strings.HasSuffix(name, " (user)") {
|
||||
t.Errorf("+list-themes: location left on %q", name)
|
||||
break
|
||||
}
|
||||
}
|
||||
th, err := g.LoadTheme("Catppuccin Mocha")
|
||||
if err != nil {
|
||||
t.Fatalf("theme file: %v", err)
|
||||
}
|
||||
if th.Background == "" || th.Palette[15] == "" {
|
||||
t.Errorf("theme file: %+v", th)
|
||||
}
|
||||
|
||||
fonts, err := g.Fonts()
|
||||
if err != nil || len(fonts) == 0 {
|
||||
t.Errorf("+list-fonts: %d fonts, %v", len(fonts), err)
|
||||
}
|
||||
|
||||
actions, err := g.Actions()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
byName := map[string]Action{}
|
||||
for _, a := range actions {
|
||||
byName[a.Name] = a
|
||||
}
|
||||
if a := byName["new_split"]; len(actions) < 50 || a.Summary == "" || !strings.Contains(a.Doc, "right") {
|
||||
t.Errorf("+list-actions --docs: %d actions, new_split = %+v", len(actions), a)
|
||||
}
|
||||
|
||||
conf := filepath.Join(t.TempDir(), "config")
|
||||
if err := os.WriteFile(conf, []byte("font-size = 14\nfont-size = abc\nbogus-key = 1\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
errs, err := g.Validate(conf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(errs) != 2 || errs[0].Line != 2 || errs[1].Line != 3 {
|
||||
t.Errorf("+validate-config: %v", errs)
|
||||
}
|
||||
}
|
||||
@@ -68,21 +68,23 @@ type Theme struct {
|
||||
}
|
||||
|
||||
// ThemeDirs returns the directories searched for themes, user dirs first.
|
||||
// Like Ghostty, this is the XDG config directory even on macOS, where the
|
||||
// config file itself usually lives under Application Support.
|
||||
func (g *Ghostty) ThemeDirs() []string {
|
||||
dirs := []string{filepath.Join(xdgConfigDir(), "themes")}
|
||||
if runtime.GOOS == "darwin" {
|
||||
dirs = append(dirs, filepath.Join(macConfigDir(), "themes"))
|
||||
}
|
||||
if r := g.ResourcesDir(); r != "" {
|
||||
dirs = append(dirs, filepath.Join(r, "themes"))
|
||||
}
|
||||
return dirs
|
||||
}
|
||||
|
||||
// LoadTheme reads a theme by name (or absolute path) for previewing.
|
||||
// LoadTheme reads a theme by name (or path) for previewing. A leading "~/"
|
||||
// stands for the home directory, as in Ghostty 1.4 and later.
|
||||
func (g *Ghostty) LoadTheme(name string) (*Theme, error) {
|
||||
var path string
|
||||
if filepath.IsAbs(name) {
|
||||
if rest, ok := strings.CutPrefix(name, "~/"); ok {
|
||||
path = filepath.Join(os.Getenv("HOME"), rest)
|
||||
} else if filepath.IsAbs(name) {
|
||||
path = name
|
||||
} else {
|
||||
for _, d := range g.ThemeDirs() {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package ghostty
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadThemeExpandsHome(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
dir := filepath.Join(home, "themes")
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
theme := "background = #252528\npalette = 1=#f38ba8\n"
|
||||
if err := os.WriteFile(filepath.Join(dir, "mine"), []byte(theme), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
th, err := (&Ghostty{}).LoadTheme("~/themes/mine")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if th.Background != "#252528" || th.Palette[1] != "#f38ba8" {
|
||||
t.Errorf("theme: %+v", th)
|
||||
}
|
||||
}
|
||||
|
||||
// Ghostty looks for user themes in the XDG config directory only, also on
|
||||
// macOS, where the config file usually lives under Application Support.
|
||||
func TestThemeDirsFollowGhostty(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", "")
|
||||
t.Setenv("GHOSTTY_RESOURCES_DIR", "")
|
||||
got := (&Ghostty{}).ThemeDirs()
|
||||
want := []string{filepath.Join(home, ".config", "ghostty", "themes")}
|
||||
if !slices.Equal(got, want) {
|
||||
t.Errorf("ThemeDirs = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user