Skip to content

feat: Add ui.Toast() pattern for status notifications - #1794

Merged
Andriy Knysh (aknysh) merged 9 commits into
mainfrom
osterman/extract-toast-pattern
Nov 15, 2025
Merged

Andriy Knysh (aknysh) merged 9 commits into
mainfrom
osterman/extract-toast-pattern

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Nov 15, 2025 •

Copy link
Copy Markdown
Member

what

  • Add new ui.Toast() and ui.Toastf() functions for flexible toast-style status notifications
  • Extract toast functionality from the larger toolchain PR (Support Atmos Toolchain for 3rd Party Tools #1686) for independent review and merge
  • Update documentation to show Toast pattern as the primary approach for status notifications

why

  • The toolchain PR (Support Atmos Toolchain for 3rd Party Tools #1686) is large and complex - extracting independent features allows faster review and merge
  • Toast pattern provides a unified, flexible approach for all user-facing status messages
  • Custom icon support enables better visual communication without creating new wrapper functions
  • Improves code maintainability by establishing a clear pattern for status notifications

Implementation Details

New Functions:

// Primary toast pattern with custom icons
ui.Toast("📦", "Using latest version: 1.2.3")
ui.Toastf("🔧", "Tool %s is not installed", toolName)

// Existing convenience wrappers (now documented as Toast wrappers)
ui.Success("Done!")      // ✓ Done! (green)
ui.Error("Failed!")      // ✗ Failed! (red)
ui.Warning("Deprecated") // ⚠ Deprecated (yellow)
ui.Info("Processing...")  // ℹ Processing... (cyan)

Benefits:

  • ✅ Consistent pattern for all toast notifications
  • ✅ Flexible icon support (custom emojis or themed icons)
  • ✅ Automatic channel routing (stderr for UI)
  • ✅ Automatic secret masking via I/O layer
  • ✅ Zero breaking changes - all existing functions work as before

Documentation Updates:

  • Updated docs/io-and-ui-output.md with Toast API reference
  • Updated docs/prd/io-handling-strategy.md with Toast pattern examples
  • Enhanced comments in pkg/ui/formatter.go to clarify Toast pattern

Testing

  • ✅ All existing tests pass
  • ✅ Builds successfully
  • ✅ Linter checks pass
  • ✅ No breaking changes to existing API

references

Summary by CodeRabbit

  • New Features

    • Added toast-style notifications with icon support, multiline toasts, and consistent icon+text formatting.
    • Introduced convenience functions for success, error, warning, and info messages with formatting variants.
  • Documentation

    • Updated UI API docs with toast examples and a new Plain UI Text section (Write/Writef/Writeln examples).
  • Tests

    • Added comprehensive tests covering toast outputs, multiline/unicode handling, and formatting variants.

Introduce a new ui.Toast() and ui.Toastf() pattern for flexible toast-style
status notifications with custom icons, providing a unified approach for all
user-facing messages.

New API:
- ui.Toast(icon, message) - Toast with custom icon
- ui.Toastf(icon, format, ...args) - Formatted toast with custom icon
- Existing ui.Success(), ui.Error(), etc. now documented as convenience
  wrappers around the Toast pattern

Documentation:
- Updated docs/prd/io-handling-strategy.md with Toast pattern examples
- Updated docs/io-and-ui-output.md API reference with Toast functions
- Added comprehensive usage examples and guidelines

Implementation:
- Added ui.Toast() and ui.Toastf() to pkg/ui/formatter.go
- Updated existing convenience functions with improved comments
- All toast notifications route through stderr (UI channel)
- Automatic secret masking and TTY detection

Benefits:
- Consistent pattern for all toast notifications
- Flexible icon support (custom emojis or themed icons)
- Automatic channel routing (stderr for UI)
- Automatic secret masking
- Cleaner, more maintainable code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions Bot added the size/m Medium size PR label Nov 15, 2025
@coderabbitai

coderabbitai Bot commented Nov 15, 2025 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

Erik Osterman (Cloud Posse) (@osterman) has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 4 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d294741 and fe265c1.

📒 Files selected for processing (1)
  • pkg/ui/formatter_test.go (2 hunks)
📝 Walkthrough

Walkthrough

Adds toast-style UI notifications to the UI package: new Toast/Toastf APIs, convenience status wrappers (Success/Error/Warning/Info variants), multiline and Unicode-aware formatting, tests, and docs; integrates via the global terminal/formatter write path.

Changes

Cohort / File(s) Summary
Documentation
docs/io-and-ui-output.md, docs/prd/io-handling-strategy.md
Adds UI Toast API docs and examples; documents Plain UI Text; lists new public functions and usage examples for toast-style stderr output
UI Formatter Implementation
pkg/ui/formatter.go
Adds Toast(icon, message) error and Toastf(icon, format, a...) error; centralizes icon+text formatting, multiline indentation, ANSI-stripping/width handling, and routes Success/Error/Warning/Info through toast flow; initializes global formatter/terminal guards
Interfaces
pkg/ui/interfaces.go
Extends Formatter interface with Toast(icon, message string) string and Toastf(icon, format string, a ...interface{}) string
Formatter Tests
pkg/ui/formatter_test.go
Large new test suite for toast behaviors: single/multiline, Unicode/width handling, ANSI stripping, error/uninitialized cases, and convenience wrappers
Output Tests (globals handling)
pkg/ui/output_test.go
Expands not-initialized test to save/restore additional globals (globalTerminal, Format) alongside the formatter

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Client code
    participant UIpkg as ui package
    participant Terminal as globalTerminal (io.Writer)
    participant Formatter as Formatter instance

    Note over Caller,UIpkg: New public APIs: Toast / Toastf / Successf / Errorf / Warning / Info variants

    Caller->>UIpkg: ui.Toast(icon, message)
    UIpkg->>Formatter: Format.Toast(icon, message)    %% formatting logic: icon + multiline handling
    Formatter-->>UIpkg: formatted string
    UIpkg->>Terminal: write(formatted string)          %% central write path (stderr)
    Terminal-->>UIpkg: write result / error
    UIpkg-->>Caller: return error?

    opt Toastf path
      Caller->>UIpkg: ui.Toastf(icon, fmt, args...)
      UIpkg->>Formatter: Format.Toastf(icon, fmt, args...)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Pay extra attention to pkg/ui/formatter.go: multiline indentation, Unicode/ANSI width calculations, and global terminal/formatter initialization guards.
  • Review pkg/ui/formatter_test.go for representative coverage and ensure tests accurately reflect intended ANSI/width behavior.
  • Confirm pkg/ui/interfaces.go additions remain compatible with existing implementations and the new formatter methods are correctly wired.
  • Check docs (docs/*) for exact API signatures matching the implementation.

Suggested labels

minor

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.63% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main feature: adding a ui.Toast() pattern for status notifications, which aligns with the PR's core purpose of introducing Toast and Toastf functions.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Nov 15, 2025 •

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

Claude (via Conductor) and others added 2 commits November 14, 2025 22:47
Add support for multiline toast messages that automatically split on newlines
and indent continuation lines to align with the first line text.

Implementation:
- Added formatToast() method to handle single and multiline messages
- Calculates proper indentation based on icon rune count
- Preserves empty lines in multiline messages
- Handles unicode emojis correctly using rune count
- Added iconMessageFormat constant to avoid string literal duplication

Testing:
- Added comprehensive tests for single-line toasts
- Added tests for multiline toasts with various icons
- Added tests for unicode width handling
- Added integration tests for Toast() and Toastf()
- All existing tests pass

Documentation:
- Updated docs/io-and-ui-output.md with multiline examples
- Updated docs/prd/io-handling-strategy.md with usage patterns
- Added visual output examples showing indentation

Example usage:
  ui.Toast("✓", "Installation complete\nVersion: 1.2.3\nLocation: /usr/local/bin")
  Output:
  ✓ Installation complete
    Version: 1.2.3
    Location: /usr/local/bin

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add extensive test coverage for multiline toast functionality including:

Edge Cases:
- Empty messages
- Messages with only newlines
- Messages starting/ending with newlines
- Multiple consecutive newlines
- Long multiline messages (5+ lines)
- Special characters (tabs, spaces)
- Unicode characters in messages

Real-World Examples:
- Installation success with details
- Error messages with context
- Progress updates with statistics
- Configuration summaries

Integration Tests:
- Multiline support with convenience functions (Success, Error, Warning, Info)
- Formatted multiline messages with Toastf
- Multiple format argument types (string, int, float, bool)

Error Handling:
- Toast/Toastf behavior when formatter not initialized

Test Results:
- All 10 new test functions pass
- 50+ individual test cases added
- UI package coverage: 92.2%
- No regressions in existing tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions Bot added size/l Large size PR and removed size/m Medium size PR labels Nov 15, 2025
@osterman Erik Osterman (Cloud Posse) (osterman) added the no-release Do not create a new release (wait for additional code changes) label Nov 15, 2025
Claude (via Conductor) and others added 2 commits November 14, 2025 23:09
… Warning, Info)

Enable all convenience functions to support multiline messages with colored icons:

Implementation:
- Refactored Success/Error/Warning/Info to use formatToast with colored icons
- Added stripANSI() helper to calculate proper indentation with colored icons
- ANSI color codes only applied to icons, not text (per design)
- All *f variants (Successf, Errorf, etc.) delegate to base functions

Key Changes:
- Success/Error/Warning/Info now support multiline via formatToast
- Colored icons properly handled in multiline layout
- Indentation calculated on plain icon width (ANSI codes stripped)
- Maintains backward compatibility with single-line messages

Testing:
- Added TestFormatter_ConvenienceFunctions_Multiline (4 test cases)
- Added TestFormatter_ANSIStripping (6 test cases for ANSI handling)
- Added TestFormatter_Successf_Multiline
- Added TestFormatter_Errorf_Multiline
- Added TestFormatter_Warningf_Multiline
- Added TestFormatter_Infof_Multiline
- All tests pass, coverage increased to 93.4%

Example:
  ui.Success("Done\nAll tasks completed")
  // With color:
  // \x1b[32m✓\x1b[0m Done
  //   All tasks completed

  ui.Errorf("Failed: %s\nReason: %s", "deploy", "timeout")
  // With color:
  // \x1b[31m✗\x1b[0m Failed: deploy
  //   Reason: timeout

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Replace custom stripANSI() with lipgloss.Width() for proper ANSI and emoji width calculation
- Remove redundant SupportsColor() checks (styles handle color degradation automatically)
- Simplify convenience functions (Success, Error, Warning, Info) to always use styled icons
- Update test expectations for accurate emoji width (2 cells + 1 space = 3 total indent)
- Add test for lipgloss.Width() behavior with ANSI codes and emojis

Benefits:
- More accurate width calculation for multi-cell characters (emojis, CJK)
- Better integration with Charmbracelet ecosystem
- Less code to maintain
- Automatic color degradation through lipgloss styles

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
pkg/ui/formatter_test.go (3)

715-779: Unicode width test uses rune count as proxy for visual width

You’re using len([]rune(icon)) to drive indent expectations, which is a reasonable approximation, but will misalign for multi-codepoint emojis or east-asian width differences. If you ever need pixel-perfect alignment across terminals, consider runewidth or similar; otherwise this is fine for now.


781-857: Global formatter setup in integration tests could be safer

TestToast_Integration and TestToastf_Integration reassign globalFormatter without taking formatterMu, while production access is guarded by that mutex. It works in practice, but can show as a race under go test -race. If you care about race-free tests, consider wrapping the reassignment with the same mutex or exposing a small test-only helper to set/reset the global formatter.


1000-1091: Consider asserting more than “no error” in high-level toast tests

TestToast_WithConvenienceFunctions and TestToastf_FormattingWithMultiline only assert that calls succeed. Given you already have strong lower-level tests, this is acceptable; if you ever refactor, you might capture terminal output and assert icon + indentation behavior end-to-end to catch wiring mistakes.

pkg/ui/formatter.go (3)

17-24: Unused tab constant

tab is defined but not used anywhere in this file. If there’s no near-term plan to use it for formatting, consider dropping it to keep the constants focused.


341-408: formatToast/stripANSI handle multiline and colored icons well, with minor caveats

The toast formatter splits on \n, preserves empty lines, and aligns continuation lines based on the (ANSI-stripped) icon rune count, which is a solid, predictable rule. stripANSI’s simple ESC […m handling is enough for typical SGR codes from lipgloss; if you ever introduce other escape sequences or need true terminal cell width, you may want to extend this logic or delegate to a dedicated width library.


410-461: Success/Warning/Error/Info now behave as toast-style helpers

These methods now build a (possibly colored) icon, pass the full message through formatToast, trim the trailing newline, and then add a single newline at write time. That gives you consistent toast-style multiline behavior for all four helpers. One behavioral detail: only the icon is styled when color is available; if you ever decide you prefer the whole line colored, you could instead render icon + text via the lipgloss style in one go.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ca9898c and 3daa4ba.

📒 Files selected for processing (4)
  • docs/io-and-ui-output.md (2 hunks)
  • docs/prd/io-handling-strategy.md (2 hunks)
  • pkg/ui/formatter.go (5 hunks)
  • pkg/ui/formatter_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: toolchain/list.go:39-42
Timestamp: 2025-09-13T18:06:07.674Z
Learning: In the cloudposse/atmos repository, for UI messages in the toolchain package, use utils.PrintfMessageToTUI instead of log.Error or fmt.Fprintln(os.Stderr, ...). Import pkg/utils with alias "u" to follow the established pattern.
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
📚 Learning: 2025-09-13T18:06:07.674Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: toolchain/list.go:39-42
Timestamp: 2025-09-13T18:06:07.674Z
Learning: In the cloudposse/atmos repository, for UI messages in the toolchain package, use utils.PrintfMessageToTUI instead of log.Error or fmt.Fprintln(os.Stderr, ...). Import pkg/utils with alias "u" to follow the established pattern.

Applied to files:

  • pkg/ui/formatter.go
  • docs/io-and-ui-output.md
  • docs/prd/io-handling-strategy.md
📚 Learning: 2025-02-03T06:00:11.419Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 959
File: cmd/describe_config.go:20-20
Timestamp: 2025-02-03T06:00:11.419Z
Learning: Commands should use `PrintErrorMarkdownAndExit` with empty title and suggestion (`"", err, ""`) for general error handling. Specific titles like "Invalid Usage" or "File Not Found" should only be used for validation or specific error scenarios.

Applied to files:

  • pkg/ui/formatter.go
  • docs/prd/io-handling-strategy.md
📚 Learning: 2025-10-22T14:55:44.014Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1695
File: pkg/auth/manager.go:169-171
Timestamp: 2025-10-22T14:55:44.014Z
Learning: Go 1.20+ supports multiple %w verbs in fmt.Errorf, which returns an error implementing Unwrap() []error. This is valid and does not panic. Atmos uses Go 1.24.8 and configures errorlint with errorf-multi: true to validate this pattern.

Applied to files:

  • pkg/ui/formatter_test.go
📚 Learning: 2024-11-10T19:28:17.365Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 768
File: internal/exec/vendor_utils.go:0-0
Timestamp: 2024-11-10T19:28:17.365Z
Learning: When TTY is not supported, log the downgrade message at the Warn level using `u.LogWarning(cliConfig, ...)` instead of `fmt.Println`.

Applied to files:

  • docs/prd/io-handling-strategy.md
🧬 Code graph analysis (2)
pkg/ui/formatter.go (1)
pkg/data/data.go (1)
  • Write (62-66)
pkg/ui/formatter_test.go (2)
pkg/terminal/terminal.go (2)
  • ColorNone (87-87)
  • ColorTrue (90-90)
pkg/ui/formatter.go (12)
  • NewFormatter (302-311)
  • Errorf (204-212)
  • InitFormatter (35-52)
  • Toast (81-88)
  • Toastf (104-107)
  • Error (191-199)
  • Success (165-173)
  • Warning (217-225)
  • Info (243-251)
  • Successf (178-186)
  • Warningf (230-238)
  • Infof (256-264)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Build (linux)
  • GitHub Check: Build (windows)
  • GitHub Check: Build (macos)
  • GitHub Check: Review Dependency Licenses
  • GitHub Check: autofix
  • GitHub Check: Lint (golangci)
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (10)
docs/io-and-ui-output.md (1)

91-132: Toast and Plain UI Text docs align well with the API

Examples match the Toast/Toastf and Write/Writef/Writeln semantics, including multiline indentation and stderr routing, so this section looks ready to ship.

pkg/ui/formatter_test.go (6)

618-713: formatToast single/multiline tests are thorough

Nice coverage of single-line, multiline, emoji icons, and blank-line preservation; expectations line up with the formatter implementation and should guard against regressions in core toast layout.


859-998: Edge-case and “real world” toast tests add valuable confidence

The edge-case suite (empty messages, leading/trailing/consecutive newlines, tabs, unicode) plus the RealWorldExamples block give very solid coverage of the formatting contract for toasts. This looks good.


1093-1116: NotInitialized behavior for Toast/Toastf is well covered

The explicit “formatter not initialized” checks for Toast and Toastf match the getFormatter error path and should prevent silent failures in early-init scenarios.


1118-1196: Multiline convenience function tests look good

The multiline tests for Success, Error, Warning, and Info validate icon presence and indentation in both color and no-color profiles, which is exactly what the new toast-backed semantics rely on.


1198-1248: ANSI stripping helper is well exercised

TestFormatter_ANSIStripping covers plain text, several SGR combinations, and icon cases, which is sufficient for using stripANSI as a width helper for colored icons.


1250-1332: *Multiline f helpers verify formatted content correctly

The multiline Successf/Errorf/Warningf/Infof tests confirm that formatted arguments flow into the expected lines, which nicely ties together formatToast and the formatted wrappers.

pkg/ui/formatter.go (2)

67-107: Toast/Toastf wiring is clean and matches the documented flow

Toast and Toastf correctly go through getFormatter and terminal.Write, so they respect the I/O context and masking behavior, while keeping the API surface simple for callers.


325-339: Shared icon/text format keeps StatusMessage consistent

Using iconMessageFormat in StatusMessage centralizes the {icon} {text} contract and keeps colored vs non-colored variants aligned. This is a nice small refactor.

docs/prd/io-handling-strategy.md (1)

308-323: PRD updates for Toasts match the implemented UI API

The documented Toast/Toastf signatures, the convenience wrapper list, and the new usage examples all align with the formatter implementation and test behavior (icons, stderr UI channel, multiline indentation). This keeps the conceptual model in sync with the code.

Also applies to: 419-446

coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 15, 2025
- UI functions now call ui.Format methods, then ui.Write() for output
- Formatter has ZERO I/O responsibilities - only formats and returns strings
- Added Toast() and Toastf() to Formatter interface for public API
- Package-level functions follow pattern: format → write (not format+write)
- Proper separation: formatter formats, terminal writes, UI orchestrates

This follows 'option 2' pattern: ui.Success() → ui.Format.Success() → ui.Write()

Benefits:
- Clear separation of concerns (formatting vs I/O)
- Formatter is pure (no side effects, testable without mocking I/O)
- Consistent API pattern across all UI functions
- Users can call Format methods directly for formatted strings without writing
@github-actions github-actions Bot added size/xl Extra large size PR and removed size/l Large size PR labels Nov 15, 2025
@mergify

mergify Bot commented Nov 15, 2025

Copy link
Copy Markdown
Contributor

Warning

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues.
Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

Claude (via Conductor) and others added 2 commits November 14, 2025 23:26
- Set Format = nil in TestPackageFunctions_NotInitialized
- Now tests all nil check paths for Success, Error, Warning, Info functions
- Coverage increased from 86.6% to 91.7%

All toast and convenience functions now have 100% test coverage.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
pkg/ui/interfaces.go (1)

26-30: Clarify Toast return semantics in the interface doc

formatter.Toast/Toastf currently return strings that include a trailing newline (see implementation), while the comments here only mention {icon} {message}. I'd tighten the doc to state whether callers should expect a newline, so alternative implementations and callers can rely on that contract.

Also applies to: 36-44

pkg/ui/output_test.go (1)

542-560: Include Toast/Toastf in the “not initialized” package-level tests (or narrow the comment)

The comment says this table covers “all package-level functions”, but Toast and Toastf are missing even though they also guard on Format/global state. Either add entries for them here or reword the comment so it doesn't drift as new package-level helpers are added.

Also applies to: 564-594

pkg/ui/formatter_test.go (1)

783-859: Avoid shadowing global formatter with unused mock terminals

In TestToast_Integration, TestToastf_Integration, TestToast_WithConvenienceFunctions, and TestToastf_FormattingWithMultiline, you:

  • Call InitFormatter(ioCtx) (which sets globalFormatter, Format, globalTerminal), then
  • Create a createMockTerminal(...) and assign globalFormatter = NewFormatter(ioCtx, term).(*formatter).

However, Toast/Toastf and the convenience wrappers only use Format + Write(globalTerminal, ...). The mock term is never wired into either Format or globalTerminal, and the overridden globalFormatter is unused in these tests. This makes the setup misleading and leaves globalFormatter diverging from Format.

I’d simplify these tests by dropping the custom globalFormatter assignment (and the unused term in those tests), letting InitFormatter own the globals. If you ever do need a mock terminal in the global path, wire it through both globalTerminal and Format, and save/restore the previous globals in a defer.

Also applies to: 1002-1093

pkg/ui/formatter.go (1)

316-331: Update StatusMessage comment now that Success/Warning/Error/Info use Toast

StatusMessage is now a lower-level formatter, while Success/Warning/Error/Info route through Toast with colored icons. The comment still calls it the “foundational method used by Success, Error, Warning, and Info”, which can confuse future readers.

I’d tweak the comment to something like “used by lower-level call sites; higher-level status helpers use Toast for multiline support” to reflect the current design.

Also applies to: 385-425

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3daa4ba and d294741.

📒 Files selected for processing (4)
  • pkg/ui/formatter.go (6 hunks)
  • pkg/ui/formatter_test.go (2 hunks)
  • pkg/ui/interfaces.go (1 hunks)
  • pkg/ui/output_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: toolchain/list.go:39-42
Timestamp: 2025-09-13T18:06:07.674Z
Learning: In the cloudposse/atmos repository, for UI messages in the toolchain package, use utils.PrintfMessageToTUI instead of log.Error or fmt.Fprintln(os.Stderr, ...). Import pkg/utils with alias "u" to follow the established pattern.
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
📚 Learning: 2025-09-13T18:06:07.674Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: toolchain/list.go:39-42
Timestamp: 2025-09-13T18:06:07.674Z
Learning: In the cloudposse/atmos repository, for UI messages in the toolchain package, use utils.PrintfMessageToTUI instead of log.Error or fmt.Fprintln(os.Stderr, ...). Import pkg/utils with alias "u" to follow the established pattern.

Applied to files:

  • pkg/ui/formatter.go
📚 Learning: 2025-06-07T19:27:40.807Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1266
File: pkg/utils/highlight_utils.go:0-0
Timestamp: 2025-06-07T19:27:40.807Z
Learning: In pkg/utils/highlight_utils.go, the global variable `isTermPresent` that caches terminal detection at package initialization is an intentional design choice and should not be changed to per-call detection.

Applied to files:

  • pkg/ui/formatter.go
  • pkg/ui/output_test.go
📚 Learning: 2025-02-21T20:56:05.539Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1077
File: pkg/downloader/custom_github_detector.go:0-0
Timestamp: 2025-02-21T20:56:05.539Z
Learning: The `github.com/charmbracelet/log` package should be imported with the alias `log` according to the project's import alias configuration.

Applied to files:

  • pkg/ui/formatter_test.go
📚 Learning: 2025-02-21T20:56:20.761Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1077
File: pkg/downloader/custom_github_detector_test.go:0-0
Timestamp: 2025-02-21T20:56:20.761Z
Learning: The `github.com/charmbracelet/log` package should be imported with the alias `log`, not `clog`.

Applied to files:

  • pkg/ui/formatter_test.go
📚 Learning: 2025-10-22T14:55:44.014Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1695
File: pkg/auth/manager.go:169-171
Timestamp: 2025-10-22T14:55:44.014Z
Learning: Go 1.20+ supports multiple %w verbs in fmt.Errorf, which returns an error implementing Unwrap() []error. This is valid and does not panic. Atmos uses Go 1.24.8 and configures errorlint with errorf-multi: true to validate this pattern.

Applied to files:

  • pkg/ui/formatter_test.go
🧬 Code graph analysis (4)
pkg/ui/formatter.go (3)
pkg/io/interfaces.go (1)
  • Context (21-42)
pkg/terminal/terminal.go (3)
  • Terminal (44-72)
  • New (145-185)
  • WithIO (192-196)
errors/errors.go (1)
  • ErrUIFormatterNotInitialized (31-31)
pkg/ui/formatter_test.go (2)
pkg/terminal/terminal.go (2)
  • ColorNone (87-87)
  • ColorTrue (90-90)
pkg/ui/formatter.go (13)
  • NewFormatter (293-302)
  • Toast (83-89)
  • Errorf (202-208)
  • InitFormatter (36-54)
  • Toastf (105-111)
  • Error (191-197)
  • Success (169-175)
  • Warning (213-219)
  • Info (235-241)
  • Format (282-282)
  • Successf (180-186)
  • Warningf (224-230)
  • Infof (246-252)
pkg/ui/interfaces.go (1)
pkg/ui/formatter.go (2)
  • Toast (83-89)
  • Toastf (105-111)
pkg/ui/output_test.go (1)
pkg/ui/formatter.go (1)
  • Format (282-282)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Build (windows)
  • GitHub Check: Build (linux)
  • GitHub Check: Build (macos)
  • GitHub Check: autofix
  • GitHub Check: Analyze (go)
  • GitHub Check: Review Dependency Licenses
  • GitHub Check: Lint (golangci)
  • GitHub Check: Summary
🔇 Additional comments (3)
pkg/ui/formatter_test.go (1)

620-715: Toast formatting test matrix looks solid

The new Toast-related tests (single-line, multiline, edge cases, real-world examples, multiline *f variants, and lipgloss width checks) cover the important behaviors: newline handling, indentation, emoji width, ANSI codes, and semantic wrappers (Success/Error/Warning/Info). Once the Unicode-width expectation above is fixed, this suite should give good confidence in the new Toast path.

Also applies to: 861-1001, 1123-1334

pkg/ui/formatter.go (2)

69-111: Toast/Toastf wiring and Write guard look consistent

The new package-level Toast/Toastf helpers delegating to Format.Toast* and then Write, combined with the Write guard on globalTerminal, line up with the stated flow (ui.Toast → Format.Toast → Write → terminal.Write → io.Write). The additional not-initialized checks are straightforward and match the tests.

Also applies to: 166-252, 254-277


332-383: Toast implementation matches the documented multiline and emoji behavior

formatter.Toast’s split-on-\n, lipgloss-based iconWidth, and iconWidth+1 indent give you the expected alignment for plain icons and multi-cell emojis, and the trailing newline keeps the contract simple. This aligns well with the test expectations and the docs in the comments.

Comment thread pkg/ui/formatter_test.go Resolved
@codecov

codecov Bot commented Nov 15, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.67%. Comparing base (98e49cc) to head (fe265c1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1794      +/-   ##
==========================================
+ Coverage   70.62%   70.67%   +0.04%     
==========================================
  Files         451      451              
  Lines       42367    42397      +30     
==========================================
+ Hits        29923    29963      +40     
+ Misses       9913     9907       -6     
+ Partials     2531     2527       -4     
Flag Coverage Δ
unittests 70.67% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/ui/formatter.go 90.04% <100.00%> (+1.16%) ⬆️

... and 3 files with indirect coverage changes

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

- Updated TestFormatter_FormatToast_UnicodeWidth to use lipgloss.Width()
- Previously used len([]rune(icon)) which doesn't match production width calculation
- Now test correctly validates wide emoji handling (📦 = 2 cells, not 1 rune)

This ensures test width model matches the formatter's actual behavior.
@aknysh
Andriy Knysh (aknysh) merged commit 8125309 into main Nov 15, 2025
@aknysh
Andriy Knysh (aknysh) deleted the osterman/extract-toast-pattern branch November 15, 2025 07:09
@github-actions

Copy link
Copy Markdown

These changes were released in v1.199.0-rc.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-release Do not create a new release (wait for additional code changes) size/xl Extra large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants