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>
293 lines
8.4 KiB
Go
293 lines
8.4 KiB
Go
package ui
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/x/ansi"
|
|
|
|
"ghosttyconf/internal/config"
|
|
"ghosttyconf/internal/schema"
|
|
)
|
|
|
|
func newTestApp(t *testing.T, content string) *App {
|
|
t.Helper()
|
|
sch, err := schema.Embedded()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
f := &config.File{Path: "/tmp/ghosttyconf-test/config.ghostty", Lines: config.Parse([]byte(content))}
|
|
a := New(sch, nil, f)
|
|
a.Update(tea.WindowSizeMsg{Width: 160, Height: 45})
|
|
return a
|
|
}
|
|
|
|
func press(a *App, keys ...string) {
|
|
for _, k := range keys {
|
|
var msg tea.KeyMsg
|
|
switch k {
|
|
case "enter":
|
|
msg = tea.KeyMsg{Type: tea.KeyEnter}
|
|
case "esc":
|
|
msg = tea.KeyMsg{Type: tea.KeyEsc}
|
|
case "down":
|
|
msg = tea.KeyMsg{Type: tea.KeyDown}
|
|
case "up":
|
|
msg = tea.KeyMsg{Type: tea.KeyUp}
|
|
case "tab":
|
|
msg = tea.KeyMsg{Type: tea.KeyTab}
|
|
case "shift+tab":
|
|
msg = tea.KeyMsg{Type: tea.KeyShiftTab}
|
|
case "space":
|
|
msg = tea.KeyMsg{Type: tea.KeySpace, Runes: []rune{' '}}
|
|
default:
|
|
msg = tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(k)}
|
|
}
|
|
a.Update(msg)
|
|
}
|
|
}
|
|
|
|
// TestEveryEditorRenders opens the editor of every option at several
|
|
// terminal sizes to catch panics and layout bugs.
|
|
func TestEveryEditorRenders(t *testing.T) {
|
|
a := newTestApp(t, "font-family = Hack\nkeybind = ctrl+a=new_tab\npalette = 1=#ff0000\n")
|
|
sizes := [][2]int{{160, 45}, {100, 30}, {60, 16}, {40, 12}}
|
|
for _, o := range a.sch.Options {
|
|
for _, sz := range sizes {
|
|
a.Update(tea.WindowSizeMsg{Width: sz[0], Height: sz[1]})
|
|
a.edit(o)
|
|
if a.editor == nil && o.Kind != schema.KindBool {
|
|
t.Fatalf("%s: no editor opened", o.Key)
|
|
}
|
|
_ = a.View()
|
|
press(a, "down", "down")
|
|
_ = a.View()
|
|
for i := 0; i < 3 && a.editor != nil; i++ {
|
|
press(a, "esc")
|
|
}
|
|
if a.editor != nil {
|
|
t.Fatalf("%s: editor did not close on esc", o.Key)
|
|
}
|
|
_ = a.View()
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEditEnumAndUndo(t *testing.T) {
|
|
a := newTestApp(t, "# keep me\ncursor-style = block\n")
|
|
press(a, "/")
|
|
for _, r := range "cursor-style" {
|
|
press(a, string(r))
|
|
}
|
|
press(a, "enter")
|
|
if o := a.selected(); o == nil || o.Key != "cursor-style" {
|
|
t.Fatalf("selected = %v", o)
|
|
}
|
|
press(a, "enter", "down", "enter") // block -> bar
|
|
if v, _ := a.file.Get("cursor-style"); v != "bar" {
|
|
t.Fatalf("cursor-style = %q", v)
|
|
}
|
|
if !a.dirty() {
|
|
t.Fatal("expected unsaved changes")
|
|
}
|
|
press(a, "u")
|
|
if v, _ := a.file.Get("cursor-style"); v != "block" {
|
|
t.Fatalf("after undo cursor-style = %q", v)
|
|
}
|
|
if a.dirty() {
|
|
t.Fatal("undo should restore the saved state")
|
|
}
|
|
if !strings.HasPrefix(string(a.file.Bytes()), "# keep me\n") {
|
|
t.Fatal("comment lost")
|
|
}
|
|
}
|
|
|
|
func TestToggleStepAndReset(t *testing.T) {
|
|
a := newTestApp(t, "font-size = 13\n")
|
|
a.selectCategory(0) // Set in Config
|
|
press(a, "+", "+")
|
|
if v, _ := a.file.Get("font-size"); v != "14" {
|
|
t.Fatalf("font-size = %q", v)
|
|
}
|
|
press(a, "r")
|
|
if a.file.Has("font-size") {
|
|
t.Fatal("font-size should have been removed")
|
|
}
|
|
}
|
|
|
|
func TestKeybindListAdd(t *testing.T) {
|
|
a := newTestApp(t, "")
|
|
a.edit(a.sch.Lookup("keybind"))
|
|
press(a, "a")
|
|
for _, r := range "ctrl+shift+t" {
|
|
press(a, string(r))
|
|
}
|
|
press(a, "tab")
|
|
for _, r := range "new_tab" {
|
|
press(a, string(r))
|
|
}
|
|
press(a, "enter", "esc")
|
|
if got := a.file.GetAll("keybind"); len(got) != 1 || got[0] != "ctrl+shift+t=new_tab" {
|
|
t.Fatalf("keybind = %v", got)
|
|
}
|
|
}
|
|
|
|
func TestKeybindManagerChangeDefault(t *testing.T) {
|
|
a := newTestApp(t, "")
|
|
o := a.sch.Lookup("keybind")
|
|
a.edit(o)
|
|
m, ok := a.editor.(*keybindManager)
|
|
if !ok {
|
|
t.Fatalf("editor is %T", a.editor)
|
|
}
|
|
// Find the built-in super+d binding and move it to super+shift+d.
|
|
press(a, "/")
|
|
for _, r := range "super+d" {
|
|
press(a, string(r))
|
|
}
|
|
press(a, "enter")
|
|
b := m.selected()
|
|
if b == nil || b.Trigger != "super+d" {
|
|
t.Fatalf("selected = %+v", b)
|
|
}
|
|
press(a, "enter") // change
|
|
press(a, "shift+tab") // trigger field
|
|
a.Update(tea.KeyMsg{Type: tea.KeyCtrlU}) // clear it
|
|
for _, r := range "super+shift+d" {
|
|
press(a, string(r))
|
|
}
|
|
press(a, "enter", "esc")
|
|
got := strings.Join(a.file.GetAll("keybind"), " | ")
|
|
if got != "super+d=unbind | super+shift+d="+b.Action {
|
|
t.Fatalf("keybind = %s", got)
|
|
}
|
|
}
|
|
|
|
func TestKeybindManagerUnbindRestore(t *testing.T) {
|
|
a := newTestApp(t, "")
|
|
a.edit(a.sch.Lookup("keybind"))
|
|
m := a.editor.(*keybindManager)
|
|
b := *m.selected()
|
|
press(a, "d")
|
|
if v := m.set.Values(); len(v) != 1 || !strings.HasSuffix(v[0], "=unbind") {
|
|
t.Fatalf("after unbind: %v", v)
|
|
}
|
|
press(a, "r")
|
|
if v := m.set.Values(); len(v) != 0 {
|
|
t.Fatalf("after restore: %v", v)
|
|
}
|
|
press(a, "esc")
|
|
if a.file.Has("keybind") {
|
|
t.Fatalf("no change expected, got %v (binding %s)", a.file.GetAll("keybind"), b.Trigger)
|
|
}
|
|
}
|
|
|
|
func TestKeybindRecording(t *testing.T) {
|
|
a := newTestApp(t, "")
|
|
a.edit(a.sch.Lookup("keybind"))
|
|
press(a, "a")
|
|
a.Update(tea.KeyMsg{Type: tea.KeyCtrlR})
|
|
if !a.capturing() {
|
|
t.Fatal("not recording")
|
|
}
|
|
// ctrl+c must be recorded, not quit the program.
|
|
_, cmd := a.Update(tea.KeyMsg{Type: tea.KeyCtrlC})
|
|
if a.dlg != nil || cmd != nil && a.capturing() == false {
|
|
t.Fatal("ctrl+c was not captured")
|
|
}
|
|
press(a, "enter")
|
|
if a.capturing() {
|
|
t.Fatal("still recording")
|
|
}
|
|
for _, r := range "copy_to_clipboard" {
|
|
press(a, string(r))
|
|
}
|
|
press(a, "enter", "esc")
|
|
if got := a.file.GetAll("keybind"); len(got) != 1 || got[0] != "ctrl+c=copy_to_clipboard" {
|
|
t.Fatalf("keybind = %v", got)
|
|
}
|
|
}
|
|
|
|
func TestUnknownKeyIsListed(t *testing.T) {
|
|
a := newTestApp(t, "bogus-key = 1\n")
|
|
a.selectCategory(0)
|
|
if len(a.opts) != 1 || a.opts[0].Key != "bogus-key" {
|
|
t.Fatalf("opts = %v", a.opts)
|
|
}
|
|
if !strings.Contains(a.View(), "bogus-key") {
|
|
t.Fatal("unknown key not rendered")
|
|
}
|
|
}
|
|
|
|
func TestUpdateHintShown(t *testing.T) {
|
|
a := newTestApp(t, "")
|
|
a.SetVersion("1.0.0")
|
|
a.SetUpdate("1.0.1")
|
|
header := func() string { return strings.SplitN(ansi.Strip(a.View()), "\n", 2)[0] }
|
|
if h := header(); !strings.Contains(h, "ghosttyconf 1.0.1 available · ") || !strings.Contains(h, "options") {
|
|
t.Errorf("header at 160 columns: %q", h)
|
|
}
|
|
// Short of space, the update outlasts the option count.
|
|
a.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
|
|
if h := header(); !strings.Contains(h, "ghosttyconf 1.0.1 available") || strings.Contains(h, "options") {
|
|
t.Errorf("header at 80 columns: %q", h)
|
|
}
|
|
press(a, "?")
|
|
if !strings.Contains(ansi.Strip(a.View()), "1.0.1 is available, run ghosttyconf --update") {
|
|
t.Error("help does not mention the update")
|
|
}
|
|
|
|
a = newTestApp(t, "")
|
|
if h := header(); strings.Contains(h, "available") || !strings.Contains(h, "options") {
|
|
t.Errorf("header without an update: %q", h)
|
|
}
|
|
}
|
|
|
|
func TestOldNameIsRenamed(t *testing.T) {
|
|
a := newTestApp(t, "# big scrollback\nscrollback-limit = 100000000\n")
|
|
a.selectCategory(0)
|
|
old := a.selected()
|
|
if old == nil || old.Key != "scrollback-limit" {
|
|
t.Fatalf("selected = %v", old)
|
|
}
|
|
if doc := ansi.Strip(a.docContent(old, 100)); !strings.Contains(doc, "old name of") || strings.Contains(doc, "misspelled") {
|
|
t.Errorf("doc of the old name:\n%s", doc)
|
|
}
|
|
// The current option shows the value set under its old name.
|
|
doc := ansi.Strip(a.docContent(a.sch.Lookup("scrollback-limit-bytes"), 100))
|
|
if !strings.Contains(doc, "100000000 ● set as scrollback-limit") || !strings.Contains(doc, "also reads the old name") {
|
|
t.Errorf("doc of the new name:\n%s", doc)
|
|
}
|
|
|
|
press(a, "enter")
|
|
if got := string(a.file.Bytes()); got != "# big scrollback\nscrollback-limit-bytes = 100000000\n" {
|
|
t.Fatalf("after rename:\n%s", got)
|
|
}
|
|
if o := a.selected(); o == nil || o.Key != "scrollback-limit-bytes" {
|
|
t.Errorf("selected after rename = %v", o)
|
|
}
|
|
press(a, "u")
|
|
if !a.file.Has("scrollback-limit") || a.dirty() {
|
|
t.Error("undo did not restore the old name")
|
|
}
|
|
}
|
|
|
|
func TestOldValueAndReplacedOption(t *testing.T) {
|
|
a := newTestApp(t, "copy-on-select = true\nbold-is-bright = true\n")
|
|
doc := ansi.Strip(a.docContent(a.sch.Lookup("copy-on-select"), 100))
|
|
if strings.Contains(doc, "invalid") || !strings.Contains(doc, "an old value") || !strings.Contains(doc, "none, primary, clipboard, both") {
|
|
t.Errorf("doc of copy-on-select = true:\n%s", doc)
|
|
}
|
|
doc = ansi.Strip(a.docContent(a.option("bold-is-bright"), 100))
|
|
if !strings.Contains(doc, "now sets bold-color") || strings.Contains(doc, "misspelled") {
|
|
t.Errorf("doc of bold-is-bright:\n%s", doc)
|
|
}
|
|
// Not renamed: enter edits the line as text.
|
|
a.selectCategory(0)
|
|
press(a, "down", "enter")
|
|
if a.editor == nil {
|
|
t.Error("enter on a replaced option opens no editor")
|
|
}
|
|
}
|