Repository navigation
feat: Add ui.Toast() pattern for status notifications - #1794
Conversation
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]>
|
Warning Rate limit exceededErik 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 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. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Suggested labels
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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. Comment |
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
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]>
… 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
There was a problem hiding this comment.
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 widthYou’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, considerrunewidthor similar; otherwise this is fine for now.
781-857: Global formatter setup in integration tests could be safer
TestToast_IntegrationandTestToastf_IntegrationreassignglobalFormatterwithout takingformatterMu, while production access is guarded by that mutex. It works in practice, but can show as a race undergo 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_WithConvenienceFunctionsandTestToastf_FormattingWithMultilineonly 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: Unusedtabconstant
tabis 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 caveatsThe 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[…mhandling 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 helpersThese 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 rendericon + textvia 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.
📒 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.godocs/io-and-ui-output.mddocs/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.godocs/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 APIExamples 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 thoroughNice 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 confidenceThe 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 coveredThe explicit “formatter not initialized” checks for Toast and Toastf match the
getFormattererror path and should prevent silent failures in early-init scenarios.
1118-1196: Multiline convenience function tests look goodThe multiline tests for
Success,Error,Warning, andInfovalidate 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_ANSIStrippingcovers plain text, several SGR combinations, and icon cases, which is sufficient for usingstripANSIas a width helper for colored icons.
1250-1332: *Multiline f helpers verify formatted content correctlyThe multiline
Successf/Errorf/Warningf/Infoftests confirm that formatted arguments flow into the expected lines, which nicely ties togetherformatToastand the formatted wrappers.pkg/ui/formatter.go (2)
67-107: Toast/Toastf wiring is clean and matches the documented flow
ToastandToastfcorrectly go throughgetFormatterandterminal.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 consistentUsing
iconMessageFormatinStatusMessagecentralizes 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 APIThe 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
- 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
|
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. |
- 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.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
pkg/ui/interfaces.go (1)
26-30: Clarify Toast return semantics in the interface doc
formatter.Toast/Toastfcurrently 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
ToastandToastfare missing even though they also guard onFormat/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 terminalsIn
TestToast_Integration,TestToastf_Integration,TestToast_WithConvenienceFunctions, andTestToastf_FormattingWithMultiline, you:
- Call
InitFormatter(ioCtx)(which setsglobalFormatter,Format,globalTerminal), then- Create a
createMockTerminal(...)and assignglobalFormatter = NewFormatter(ioCtx, term).(*formatter).However,
Toast/Toastfand the convenience wrappers only useFormat+Write(globalTerminal, ...). The mocktermis never wired into eitherFormatorglobalTerminal, and the overriddenglobalFormatteris unused in these tests. This makes the setup misleading and leavesglobalFormatterdiverging fromFormat.I’d simplify these tests by dropping the custom
globalFormatterassignment (and the unusedtermin those tests), lettingInitFormatterown the globals. If you ever do need a mock terminal in the global path, wire it through bothglobalTerminalandFormat, 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
StatusMessageis now a lower-level formatter, whileSuccess/Warning/Error/Inforoute 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.
📒 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.gopkg/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 solidThe 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 consistentThe new package-level
Toast/Toastfhelpers delegating toFormat.Toast*and thenWrite, combined with theWriteguard onglobalTerminal, 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-basediconWidth, andiconWidth+1indent 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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
- 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.
|
These changes were released in v1.199.0-rc.1. |
what
ui.Toast()andui.Toastf()functions for flexible toast-style status notificationswhy
Implementation Details
New Functions:
Benefits:
Documentation Updates:
docs/io-and-ui-output.mdwith Toast API referencedocs/prd/io-handling-strategy.mdwith Toast pattern examplespkg/ui/formatter.goto clarify Toast patternTesting
references
Summary by CodeRabbit
New Features
Documentation
Tests