fix: wire up unmapped termios constants in JNI and FFM providers#1838
Conversation
#1829) Add missing Attributes enum values for platform-specific termios constants that were defined but never mapped: VSWTC, VERASE2 (ControlChar), IUCLC (InputFlag), OLCUC (OutputFlag), XCASE (LocalFlag). Wire them in toTermios/toAttributes for Linux, Solaris, and FreeBSD in both JNI NativePty classes and FFM CLibrary.
📝 WalkthroughWalkthroughThis PR extends terminal attribute support by adding previously unmapped termios constants to the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
🧹 Nitpick comments (1)
terminal-ffm/src/main/java/org/jline/terminal/impl/ffm/CLibrary.java (1)
182-182: Implicit zero-default on platforms missingIUCLC/OLCUC/XCASE.These flags are written/read unconditionally and rely on the per-OS initializer leaving the constant at
0on platforms where the flag is absent (macOS and FreeBSD branches don't assign them). OR-ing with0and masking against0are safe no-ops, so behavior is correct — but the convention elsewhere in this file (e.g.,VDSUSP,VSTATUS, and the newVSWTC/VERASE2) is to use-1sentinels with guards, which is more defensive and self-documenting. Consider initializing these to-1on platforms that don't support them and guarding withif (XCASE != -1) …for consistency.Also applies to: 187-187, 233-233, 361-361, 366-366, 411-411
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@terminal-ffm/src/main/java/org/jline/terminal/impl/ffm/CLibrary.java` at line 182, The code unconditionally uses the constants IUCLC, OLCUC, and XCASE when calling setFlag and masking even on platforms that don't define them; change the per-OS initializers to set IUCLC/OLCUC/XCASE to -1 when unsupported and update all uses (the setFlag call that assigns c_iflag, the corresponding output flag masking, and any XCASE checks) to guard with if (IUCLC != -1) / if (OLCUC != -1) / if (XCASE != -1) before calling setFlag or applying bitmasks so the sentinel -1 indicates “unsupported” and avoids implicit zero-default behavior; update the same pattern for the other referenced occurrences (the lines handling these flags and their reads/writes) to match the VDSUSP/VSTATUS/VSWTC/VERASE2 defensive style.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@terminal-ffm/src/main/java/org/jline/terminal/impl/ffm/CLibrary.java`:
- Line 182: The code unconditionally uses the constants IUCLC, OLCUC, and XCASE
when calling setFlag and masking even on platforms that don't define them;
change the per-OS initializers to set IUCLC/OLCUC/XCASE to -1 when unsupported
and update all uses (the setFlag call that assigns c_iflag, the corresponding
output flag masking, and any XCASE checks) to guard with if (IUCLC != -1) / if
(OLCUC != -1) / if (XCASE != -1) before calling setFlag or applying bitmasks so
the sentinel -1 indicates “unsupported” and avoids implicit zero-default
behavior; update the same pattern for the other referenced occurrences (the
lines handling these flags and their reads/writes) to match the
VDSUSP/VSTATUS/VSWTC/VERASE2 defensive style.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c25789fb-647f-4242-9fb2-5e45a74ada4c
📒 Files selected for processing (5)
terminal-ffm/src/main/java/org/jline/terminal/impl/ffm/CLibrary.javaterminal-jni/src/main/java/org/jline/terminal/impl/jni/freebsd/FreeBsdNativePty.javaterminal-jni/src/main/java/org/jline/terminal/impl/jni/linux/LinuxNativePty.javaterminal-jni/src/main/java/org/jline/terminal/impl/jni/solaris/SolarisNativePty.javaterminal/src/main/java/org/jline/terminal/Attributes.java
The TermiosMapping classes were extracted from pre-fix NativePty code and still had the old bugs. Apply fixes from #1834, #1835, #1837, #1838: - LinuxTermiosMapping: fix PENDIN constant, add IUCLC/OLCUC/XCASE/VSWTC wiring - SolarisTermiosMapping: fix all octal-as-hex constants, add IUCLC/OLCUC/XCASE/VSWTC wiring - FreeBsdTermiosMapping: fix PENDIN/NOFLSH constants, add VERASE2 wiring


Summary
Fixes #1829
Several platform-specific termios constants were defined in the JNI NativePty classes and FFM CLibrary but never wired into the
toTermios/toAttributes(JNI) andofTermios/asAttributes(FFM) mapping methods, making them silently lost during roundtrip.This PR:
Attributesenum values:VSWTC,VERASE2(ControlChar),IUCLC(InputFlag),OLCUC(OutputFlag),XCASE(LocalFlag)-1guards for platform-absent constantsFiles changed
Attributes.javaLinuxNativePty.javaSolarisNativePty.javaFreeBsdNativePty.javaCLibrary.java(FFM)Test plan
./mvx mvn spotless:applypasses./mvx mvn test -pl terminal,terminal-jni,terminal-ffmpasses./mvx rebuildpasses (all 21 modules)Summary by CodeRabbit