Skip to content

Conversation

@piekstra
Copy link
Contributor

[#14]

Extract mode-specific state from the flat Model struct into dedicated sub-types for better organization and clarity.

Changes

New sub-model types:

  • MainState: Holds state for the main two-pane view (pendingOps, showConfirm, showQuitConfirm, mouseEnabled)
  • FilterState: Holds state for filter mode (active, text)
  • ProgressState: Holds state for operation progress (operations, errors, currentIdx, loading)

Updated Model struct:

type Model struct {
    // Core state (always used)
    client      claude.Client
    styles      Styles
    keys        KeyBindings
    plugins     []PluginState
    filteredIdx []int
    mode        Mode
    height      int
    width       int
    selectedIdx int
    listOffset  int
    err         error
    workingDir  string

    // Mode-specific state (value types)
    main     MainState
    filter   FilterState
    progress ProgressState
}

Benefits

  1. Clearer organization - Mode responsibilities are explicit
  2. Easier testing - Can test mode state in isolation
  3. Better documentation - Type names document purpose
  4. Future-proof - Adding new modes doesn't pollute main struct
  5. Initialization clarity - Each mode can have its own constructor

Migration

All existing functionality preserved. Field accesses updated to use sub-models:

  • m.pendingOpsm.main.pendingOps
  • m.filterActivem.filter.active
  • m.operationsm.progress.operations
  • etc.

Closes #14

Extract mode-specific state from Model into dedicated sub-types:
- MainState: pendingOps, showConfirm, showQuitConfirm, mouseEnabled
- FilterState: active, text
- ProgressState: operations, errors, currentIdx, loading

This improves code organization and makes mode responsibilities explicit.
All existing functionality preserved with updated field accesses.

[#14]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(tui): Extract mode-specific state into sub-models

2 participants