charmbracelet / charmbracelet/bubbles

BUG [Help Model]: Configured width is not respected in edge-case

Open
#1,038 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
8.9k
Forks
457
Avg merge
1d 18h
Merged PRs (30d)
5

Description

**Describe the bug**

The `Help` model has a configurable `width` parameter.

The configured `width` is applied when calling the `ShortHelpView` or `FullHelpView` methods on `Help`.

Outside of the herein described edge-case, the `len` of the returned string will be equal to or less than the configured width. However, for both methods, there is an edge-case, resulting in the full string being returned untruncated, with a `len` that exceeds the configured `width`.

This occurs when the leading subset of distinct help items (items in `ShortHelpView` and columns in `FullHelpview`), fit within the configured `width` with a margin of 0-2 (and `width` > 0). In this case, the `shouldAddItem` helper function will not prevent the addition of new items, instead allowing each item to be added to the final string, exceeding the configured `width`. The margin mentioned assumes the configured `Help.Ellipsis` to be of `len==1`: the edge-case margin is equal to [0 - `len(Help.Ellipsis) + 1`].

This might duplicate another [bug](https://github.com/charmbracelet/bubbles/issues/461) that was reported some time ago.

I have prepared a [PR](https://github.com/charmbracelet/bubbles/pull/1032) that fixes the issue and describes more technical detail.

**Setup**

- **OS**: arch Linux x86_64 (kernel 7.1.8-arch1-3)
- **Shell**: fish 4.8.1
- **Terminal Emulator**: ghostty 1.3.1-arch2
- **Terminal Multiplexer**: tmux 3.7c
- **Locale**: en_GB.UTF-8

**To Reproduce**

Steps to reproduce the behavior:
1. Clone to [my fork with fix](https://github.com/wolfwfr/bubbles/tree/fix/help-truncation)
2. Copy `./help/testdata/*` & `./help/help_test.go` into original source-code
3. Execute tests and observe edge-case failure

**Source Code**

See the `Help` model [src](https://github.com/charmbracelet/bubbles/blob/main/help/help.go)

**Expected behavior**

When `width` is configured, one would ideally be able to expect that it is respected in subsequent model method outputs.

**Screenshots**

SHORT HELP VIEW

**BUG**
Image

**FIX**
Image

FULL HELP VIEW

**BUG**
Image

**FIX**
Image

Contributor guide

Open the contributing guide

Research direction

Start with help/help.go, focusing on Help.ShortHelpView, Help.FullHelpView, and the shouldAddItem helper. Review the tests and fixtures in help/help_test.go and help/testdata, including the cases described in PR #1032. Done means both views never exceed a configured positive width, including the documented edge case, with the relevant tests passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.