Conversation
📝 WalkthroughWalkthroughAdds modern go:build directives to platform-gated files, promotes several terminal attribute flags to exported Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)parse.go (1)
🔇 Additional comments (8)
✏️ Tip: You can disable this entire section by setting 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 |
Previously, each rune was treated as occupying 1 column, causing incorrect cursor positioning for wide characters like CJK text. Changes: - Add go-runewidth dependency to calculate display width - Add AttrWide and AttrWideDummy flags for wide char tracking - Move cursor by actual character width (2 for wide chars) - Handle wide char wrapping at line end - Clear orphaned cells when overwriting partial wide chars
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
state.go (1)
292-300: Dimming by 50% may be too aggressive for faint text.The
dimColorfunction halves each RGB component to create a faint appearance. While this is simple and effective, dimming by 50% may make text too hard to read in some color schemes, especially for already-dark colors.Consider:
- Using a less aggressive dimming factor (e.g., 33% or 25% reduction) for better readability.
- Making the dimming factor configurable.
- Testing with various color combinations to ensure faint text remains legible.
That said, 50% dimming matches the reference image mentioned in the PR description, so this may be intentional.
Please verify that the 50% dimming matches the intended visual appearance from the reference image and provides acceptable readability across different color schemes.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
go.modparse.gostate.go
🧰 Additional context used
🧬 Code graph analysis (2)
state.go (1)
color.go (3)
Color(35-35)DefaultFG(27-27)DefaultBG(28-28)
parse.go (1)
state.go (6)
State(86-107)AttrGfx(17-17)ModeWrap(37-37)AttrWrap(20-20)AttrWideDummy(23-23)AttrWide(22-22)
🔇 Additional comments (9)
parse.go (4)
28-31: Treating zero-width as 1 may not handle combining characters correctly.Zero-width characters (e.g., combining marks) are treated as width 1, which causes them to advance the cursor. In proper Unicode rendering, these should combine with the previous character without advancing the cursor.
Is combining character support required for this terminal emulator? If so, this logic should be enhanced to handle width==0 properly by combining with the previous cell rather than treating it as width 1.
34-43: Wide character silently dropped when wrapping is disabled.When a wide character doesn't fit and
ModeWrapis not enabled, the function returns early (line 41), silently dropping the character without writing anything.Please confirm this is the intended behavior for the terminal emulator. Some terminals might instead truncate the wide character or write a replacement character.
45-86: Wide character handling logic is comprehensive and well-bounded.The implementation correctly:
- Clears overlapped wide characters in all scenarios (writing over dummy, main, or placing dummy over another wide char's main).
- Performs proper bounds checking before all array accesses.
- Sets appropriate flags (
AttrWide,AttrWideDummy) for the main and dummy cells.- Moves the cursor by the actual character width.
The complexity is necessary to maintain correct rendering state when wide characters are overwritten or wrap across lines.
3-3: No action needed — the library version is valid and secure.
github.com/mattn/go-runewidth v0.0.19is the latest available version with no known vulnerabilities or security issues.go.mod (1)
5-5: Dependency addition aligns with wide-character support.The addition of
github.com/mattn/go-runewidth v0.0.19is necessary for the wide-character handling implemented inparse.go. Version verification was requested in the parse.go review.state.go (4)
14-24: Exported attribute constants enable external API usage.The promotion of attribute constants to exported names (e.g.,
AttrReverse,AttrBold) and the addition of new constants (AttrFaint,AttrWide,AttrWideDummy) align well with the PR objectives:
AttrFaintimplements SGR 2 (faint/decreased intensity) support.AttrWideandAttrWideDummyenable correct wide-character (CJK) rendering.The comments on lines 22-23 helpfully document the purpose of the wide-character flags.
162-166: Unsynchronized access viaRawLines()could lead to data races.The
RawLines()method exposes the internallinesslice without acquiring the mutex, breaking the thread-safety guarantees typically provided by theStatetype. While the comment documents this, it places a significant burden on callers to ensure proper synchronization.Please confirm:
- Is this API necessary, or could callers use the existing
Cell(x, y)method with proper locking?- Where will this be used, and have the call sites been audited to ensure they properly synchronize access?
- Consider making this a private method (e.g.,
rawLines()) if it's only needed internally.Based on learnings, unsynchronized APIs in concurrent code require careful justification and documentation of the exact use cases.
280-285: Faint and bold attributes are mutually exclusive.The implementation ensures that bold (line 280) and faint (line 283) are mutually exclusive:
- Bold brightening (FG + 8) is only applied if NOT faint.
- Faint dimming is only applied if NOT bold.
This is a reasonable design choice, as applying both simultaneously would be ambiguous. However, this behavior should be documented, as some terminal emulators may handle the combination differently.
Please confirm this mutual exclusion matches the intended terminal behavior and consider documenting it in code comments or external documentation.
636-660: SGR attribute handling correctly implements faint support.The implementation properly handles SGR (Select Graphic Rendition) sequences:
- SGR 0 (line 636): Resets all attributes including the new
AttrFaint.- SGR 2 (lines 641-642): Sets
AttrFaintas per the PR objective.- SGR 21/22 (line 652): Clears both
AttrBoldandAttrFaint, correctly implementing "normal intensity."All changes use the exported attribute constants consistently.
https://xtermjs.org/docs/api/vtfeatures/> SGR 2: Faint, decreased intensity.
Made it for gray text from codex:

Summary by CodeRabbit
New Features
Improvements
Tests
API Changes
✏️ Tip: You can customize this high-level summary in your review settings.