Skip to content

Standardize TUI model updates on KeyPressMsg and constructor reuse - #30

Merged
polymorcodeus merged 2 commits into
mainfrom
tui-enhance
Sep 10, 2026
Merged

polymorcodeus merged 2 commits into
mainfrom
tui-enhance

Conversation

@polymorcodeus

Copy link
Copy Markdown
Owner

Summary

TUI architecture cleanup for internal/model, replacing tea.KeyMsg with tea.KeyPressMsg, making all Update() methods return copies, and routing entity creation through book.NewShelf/book.NewCollection.

What's new

  • Shared key handler - handleCommonKeys in internal/model/tea.go centralizes ctrl+c/esc/ctrl+p for all six TUI Update methods.
  • Immutable get* models - getMarkModel and getCollectionModel sync derived state via value-receiver reloadFromForm(); View() no longer triggers side effects.
  • Immutable edit* models - editShelfModel, editCollectionModel, and editMarkModel copy on form completion and wire entities before the write command runs.
  • Constructor reuse in the TUI - editShelfModel and editCollectionModel create v2 shelves/collections through book.NewShelf/book.NewCollection instead of inline ID/timestamp assignments.
  • Terminal error plumbing - new ErrorProvider interface lets runProgram return TUI errors after exit; ResultView suppresses output on error.

Behavior changes / guardrails

  • Derived model state starts nil and form constructors create local scaffolding structs (for example &book.Shelf{}) rather than storing fake values in the model.
  • updateShelfFileCmd closures now only add/touch entities and write files; creation happens in Update().
  • Shelf.ValidateNewCollectionName rejects empty or duplicate collection names in the TUI, matching the CLI behavior.
  • getShelfModel.View now displays the actual picked shelf name instead of the "fake" debug placeholder.
  • markModel.verifyMark is now a value receiver, matching verifyCollection.

Testing

  • make check runs fmt, vet, lint, and tests; all green.

@polymorcodeus
polymorcodeus merged commit 7c98b0f into main Sep 10, 2026
4 checks passed
@polymorcodeus
polymorcodeus deleted the tui-enhance branch September 10, 2026 02:21
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.

1 participant