Skip to content

Dynamic Shortcut Helper Height Auto-Adaptation - #131

Merged
markusressel merged 2 commits into
mainfrom
feature/shortcut-helper-dynamic-size
Jun 21, 2026
Merged

Dynamic Shortcut Helper Height Auto-Adaptation#131
markusressel merged 2 commits into
mainfrom
feature/shortcut-helper-dynamic-size

Conversation

@markusressel

Copy link
Copy Markdown
Owner

This PR introduces dynamic height auto-adaptation for the TUI shortcut helper panel at the bottom of the interface. It ensures that all defined shortcuts are visible at all times, handling line wraps and terminal window resizing cleanly in a one-shot computation without clipping, entry splitting, or startup flickering.


Features & Implementation Details

1. Custom Word-Wrapping Height Math

  • Implemented a precise word-wrapping line counter (CalculateHeightForWidth) inside ShortcutMapComponent (shortcut_map_component.go) that operates on a slice of runes.
  • Simulates word boundary wrap locations to calculate the exact height required for the shortcut text block in terminal cells.

2. Unbreakable Shortcut Entries (NBSP & Dental Click separators)

  • To prevent keyboard key combos and action names from being split across line breaks (which looks messy and splits definition from label):
    • Spaces within each shortcut entry are replaced with Unicode Non-Breaking Spaces (\u00a0).
    • Vertical bars separating multiple key combos for a single action (e.g. ⭾|shift+⭾) are joined using the Unicode Latin Letter Dental Click (\u01c0 / ǀ), which renders identically to a vertical bar but is treated as an alphabetic character by the Unicode wrapping algorithm (UAX Bump github.com/spf13/viper from 1.17.0 to 1.18.0 #14).
    • Regular spaces are used exclusively between different entries, forcing wrap boundaries only at full shortcut entry units.

3. Flicker-Free Initial Sizing

  • Retrieves the console dimensions directly from the OS on startup using golang.org/x/term (term.GetSize(int(os.Stdout.Fd()))) as a fallback if the layout hasn't been drawn yet.
  • Resizes the shortcut map item in the parent Flex prior to the first draw loop, rendering the first frame perfectly with zero layout flickering.

4. Smooth Terminal Resize Support

  • Overrides SetDrawFunc on the underlying text view to monitor real-time dimension shifts during terminal window resizes.
  • If the layout width shifts and triggers wrapping adjustments, the parent Flex layout (mainPageLayout in main_page.go) is updated asynchronously using application.QueueUpdateDraw from a background goroutine, avoiding deadlocks or recursion during the draw loop.

Validation

  • Verified that all unit tests (go test ./...) compile and pass successfully.
  • Manually tested that layout is stable across different window sizes and scales instantly without incremental sizing steps.

- Calculate required height on-the-fly using a custom word-wrap algorithm.
- Support terminal resizing via a custom draw function that recalculates the height when the width changes.
- Avoid line splits inside individual shortcut entries by formatting space with non-breaking spaces (\u00a0) and separator vertical bar (|) with non-breaking dental clicks (\u01c0).
- Avoid first-frame flicker by querying terminal size using golang.org/x/term on startup.
@markusressel markusressel added the enhancement New feature or request label Jun 21, 2026
- Achieves 89% statement coverage for ShortcutMapComponent.
- Verifies NewShortcutMap initialization, SetEntries formatting, Clear behavior, and custom CalculateHeightForWidth wrapping computations.
@markusressel
markusressel merged commit 97abab5 into main Jun 21, 2026
8 checks passed
@markusressel
markusressel deleted the feature/shortcut-helper-dynamic-size branch June 21, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant