fix: apply dim and italic attributes in SwingTerminal, fix conceal+dim interaction#1758
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughConceal now prevents dim from altering foreground in ScreenTerminal. SwingTerminal centralizes color/font resolution (adds dim, italic handling and helpers). New unit tests validate conceal-vs-dim behavior and SwingTerminal color/font resolution. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
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🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
builtins/src/main/java/org/jline/builtins/SwingTerminal.java (1)
680-687:⚠️ Potential issue | 🟡 MinorBug: Bold style is lost when both bold and italic are set.
Font.deriveFont(int style)replaces the font style rather than combining styles. When bothboldanditalicare true, the second call overwrites the bold style, resulting in italic-only text.🐛 Proposed fix to combine font styles
// Set font style Font font = terminalFont; - if (bold) { - font = font.deriveFont(Font.BOLD); - } - if (italic) { - font = font.deriveFont(Font.ITALIC); + int style = Font.PLAIN; + if (bold) { + style |= Font.BOLD; + } + if (italic) { + style |= Font.ITALIC; + } + if (style != Font.PLAIN) { + font = font.deriveFont(style); } g2d.setFont(font);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@builtins/src/main/java/org/jline/builtins/SwingTerminal.java` around lines 680 - 687, The font derivation currently calls terminalFont.deriveFont twice so the second call overwrites the first and drops the bold flag when both bold and italic are true; instead compute a combined style int (e.g., style = (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0)) and call terminalFont.deriveFont(style) once, then pass that font to g2d.setFont; update the code around terminalFont, bold, italic, deriveFont and g2d.setFont in SwingTerminal accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@builtins/src/main/java/org/jline/builtins/SwingTerminal.java`:
- Around line 680-687: The font derivation currently calls
terminalFont.deriveFont twice so the second call overwrites the first and drops
the bold flag when both bold and italic are true; instead compute a combined
style int (e.g., style = (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0))
and call terminalFont.deriveFont(style) once, then pass that font to
g2d.setFont; update the code around terminalFont, bold, italic, deriveFont and
g2d.setFont in SwingTerminal accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: de01b9ac-cd30-4d41-93ad-6446ba752bbf
📒 Files selected for processing (2)
builtins/src/main/java/org/jline/builtins/ScreenTerminal.javabuiltins/src/main/java/org/jline/builtins/SwingTerminal.java
…t to SwingTerminal
Extract resolveColors(), dimColor(), and resolveFontStyle() from paintCell to reduce cognitive complexity from 18 to 7 (SonarCloud java:S3776 threshold is 15). Add unit tests for conceal+dim interaction (conceal must win) and for SwingTerminal color/font resolution logic.
379c7b3 to
38e7e51
Compare
|



Summary
Fixes two issues with attributes added in 237f60b:
else ifafter conceal.Changes
Bug fix — conceal + dim interaction (
ScreenTerminal)if (dim)toelse if (dim)after theif (conceal)block ingenerateSpanTag, so concealment always wins.Feature — dim and italic support (
SwingTerminal)Font.BOLDandFont.ITALICin a singlederiveFont()call.resolveColors(),dimColor(), andresolveFontStyle()frompaintCellto reduce cognitive complexity from 18 to 7 (SonarCloud java:S3776 threshold is 15).Tests
ScreenTerminalTest: conceal + dim interaction (verifies fg equals bg via HTML dump).SwingTerminalRenderingTest(new, 16 tests): unit tests forresolveColors,dimColor, andresolveFontStylecovering defaults, inverse, conceal, dim, conceal+dim, cursor override, bold, italic, bold+italic.Summary by CodeRabbit
Bug Fixes
Tests