Skip to content

Commit af59005

Browse files
committed
Revert "Merge pull request #3724 from docker/fix/lean-mode-exclude-noop-commands"
This reverts commit eba9421, reversing changes made to d771c13.
1 parent 66a9488 commit af59005

2 files changed

Lines changed: 21 additions & 187 deletions

File tree

pkg/tui/tui.go

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import (
88
"log/slog"
99
"os"
1010
"os/exec"
11-
"reflect"
1211
goruntime "runtime"
13-
"slices"
1412
"strings"
1513
"sync"
1614
"time"
@@ -290,23 +288,9 @@ type Option func(*appModel)
290288
func WithLeanMode() Option {
291289
return func(m *appModel) {
292290
m.leanMode = true
293-
m.addDisabledCommands(leanModeDisabledSlashCommands)
294291
}
295292
}
296293

297-
// leanModeDisabledSlashCommands lists the built-in slash commands that are
298-
// no-ops in lean mode: their Execute produces a message type that
299-
// leanModeDroppedMessageTypes (see appModel.update) silently drops there, so
300-
// running the command would do nothing. WithLeanMode seeds disabledCommands
301-
// from this list so they are also hidden from completion and the palette.
302-
//
303-
// TestLeanModeDisabledSlashCommandsMatchDroppedMessages cross-checks this
304-
// list against leanModeDroppedMessageTypes so the two can't silently drift
305-
// apart.
306-
var leanModeDisabledSlashCommands = []string{
307-
"/settings", // OpenSettingsDialogMsg
308-
}
309-
310294
// WithHideSidebar hides the chat sidebar. Unlike lean mode, the rest of
311295
// the chrome (tab bar, status bar, dialogs) remains visible. The user
312296
// cannot bring the sidebar back via the TUI.
@@ -376,28 +360,22 @@ func WithVersion(v string) Option {
376360
// command names (so "/Cost" and "/cost" are equivalent).
377361
func WithDisabledCommands(slashCommands []string) Option {
378362
return func(m *appModel) {
379-
m.addDisabledCommands(slashCommands)
380-
}
381-
}
382-
383-
// addDisabledCommands normalizes slashCommands (lower-cased, "/"-prefixed)
384-
// and merges them into m.disabledCommands.
385-
func (m *appModel) addDisabledCommands(slashCommands []string) {
386-
if len(slashCommands) == 0 {
387-
return
388-
}
389-
if m.disabledCommands == nil {
390-
m.disabledCommands = make(map[string]bool, len(slashCommands))
391-
}
392-
for _, c := range slashCommands {
393-
c = strings.ToLower(strings.TrimSpace(c))
394-
if c == "" {
395-
continue
363+
if len(slashCommands) == 0 {
364+
return
396365
}
397-
if !strings.HasPrefix(c, "/") {
398-
c = "/" + c
366+
if m.disabledCommands == nil {
367+
m.disabledCommands = make(map[string]bool, len(slashCommands))
368+
}
369+
for _, c := range slashCommands {
370+
c = strings.ToLower(strings.TrimSpace(c))
371+
if c == "" {
372+
continue
373+
}
374+
if !strings.HasPrefix(c, "/") {
375+
c = "/" + c
376+
}
377+
m.disabledCommands[c] = true
399378
}
400-
m.disabledCommands[c] = true
401379
}
402380
}
403381

@@ -800,33 +778,15 @@ func (m *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
800778
return model, cmd
801779
}
802780

803-
// leanModeDroppedMessageTypes lists the message types that appModel.update
804-
// silently drops when leanMode is set, because the corresponding feature
805-
// (multi-tab sessions, sidebar, settings dialog) doesn't exist in lean mode.
806-
// It is the single source of truth for isLeanModeNoOp below, which in turn
807-
// TestLeanModeDisabledSlashCommandsMatchDroppedMessages uses to keep
808-
// leanModeDisabledSlashCommands (see WithLeanMode) from drifting out of sync.
809-
var leanModeDroppedMessageTypes = []reflect.Type{
810-
reflect.TypeFor[messages.SpawnSessionMsg](),
811-
reflect.TypeFor[messages.SwitchTabMsg](),
812-
reflect.TypeFor[messages.CloseTabMsg](),
813-
reflect.TypeFor[messages.ReorderTabMsg](),
814-
reflect.TypeFor[messages.ToggleSidebarMsg](),
815-
reflect.TypeFor[messages.OpenSettingsDialogMsg](),
816-
}
817-
818-
// isLeanModeNoOp reports whether msg is one of leanModeDroppedMessageTypes.
819-
func isLeanModeNoOp(msg tea.Msg) bool {
820-
return slices.Contains(leanModeDroppedMessageTypes, reflect.TypeOf(msg))
821-
}
822-
823781
func (m *appModel) update(msg tea.Msg) (tea.Model, tea.Cmd) {
824782
// In lean mode, silently drop messages for features that don't exist.
825-
// leanModeDroppedMessageTypes is the single source of truth for what's
826-
// dropped here; leanModeDisabledSlashCommands (see WithLeanMode) hides
827-
// the built-in slash commands that would otherwise do nothing.
828-
if m.leanMode && isLeanModeNoOp(msg) {
829-
return m, nil
783+
if m.leanMode {
784+
switch msg.(type) {
785+
case messages.SpawnSessionMsg, messages.SwitchTabMsg,
786+
messages.CloseTabMsg, messages.ReorderTabMsg,
787+
messages.ToggleSidebarMsg, messages.OpenSettingsDialogMsg:
788+
return m, nil
789+
}
830790
}
831791

832792
switch msg := msg.(type) {

pkg/tui/tui_leanmode_test.go

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)