Skip to content

refactor(tui): simplify components, drop dead code, consolidate helpers#2544

Merged
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/simplifying-custom-tui-component-5a41ea99
Apr 27, 2026
Merged

refactor(tui): simplify components, drop dead code, consolidate helpers#2544
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/simplifying-custom-tui-component-5a41ea99

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Apr 27, 2026

Two behavior-preserving refactor commits over pkg/tui/components/. Build, go vet, golangci-lint run ./... (0 issues) and the full go test ./... suite all pass.

Net diff: −277 / +103 across 17 files (one file deleted, two added).

Commits

1. refactor(tui): drop dead code and unused options across components

  • scrollview: remove unused WithGapWidth option.
  • sidebar: remove unused WithLayoutConfig, the Option type, and the opts ...Option parameter on New (no caller passes options).
  • reasoningblock: remove the BlockMsg / blockMsgBase / ToggleMsg / GetBlockID infrastructure — no code ever constructs a ToggleMsg, so the matching switch case in messages.Update was unreachable.
  • messages: drop the unreachable case reasoningblock.BlockMsg: branch and the orphaned forwardToReasoningBlock helper.
  • tool/registry: remove the unused single-name Registry.Register(name, builder) overload (only RegisterAll was called).
  • markdown: move NewGlamourRenderer into fast_renderer_test.go as newGlamourRenderer (only tests use it). Production renderer.go no longer imports glamour or styles.
  • message: move stripANSI (and its regex) into message_test.go. Production message.go no longer imports regexp.

2. refactor(tui): simplify tool factory and consolidate render helpers

  • tool: collapse Registry + Factory into a single static lookup table in factory.go; delete registry.go. The previous abstraction (Registry, Factory, Registration, NewRegistry, NewFactory, sync.RWMutex) was never instantiated externally and added indirection over a static map. tool.New API is unchanged. The map is initialized once at package load and only read afterwards, so the mutex is not needed.
  • toolcommon: introduce NoArgsRenderer for tools that only show the icon + tool name (e.g. user_prompt, todo helpers). userprompt.go and todotool/component.go collapse to a one-line New().
  • toolcommon: add Pluralize(count, singular, plural) and use it from listdirectory, directorytree, and searchfilescontent (each had its own copy/variant). The formatCount unit test moves to toolcommon/pluralize_test.go alongside the helper.
  • toolcommon: drop the unused Base getters (Message, SessionState, Width, Height, Spinner) — every renderer already gets these via the Renderer signature.
  • tool/factory.go: clearer package doc comment spelling out the lookup order.

What was deliberately not touched

  • The big files (markdown/fast_renderer.go, messages/messages.go, editor/editor.go, editfile/render.go). Heavily exercised by tests; refactoring them is high-risk and orthogonal to readability.
  • tab / tabbar (different concepts despite similar filenames; both used).
  • The other public scrollview options (WithReserveScrollbarSpace, WithWheelStep, WithKeyMap) — all in active use.
  • The uniform Renderer(msg, spinner, sessionState, width, height) signature, even where individual renderers ignore parameters, because Base orchestrates spinners and resize uniformly.

Validation

  • go build ./...
  • go vet ./...
  • golangci-lint run ./... ✅ — 0 issues
  • go test ./... -count=1 ✅ — all packages green
  • deadcode -filter pkg/tui/components/ ./... ✅ — no remaining unreachable code

Internally reviewed (no bugs, security issues, concurrency issues, or coverage gaps found).

dgageot added 2 commits April 27, 2026 17:27
Remove unreachable functions, unused functional options and
test-only helpers from the production code paths in pkg/tui.
No behavior change; builds, lint, and the full test suite all
pass.

- scrollview: remove unused WithGapWidth option.
- sidebar: remove unused WithLayoutConfig and Option type, drop
  the variadic opts ...Option from New (no caller passes any).
- reasoningblock: remove the BlockMsg/blockMsgBase/ToggleMsg/
  GetBlockID infrastructure; nothing constructed a ToggleMsg.
- messages: drop the now-unreachable BlockMsg switch case in
  Update and the orphaned forwardToReasoningBlock helper.
- tool/registry: collapse Register/RegisterAll into a single
  Register(registrations) entry point; the per-name overload
  was never called.
- markdown: move newGlamourRenderer into fast_renderer_test.go
  (only tests used it); production renderer.go no longer needs
  the glamour or styles imports.
- message: move stripANSI into message_test.go (only tests
  used it); production message.go no longer needs regexp.

Assisted-By: docker-agent
Reduce boilerplate and surface area in pkg/tui/components/tool
without changing behavior. Build, lint, and the full test suite
still pass.

- tool: collapse the Registry+Factory abstraction into a single
  package-level lookup table in factory.go and delete registry.go.
  The previous types (Registry, Factory, Registration, NewRegistry,
  NewFactory, the RWMutex) were never instantiated externally and
  added indirection for a static map. Resulting tool.New is the
  same API as before.
- toolcommon: introduce NoArgsRenderer for tools that only need
  the "icon + name" header (user_prompt, todo_*). userprompt and
  todotool/component.go now collapse to a one-line New().
- toolcommon: add Pluralize helper and use it from listdirectory,
  directorytree, and searchfilescontent (each had its own
  copy/variant). The unit test moves to toolcommon alongside the
  helper.
- toolcommon: drop the unused Base getters (Message, SessionState,
  Width, Height, Spinner). All renderers receive these directly via
  the Renderer signature.

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner April 27, 2026 15:56
@dgageot dgageot merged commit 672101e into docker:main Apr 27, 2026
9 checks passed
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.

2 participants