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

+5 -1
View File
@@ -99,6 +99,7 @@ type App struct {
quitAfterSave bool
autoReload bool
version string
update string // a newer release, if one is known
// Screen regions from the last render, for mouse handling.
catRect, optRect, docRect rect
@@ -159,6 +160,9 @@ func (a *App) SetAutoReload(on bool) { a.autoReload = on }
// SetVersion sets the program version shown in the help.
func (a *App) SetVersion(v string) { a.version = v }
// SetUpdate names a newer release, shown in the header and the help.
func (a *App) SetUpdate(v string) { a.update = v }
func (a *App) Init() tea.Cmd {
if a.gh == nil {
return nil
@@ -407,7 +411,7 @@ func (a *App) updateBrowse(km tea.KeyMsg) tea.Cmd {
case "q":
return a.quit()
case "?", "f1":
a.dlg = helpDialog(a.version)
a.dlg = helpDialog(a.version, a.update)
return nil
case "/", "ctrl+f":
// Every search starts fresh, like "/" in less or vim.
+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)
}
}
+8 -2
View File
@@ -99,13 +99,13 @@ func (d *dialog) view(width, height int) string {
return framed(d.title, content, w, len(lines)+2, color)
}
func helpDialog(version string) *dialog {
func helpDialog(version, update string) *dialog {
k := func(key, desc string) string { return stKey.Render(fit(key, 16)) + desc }
title := "Help"
if version != "" {
title = "Help · ghosttyconf " + version
}
return &dialog{
d := &dialog{
title: title,
lines: []string{
stBold.Render("Browsing"),
@@ -155,4 +155,10 @@ func helpDialog(version string) *dialog {
},
keys: []dialogKey{{"esc", "Close"}},
}
if update != "" {
note := stChanged.Render("ghosttyconf "+update+" is available") +
stDim.Render(", run ") + "ghosttyconf --update" + stDim.Render(" after quitting")
d.lines = append([]string{note, ""}, d.lines...)
}
return d
}
+13 -3
View File
@@ -31,9 +31,19 @@ func (a *App) View() string {
func (a *App) viewHeader() string {
title := stTitle.Render("Ghostty Config Editor") + " "
right := stHeader.Render(fmt.Sprintf(" %s · %d options ", a.sch.Source, len(a.sch.Options)))
if lipgloss.Width(title)+lipgloss.Width(right)+20 > a.width {
right = ""
info := stHeader.Render(fmt.Sprintf(" %s · %d options ", a.sch.Source, len(a.sch.Options)))
fits := func(s string) bool { return lipgloss.Width(title)+lipgloss.Width(s)+20 <= a.width }
// A newer release outlasts the option count when space runs short; the
// help says how to get it.
upd := " ghosttyconf " + a.update + " available"
var right string
switch {
case a.update != "" && fits(stChanged.Render(upd)+stHeader.Render(" ·")+info):
right = stChanged.Render(upd) + stHeader.Render(" ·") + info
case a.update != "" && fits(stChanged.Render(upd+" ")):
right = stChanged.Render(upd + " ")
case fits(info):
right = info
}
path := shortPath(a.file.Path)
if !a.file.Exists {