Skip to content

refactor: centralize TUI layout logic and constants to standardize responsive dimensions#342

Merged
SuperCoolPencil merged 5 commits intomainfrom
fix-tui-magic
Apr 10, 2026
Merged

refactor: centralize TUI layout logic and constants to standardize responsive dimensions#342
SuperCoolPencil merged 5 commits intomainfrom
fix-tui-magic

Conversation

@SuperCoolPencil
Copy link
Copy Markdown
Member

@SuperCoolPencil SuperCoolPencil commented Apr 10, 2026

Greptile Summary

This PR centralizes TUI layout constants into constants.go and extracts responsive dimension helpers into layout_helpers.go, replacing scattered inline arithmetic in view_category.go, view_settings.go, and update_category.go. The refactor also replaces hardcoded style padding literals with named constants in styles.go.

Confidence Score: 5/5

Safe to merge — all findings are P2 suggestions; no logic regressions introduced by the refactor

The refactor is purely extractive: constants and helpers carry identical values/logic from their inline origins, the navigation state fix (SettingsState instead of DashboardState) is straightforwardly correct, and callers guard against extreme edge cases. The only remaining gap is missing unit tests for the non-trivial branching in CalculateTwoColumnWidths and GetGraphAreaDimensions, which is a P2 best-practice concern and does not block merge.

internal/tui/layout_helpers.go — CalculateTwoColumnWidths and GetGraphAreaDimensions have branching logic without unit test coverage

Important Files Changed

Filename Overview
internal/tui/layout_helpers.go New file centralizing layout dimension helpers; CalculateTwoColumnWidths has branching edge-case logic with no accompanying unit tests
internal/tui/constants.go New file collecting all layout, threshold, and padding constants; values are identical to prior hardcoded literals — clean extraction
internal/tui/styles.go Replaced hardcoded padding literals (0, 1) and (1, 2) with DefaultPaddingY/X and PopupPaddingY/X; functionally identical, improves consistency
internal/tui/update_category.go Replaced inline two-column width arithmetic with CalculateTwoColumnWidths; also fixes navigation state to return to SettingsState instead of DashboardState
internal/tui/view_category.go Now calls GetSettingsDimensions and CalculateTwoColumnWidths directly, removing the previously flagged pass-through wrapper
internal/tui/view_settings.go Now calls GetSettingsDimensions and CalculateTwoColumnWidths directly; updateSettingsInputWidthForViewport mirrors the same pattern as the category equivalent
internal/tui/view.go Adopts GetListWidth, GetHeaderHeight, and GetGraphAreaDimensions from the new helper module; no logic changes

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Window resize event] --> B[GetSettingsDimensions]
    B --> C{width within Min/Max bounds?}
    C -- clamp to range --> D[constrained width]
    D --> E{height fits terminal?}
    E -- clamp to maxHeight --> F[constrained height]
    F --> G{modalWidth >= threshold 72 settings / 76 category}
    G -- yes --> H[CalculateTwoColumnWidths]
    G -- no --> I[Compact single-column layout]
    H --> J{leftWidth >= 16?}
    J -- clamp to 16 --> K{rightWidth >= minRight?}
    J -- yes --> K
    K -- clamp + recalc left --> L[Two-column render]
    K -- yes --> L
    A2[Dashboard render] --> B2[GetListWidth]
    B2 --> C2{rightWidth >= MinRightColumnWidth?}
    C2 -- yes --> D2[Split list / detail]
    C2 -- no --> E2[Full-width list]
    A3[Graph render] --> B3[GetGraphAreaDimensions]
    B3 --> C3{isStatsHidden?}
    C3 -- yes --> D3[graphWidth = rightWidth - axis - frame x5]
    C3 -- no --> E3[graphWidth = rightWidth - stats - axis - frame x3]
Loading

Comments Outside Diff (1)

  1. internal/tui/view.go, line 406 (link)

    P2 GraphTargetHeightRatio constant unused at its only use-site

    GraphTargetHeightRatio = 0.4 was introduced in constants.go specifically for this calculation, but the raw literal 0.4 was left in place. The constant is never actually referenced anywhere, making it dead code and defeating the PR's stated goal.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: internal/tui/view.go
    Line: 406
    
    Comment:
    **`GraphTargetHeightRatio` constant unused at its only use-site**
    
    `GraphTargetHeightRatio = 0.4` was introduced in `constants.go` specifically for this calculation, but the raw literal `0.4` was left in place. The constant is never actually referenced anywhere, making it dead code and defeating the PR's stated goal.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: internal/tui/layout_helpers.go
Line: 91-111

Comment:
**New helpers lack unit tests**

`CalculateTwoColumnWidths` has three distinct branches (normal path, `leftWidth` floor at 16, and `rightWidth < minRight` recovery), and `GetGraphAreaDimensions` has two paths controlled by `isStatsHidden`. Neither has a test file. Edge inputs — e.g. `modalWidth` smaller than `preferredLeft + minRight + horizontalPadding` — can quietly return widths that sum beyond `modalWidth`, relying on callers to fall back to compact mode. Per the team's testing rule, edge cases and integration boundaries should have explicit coverage.

**Rule Used:** What: All code changes must include tests for edge... ([source](https://app.greptile.com/review/custom-context?memory=2b22782d-3452-4d55-b059-e631b2540ce8))

How can I resolve this? If you propose a fix, please make it concise.

Reviews (4): Last reviewed commit: "refactor: reduce minimum settings window..." | Re-trigger Greptile

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 10, 2026

Binary Size Analysis

⚠️ Size Increased

Version Human Readable Raw Bytes
Main 18.97 MB 19894564
PR 18.98 MB 19898660
Difference 4.00 KB 4096

Comment thread internal/tui/view_category.go Outdated
Comment thread internal/tui/layout_helpers.go
Comment thread internal/tui/layout_helpers.go Outdated
@SuperCoolPencil SuperCoolPencil merged commit a2d94ce into main Apr 10, 2026
15 checks passed
@SuperCoolPencil SuperCoolPencil deleted the fix-tui-magic branch April 10, 2026 21:11
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