|
8 | 8 | "log/slog" |
9 | 9 | "os" |
10 | 10 | "os/exec" |
11 | | - "reflect" |
12 | 11 | goruntime "runtime" |
13 | | - "slices" |
14 | 12 | "strings" |
15 | 13 | "sync" |
16 | 14 | "time" |
@@ -290,23 +288,9 @@ type Option func(*appModel) |
290 | 288 | func WithLeanMode() Option { |
291 | 289 | return func(m *appModel) { |
292 | 290 | m.leanMode = true |
293 | | - m.addDisabledCommands(leanModeDisabledSlashCommands) |
294 | 291 | } |
295 | 292 | } |
296 | 293 |
|
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 | | - |
310 | 294 | // WithHideSidebar hides the chat sidebar. Unlike lean mode, the rest of |
311 | 295 | // the chrome (tab bar, status bar, dialogs) remains visible. The user |
312 | 296 | // cannot bring the sidebar back via the TUI. |
@@ -376,28 +360,22 @@ func WithVersion(v string) Option { |
376 | 360 | // command names (so "/Cost" and "/cost" are equivalent). |
377 | 361 | func WithDisabledCommands(slashCommands []string) Option { |
378 | 362 | 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 |
396 | 365 | } |
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 |
399 | 378 | } |
400 | | - m.disabledCommands[c] = true |
401 | 379 | } |
402 | 380 | } |
403 | 381 |
|
@@ -800,33 +778,15 @@ func (m *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
800 | 778 | return model, cmd |
801 | 779 | } |
802 | 780 |
|
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 | | - |
823 | 781 | func (m *appModel) update(msg tea.Msg) (tea.Model, tea.Cmd) { |
824 | 782 | // 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 | + } |
830 | 790 | } |
831 | 791 |
|
832 | 792 | switch msg := msg.(type) { |
|
0 commit comments