Add self-update, version 1.0.1

ghosttyconf --update installs the newest release from git.micw.org,
--check-update only checks. The download lands next to the running
binary, is started once with --version and only then replaces it.

Once a day a normal start asks in the background and mentions a newer
release in the header, at the top of the help and on stderr after
quitting; only on a terminal and not with GHOSTTYCONF_NO_UPDATE_CHECK
set. selfupdate.go is nscan's copyable template, with goca's --update
spelling in the hints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mikeandClaude Opus 5.5 committed 2026-10-28 10:22:51 +01:00
1 parent e5750ef24b
commit fb5602452a
13 files changed
+818 -11

No files matched your search

+25
View File
@@ -5,6 +5,7 @@ import (
"testing"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
"ghosttyconf/internal/config"
"ghosttyconf/internal/schema"
@@ -218,3 +219,27 @@ func TestUnknownKeyIsListed(t *testing.T) {
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)
}
}