Skip to content

fix: add WithHardTabs/WithBackspace options and fix doc bugs#1722

Open
GautamKumarOffical wants to merge 3 commits into
charmbracelet:mainfrom
GautamKumarOffical:fix/add-hardtabs-option-and-doc-fixes
Open

fix: add WithHardTabs/WithBackspace options and fix doc bugs#1722
GautamKumarOffical wants to merge 3 commits into
charmbracelet:mainfrom
GautamKumarOffical:fix/add-hardtabs-option-and-doc-fixes

Conversation

@GautamKumarOffical

Copy link
Copy Markdown

Summary

This PR addresses issue #1635 and fixes several documentation bugs.

New WithHardTabs and WithBackspace options

The v2 cursor optimization in cursedRenderer auto-detects the terminal's TAB0 flag via termios and replaces runs of space cells with \t characters as a cursor-movement optimization. This silently corrupts application output that relies on precise space-based column alignment (see #1635).

Previously there was no way to disable this behavior. This PR adds:

  • tea.WithHardTabs(bool) — explicitly enable or disable hard tab optimization
  • tea.WithBackspace(bool) — explicitly enable or disable backspace optimization

When these options are not set, the auto-detection from termios continues to work as before. When they are set, the explicit value takes precedence.

Usage:

p := tea.NewProgram(model{}, tea.WithHardTabs(false))

Documentation fixes

  • InterruptMsg doc incorrectly said "signals the program should suspend" — changed to "interrupt"
  • ResumeMsg doc had a grammar error ("listen" → "listened")
  • BackgroundColorMsg example was missing return m, nil and referenced [Update.Init] instead of [Model.Init]
  • KeyboardEnhancements doc example used non-existent msg.ReportEventTypes field instead of msg.SupportsEventTypes() method
  • Removed duplicate KeyboardEnhancements doc comment

Testing

All existing tests pass. The changes are backward-compatible — no existing behavior changes unless WithHardTabs/WithBackspace are explicitly set.

Add WithHardTabs and WithBackspace ProgramOptions to allow users to
explicitly control cursor movement optimizations, addressing issue charmbracelet#1635
where the auto-detected hard-tab optimization breaks column alignment in
View() output.

Also fix several documentation bugs:
- InterruptMsg doc incorrectly says 'suspend' instead of 'interrupt'
- ResumeMsg doc has grammar error ('listen' instead of 'listened')
- BackgroundColorMsg example is missing return statement and has wrong
  [Update.Init] reference instead of [Model.Init]
- KeyboardEnhancements doc example uses non-existent msg.ReportEventTypes
  field instead of msg.SupportsEventTypes() method
- Remove duplicate KeyboardEnhancements doc comment

Signed-off-by: Gautam Kumar <gautamkumarofficial@users.noreply.github.com>
@GautamKumarOffical

Copy link
Copy Markdown
Author

Hi! This PR adds WithHardTabs/WithBackspace options and fixes several doc bugs. All checks pass. Happy to make any adjustments. Thanks!

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.92%. Comparing base (a23da80) to head (95d4ccf).

Files with missing lines Patch % Lines
options.go 0.00% 6 Missing ⚠️
tea.go 0.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1722      +/-   ##
==========================================
- Coverage   56.50%   55.92%   -0.58%     
==========================================
  Files          25       25              
  Lines        1315     1325      +10     
==========================================
- Hits          743      741       -2     
- Misses        482      491       +9     
- Partials       90       93       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Gautam Kumar added 2 commits June 18, 2026 07:57
Adds tests to improve code coverage for the new WithHardTabs and
WithBackspace options introduced in this PR.

Closes charmbracelet#1722
Check backspaceOverride instead of hardTabsOverride when testing
WithBackspace(false).

Signed-off-by: Gautam Kumar <gautamkumarofficial@users.noreply.github.com>
@GautamKumarOffical

Copy link
Copy Markdown
Author

Fixed a typo in the WithBackspace test — was checking hardTabsOverride instead of backspaceOverride. All tests pass now. The codecov report was from an earlier commit before the tests were added.

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