-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(fmt): add comma number formatter for progress display #25356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add CommaNumberFormatter to format numbers with thousand separators.
Update Progress.zig to use commaNumber formatter for byte counts,
replacing {Bi:.2} format with comma-separated numbers for better
readability (e.g., 1,234,567 instead of 1.23M).
WalkthroughAdds a comma-separated integer formatter and updates the bytes progress display to use that formatter, changing byte-count rendering while leaving control flow and non-bytes branches unchanged. (≤50 words) Changes
Possibly related PRs
Suggested reviewers
Pre-merge checks✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (3)src/**/*.{cpp,zig}📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Files:
src/**/*.zig📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Files:
**/*.zig📄 CodeRabbit inference engine (.cursor/rules/zig-javascriptcore-classes.mdc)
Files:
🧠 Learnings (2)📚 Learning: 2025-10-24T10:43:09.398ZApplied to files:
📚 Learning: 2025-09-02T19:17:26.376ZApplied to files:
🔇 Additional comments (1)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
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 (2)
src/Progress.zig(1 hunks)src/fmt.zig(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/**/*.{cpp,zig}
📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
src/**/*.{cpp,zig}: Usebun bdorbun run build:debugto build debug versions for C++ and Zig source files; creates debug build at./build/debug/bun-debug
Run tests usingbun bd test <test-file>with the debug build; never usebun testdirectly as it will not include your changes
Execute files usingbun bd <file> <...args>; never usebun <file>directly as it will not include your changes
Enable debug logs for specific scopes usingBUN_DEBUG_$(SCOPE)=1environment variable
Code generation happens automatically as part of the build process; no manual code generation commands are required
Files:
src/Progress.zigsrc/fmt.zig
src/**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Use
bun.Output.scoped(.${SCOPE}, .hidden)for creating debug logs in Zig codeImplement core functionality in Zig, typically in its own directory in
src/
src/**/*.zig: Private fields in Zig are fully supported using the#prefix:struct { #foo: u32 };
Use decl literals in Zig for declaration initialization:const decl: Decl = .{ .binding = 0, .value = 0 };
Prefer@importat the bottom of the file (auto formatter will move them automatically)Be careful with memory management in Zig code - use defer for cleanup with allocators
Files:
src/Progress.zigsrc/fmt.zig
**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/zig-javascriptcore-classes.mdc)
**/*.zig: Expose generated bindings in Zig structs usingpub const js = JSC.Codegen.JS<ClassName>with trait conversion methods:toJS,fromJS, andfromJSDirect
Use consistent parameter nameglobalObjectinstead ofctxin Zig constructor and method implementations
Usebun.JSError!JSValuereturn type for Zig methods and constructors to enable proper error handling and exception propagation
Implement resource cleanup usingdeinit()method that releases resources, followed byfinalize()called by the GC that invokesdeinit()and frees the pointer
UseJSC.markBinding(@src())in finalize methods for debugging purposes before callingdeinit()
For methods returning cached properties in Zig, declare external C++ functions usingextern fnandcallconv(JSC.conv)calling convention
Implement getter functions with naming patternget<PropertyName>in Zig that acceptthisandglobalObjectparameters and returnJSC.JSValue
Access JavaScript CallFrame arguments usingcallFrame.argument(i), check argument count withcallFrame.argumentCount(), and getthiswithcallFrame.thisValue()
For reference-counted objects, use.deref()in finalize instead ofdestroy()to release references to other JS objects
Files:
src/Progress.zigsrc/fmt.zig
🔇 Additional comments (1)
src/fmt.zig (1)
1484-1518: LGTM! The comma number formatter implementation is correct and efficient.The logic correctly handles:
- Zero case with early return
- Buffer sizing (32 bytes is sufficient for max usize with commas)
- First group calculation ensuring 1-3 leading digits
- Loop that safely processes remaining digits in groups of 3
The mathematical guarantee that
(len - remaining)is always divisible by 3 ensures the loop never overruns the buffer.
Consolidate multiple bufWrite calls into single calls for byte unit progress display. This makes the code more concise and easier to read without changing functionality.
Add CommaNumberFormatter to format numbers with thousand separators. Update Progress.zig to use commaNumber formatter for byte counts, replacing {Bi:.2} format with comma-separated numbers for better readability (e.g., 1,234,567 instead of 1.23M).
What does this PR do?
This PR adds a new
CommaNumberFormattertosrc/fmt.zigthat formats numbers with thousand separators (commas) for improved readability. The formatter is then integrated intosrc/Progress.zigto display byte counts in a more human-readable format.Changes:
CommaNumberFormatterstruct andcommaNumber()function insrc/fmt.zigProgress.zigto usecommaNumberformatter for byte count displays instead of the{Bi:.2}format1,234,567instead of1.23M)This change improves the readability of large numbers in progress output, making it easier to understand the exact byte counts at a glance.
How did you verify your code works?
Created standalone test file: Created
test_comma_number.zigwith comprehensive test cases covering:zig test test_comma_number.zigTest cases verified:
0→"0"123→"123"(no comma needed)1234→"1,234"1234567→"1,234,567"1234567890→"1,234,567,890"Integration testing: The formatter is used in
Progress.zigfor displaying byte counts in progress indicators, replacing the previous{Bi:.2}format with comma-separated numbers.