Finish settings TODO cleanup

This commit is contained in:
2026-05-18 10:05:26 +01:00
parent cadd4c8f64
commit f10598601f
8 changed files with 131 additions and 86 deletions

View File

@@ -505,7 +505,18 @@ func (st *uiState) dbgf(format string, args ...any) {
}
func (st *uiState) activeSummaryText(width int) string {
if width <= 0 || st.summaries == nil {
text := st.activeSummaryRaw()
if text == "" || width <= 0 {
return ""
}
if visibleLen(text) > width {
text = clipRunes(text, width-1) + "…"
}
return text
}
func (st *uiState) activeSummaryRaw() string {
if st.summaries == nil {
return ""
}
st.settingsMu.Lock()
@@ -525,9 +536,6 @@ func (st *uiState) activeSummaryText(width int) string {
if text == "" {
return ""
}
if visibleLen(text) > width {
text = clipRunes(text, width-1) + "…"
}
return text
}
@@ -1626,6 +1634,11 @@ func (st *uiState) processStdin(chunk []byte) {
adv = 1
}
i += adv
if action.kind == "settings-save" {
st.applySettingsAction(action)
st.renderPaletteLocked()
continue
}
if done {
a := action
pendingAction = &a

View File

@@ -1277,8 +1277,11 @@ func (p *paletteState) handleSettingsTextInput(chunk []byte, i int) (paletteActi
}
switch b {
case '\r', '\n':
p.applySettingsInput()
changed := p.applySettingsInput()
p.mode = paletteModeAutoSummary
if changed {
return p.settingsAction("settings-save"), false, 1
}
case 0x7f, 0x08:
if len(p.settingsInput.value) > 0 {
p.settingsInput.value = p.settingsInput.value[:len(p.settingsInput.value)-1]
@@ -1310,7 +1313,6 @@ func autoSummaryRows() []autoSummaryRow {
{key: "run_now", label: "Summarize current top-level agent now"},
{key: "save", label: "Save settings"},
{key: "cancel", label: "Cancel"},
{key: "back", label: "Back to Settings"},
}
}
@@ -1322,6 +1324,8 @@ func (p *paletteState) activateAutoSummaryRow() (paletteAction, bool, int) {
switch rows[p.cursor].key {
case "enabled":
p.settings.AutoSummary.Enabled = !p.settings.AutoSummary.Enabled
p.settings.normalize()
return p.settingsAction("settings-save"), false, 1
case "provider":
switch p.settings.AutoSummary.Provider {
case "codex":
@@ -1331,6 +1335,8 @@ func (p *paletteState) activateAutoSummaryRow() (paletteAction, bool, int) {
default:
p.settings.AutoSummary.Provider = "codex"
}
p.settings.normalize()
return p.settingsAction("settings-save"), false, 1
case "codex_model", "opencode_model", "claude_model":
provider := strings.TrimSuffix(rows[p.cursor].key, "_model")
p.settingsInput = &settingsInputForm{
@@ -1349,6 +1355,8 @@ func (p *paletteState) activateAutoSummaryRow() (paletteAction, bool, int) {
default:
p.settings.AutoSummary.Cadence = "15s"
}
p.settings.normalize()
return p.settingsAction("settings-save"), false, 1
case "test":
return p.settingsAction("settings-test"), true, 1
case "run_now":
@@ -1357,36 +1365,36 @@ func (p *paletteState) activateAutoSummaryRow() (paletteAction, bool, int) {
return p.settingsAction("settings-close"), true, 1
case "cancel":
return paletteAction{kind: "cancel"}, true, 1
case "back":
p.mode = paletteModeSettings
p.cursor = 0
p.query = nil
p.rebuildSettings()
}
p.settings.normalize()
return paletteAction{}, false, 1
}
func (p *paletteState) applySettingsInput() {
func (p *paletteState) applySettingsInput() bool {
if p.settingsInput == nil {
return
return false
}
val := strings.TrimSpace(string(p.settingsInput.value))
if val == "" {
return
return false
}
if p.settings.AutoSummary.Models == nil {
p.settings.AutoSummary.Models = defaultSummaryModels()
}
changed := false
switch p.settingsInput.field {
case "codex_model":
changed = p.settings.AutoSummary.Models["codex"] != val
p.settings.AutoSummary.Models["codex"] = val
case "opencode_model":
changed = p.settings.AutoSummary.Models["opencode"] != val
p.settings.AutoSummary.Models["opencode"] = val
case "claude_model":
changed = p.settings.AutoSummary.Models["claude"] != val
p.settings.AutoSummary.Models["claude"] = val
}
p.settings.normalize()
return changed
}
func (p *paletteState) settingsCloseAction() paletteAction {
@@ -1473,7 +1481,7 @@ func (p *paletteState) renderAutoSummary(out writeFlusher, cols, rows int) {
moveTo(&b, row, leftPad)
b.WriteString(styleBorder + "├" + strings.Repeat("─", width-2) + "┤" + styleReset)
row++
footer := styleHint + "↵ edit/toggle · cadence 15s/30s/1m · save row commits · esc cancel" + styleReset
footer := styleHint + "↵ edit/toggle · changes save when applied · esc cancel" + styleReset
if visibleLen(footer) > content {
footer = clipRunes(footer, content-1) + "…"
}
@@ -1503,7 +1511,7 @@ func (p *paletteState) autoSummaryDisplayRows() []string {
var out []string
for _, row := range autoSummaryRows() {
if v, ok := values[row.key]; ok {
out = append(out, row.label+": "+v)
out = append(out, styleHint+row.label+":"+styleReset+" "+v)
} else {
out = append(out, row.label)
}

View File

@@ -356,20 +356,71 @@ func TestAutoSummaryCadenceCyclesSoloValues(t *testing.T) {
if p.settings.AutoSummary.Cadence != "1m" {
t.Fatalf("initial cadence = %q", p.settings.AutoSummary.Cadence)
}
p.activateAutoSummaryRow()
action, done, _ := p.activateAutoSummaryRow()
if done || action.kind != "settings-save" {
t.Fatalf("first cycle action = %+v done=%v, want settings-save without close", action, done)
}
if p.settings.AutoSummary.Cadence != "15s" {
t.Fatalf("first cycle cadence = %q", p.settings.AutoSummary.Cadence)
}
p.activateAutoSummaryRow()
action, done, _ = p.activateAutoSummaryRow()
if done || action.kind != "settings-save" {
t.Fatalf("second cycle action = %+v done=%v, want settings-save without close", action, done)
}
if p.settings.AutoSummary.Cadence != "30s" {
t.Fatalf("second cycle cadence = %q", p.settings.AutoSummary.Cadence)
}
p.activateAutoSummaryRow()
action, done, _ = p.activateAutoSummaryRow()
if done || action.kind != "settings-save" {
t.Fatalf("third cycle action = %+v done=%v, want settings-save without close", action, done)
}
if p.settings.AutoSummary.Cadence != "1m" {
t.Fatalf("third cycle cadence = %q", p.settings.AutoSummary.Cadence)
}
}
func TestAutoSummaryScreenOmitsBackRow(t *testing.T) {
for _, row := range autoSummaryRows() {
if row.label == "Back to Settings" {
t.Fatal("auto-summary settings should not show Back to Settings")
}
}
}
func TestAutoSummaryValueRowsStyleLabelAndValueSeparately(t *testing.T) {
p := newPalette(nil, "", "", preset.Set{}, defaultSettings())
rows := p.autoSummaryDisplayRows()
for _, row := range rows {
if strings.Contains(row, "Cadence:") {
if !strings.HasPrefix(row, styleHint+"Cadence:"+styleReset+" ") {
t.Fatalf("cadence row styling = %q", row)
}
if strings.Contains(strings.TrimPrefix(row, styleHint+"Cadence:"+styleReset+" "), styleHint) {
t.Fatalf("cadence value should use regular text styling: %q", row)
}
return
}
}
t.Fatal("missing cadence display row")
}
func TestAutoSummaryTextInputSavesWhenSubmitted(t *testing.T) {
p := newPalette(nil, "", "", preset.Set{}, defaultSettings())
p.mode = paletteModeSettingsInput
p.settingsInput = &settingsInputForm{
title: "codex model",
field: "codex_model",
value: []rune("custom-model"),
}
action, done, _ := p.handleSettingsTextInput([]byte{'\r'}, 0)
if done || action.kind != "settings-save" {
t.Fatalf("submit action = %+v done=%v, want settings-save without close", action, done)
}
if got := p.settings.AutoSummary.modelFor("codex"); got != "custom-model" {
t.Fatalf("codex model = %q", got)
}
}
func TestPaletteFormCtrlRTogglesRelaunchFromCommandField(t *testing.T) {
p := newPalette(nil, "", "", preset.Set{})
p.mode = paletteModeSpawnForm

View File

@@ -331,7 +331,7 @@ func (st *uiState) drawSidebar() {
write(prefix + openStyle + nameCell + styleReset + suffix)
}
if summary := st.activeSummaryText(width - 4); summary != "" && row+2 <= maxRow {
if summary := st.activeSummaryRaw(); summary != "" && row+2 <= maxRow {
write("")
for _, line := range wrapSidebarSummary(summary, width-4) {
if row > maxRow {
@@ -417,7 +417,13 @@ func wrapSidebarSummary(s string, width int) []string {
out = append(out, cur)
cur = ""
}
out = append(out, clipRunes(word, width-1)+"…")
for visibleLen(word) > width {
out = append(out, clipRunes(word, width))
word = string([]rune(word)[width:])
}
if word != "" {
cur = word
}
continue
}
if cur == "" {

View File

@@ -42,8 +42,13 @@ func TestWrapSidebarSummaryKeepsWordBoundaries(t *testing.T) {
}
}
long := wrapSidebarSummary("supercalifragilistic short", 8)
if len(long) == 0 || !strings.HasSuffix(long[0], "…") {
t.Fatalf("long word should clip with ellipsis: %#v", long)
if len(long) == 0 || strings.Contains(strings.Join(long, ""), "…") {
t.Fatalf("long word should wrap without ellipsis: %#v", long)
}
for _, line := range long {
if visibleLen(line) > 8 {
t.Fatalf("line %q exceeds width", line)
}
}
}

View File

@@ -64,6 +64,7 @@ func (st *uiState) drawTabBar() {
label string
active bool
}
activeTab := -1
// Reserve space at the right edge for "+ new". If there are too
// many tabs to fit even at minTabWidth, drop tabs from the right
@@ -134,6 +135,9 @@ func (st *uiState) drawTabBar() {
label: label,
active: c.ID == focus,
})
if tabs[len(tabs)-1].active {
activeTab = len(tabs) - 1
}
col += w
}
}
@@ -195,8 +199,12 @@ func (st *uiState) drawTabBar() {
hintCol, styleBorder, strings.Repeat("─", newHintW), styleReset)
}
if summary := st.activeSummaryText(width - 2); summary != "" {
fmt.Fprintf(&b, "\x1b[2;1H %s%s%s", styleDim, summary, styleReset)
if activeTab >= 0 {
tab := tabs[activeTab]
summaryWidth := tab.width - 2
if summary := st.activeSummaryText(summaryWidth); summary != "" {
fmt.Fprintf(&b, "\x1b[2;%dH %s%s%s", tab.startCol, styleDim, summary, styleReset)
}
}
frame := b.String()