Skip to content

fix: wire up unmapped termios constants in JNI and FFM providers#1838

Merged
gnodet merged 1 commit into
masterfrom
ci-issue-1829
Apr 25, 2026
Merged

fix: wire up unmapped termios constants in JNI and FFM providers#1838
gnodet merged 1 commit into
masterfrom
ci-issue-1829

Conversation

@gnodet
Copy link
Copy Markdown
Member

@gnodet gnodet commented Apr 25, 2026

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) and ofTermios/asAttributes (FFM) mapping methods, making them silently lost during roundtrip.

This PR:

  • Adds missing Attributes enum values: VSWTC, VERASE2 (ControlChar), IUCLC (InputFlag), OLCUC (OutputFlag), XCASE (LocalFlag)
  • Wires them in Linux and Solaris JNI providers (setFlag/addFlag + c_cc mapping for VSWTC)
  • Wires VERASE2 in FreeBSD JNI provider
  • Wires all in FFM CLibrary with proper -1 guards for platform-absent constants

Files changed

File Change
Attributes.java Add 5 new enum values
LinuxNativePty.java Wire IUCLC, OLCUC, XCASE, VSWTC
SolarisNativePty.java Wire IUCLC, OLCUC, XCASE, VSWTC
FreeBsdNativePty.java Wire VERASE2
CLibrary.java (FFM) Wire all 5, with guards

Test plan

  • ./mvx mvn spotless:apply passes
  • ./mvx mvn test -pl terminal,terminal-jni,terminal-ffm passes
  • ./mvx rebuild passes (all 21 modules)

Summary by CodeRabbit

  • New Features
    • Expanded terminal attribute handling with support for additional input and output character case mapping flags.
    • Added support for extra control character configurations for improved terminal setting customization across multiple platforms.

#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.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

📝 Walkthrough

Walkthrough

This PR extends terminal attribute support by adding previously unmapped termios constants to the Attributes enum classes and wiring them through platform-specific implementations. New enum values include IUCLC, OLCUC, XCASE flags and VSWTC, VERASE2 control characters, with corresponding bidirectional mappings in FFM and JNI implementations for Linux, Solaris, and FreeBSD.

Changes

Cohort / File(s) Summary
Attributes Base Enums
terminal/src/main/java/org/jline/terminal/Attributes.java
Added new enum constants: VSWTC and VERASE2 to ControlChar; IUCLC to InputFlag; OLCUC to OutputFlag; XCASE to LocalFlag.
FFM CLibrary Mapping
terminal-ffm/src/main/java/org/jline/terminal/impl/ffm/CLibrary.java
Extended termios() builder and asAttributes() to round-trip IUCLC, OLCUC, XCASE flags and VSWTC, VERASE2 control characters with conditional reads/writes.
JNI Platform-Specific Mappings
terminal-jni/src/main/java/org/jline/terminal/impl/jni/linux/LinuxNativePty.java, terminal-jni/src/main/java/org/jline/terminal/impl/jni/solaris/SolarisNativePty.java
Added bidirectional mapping for IUCLC, OLCUC, XCASE flags and VSWTC control character in termios(Attributes) and toAttributes(Termios) conversions.
JNI FreeBSD Mapping
terminal-jni/src/main/java/org/jline/terminal/impl/jni/freebsd/FreeBsdNativePty.java
Added VERASE2 control character mapping in termios conversion methods.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Bits and bytes and flags galore,
Constants mapped from core to core,
IUCLC, VERASE, and more,
Terminal magic we can't ignore! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding missing termios constant mappings in JNI and FFM providers.
Linked Issues check ✅ Passed All coding requirements from issue #1829 are met: enum constants added to Attributes [IUCLC, OLCUC, XCASE, VSWTC, VERASE2] and wired into all mapping classes with proper guards.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #1829: adding enum values and wiring mappings in termios classes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci-issue-1829

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
36.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
terminal-ffm/src/main/java/org/jline/terminal/impl/ffm/CLibrary.java (1)

182-182: Implicit zero-default on platforms missing IUCLC/OLCUC/XCASE.

These flags are written/read unconditionally and rely on the per-OS initializer leaving the constant at 0 on platforms where the flag is absent (macOS and FreeBSD branches don't assign them). OR-ing with 0 and masking against 0 are safe no-ops, so behavior is correct — but the convention elsewhere in this file (e.g., VDSUSP, VSTATUS, and the new VSWTC/VERASE2) is to use -1 sentinels with guards, which is more defensive and self-documenting. Consider initializing these to -1 on platforms that don't support them and guarding with if (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

📥 Commits

Reviewing files that changed from the base of the PR and between da637d3 and c6e17e7.

📒 Files selected for processing (5)
  • terminal-ffm/src/main/java/org/jline/terminal/impl/ffm/CLibrary.java
  • terminal-jni/src/main/java/org/jline/terminal/impl/jni/freebsd/FreeBsdNativePty.java
  • terminal-jni/src/main/java/org/jline/terminal/impl/jni/linux/LinuxNativePty.java
  • terminal-jni/src/main/java/org/jline/terminal/impl/jni/solaris/SolarisNativePty.java
  • terminal/src/main/java/org/jline/terminal/Attributes.java

@gnodet gnodet merged commit e1777da into master Apr 25, 2026
14 of 15 checks passed
@gnodet gnodet deleted the ci-issue-1829 branch April 25, 2026 18:45
gnodet added a commit that referenced this pull request Apr 25, 2026
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
@gnodet gnodet added the fix Bug fix label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unused termios constants lack corresponding Attributes enum values

1 participant