Skip to content

feat: implement IO::Tty/IO::Pty module with FFM native PTY bindings#498

Merged
fglock merged 3 commits intomasterfrom
feature/io-pty
Apr 13, 2026
Merged

feat: implement IO::Tty/IO::Pty module with FFM native PTY bindings#498
fglock merged 3 commits intomasterfrom
feature/io-pty

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 13, 2026

Summary

Implement IO::Tty and IO::Pty as bundled Java modules using FFM (Foreign Function & Memory) native bindings for POSIX pseudo-terminal operations.

What's included

FFM PTY Bindings

  • ~15 new native methods: posix_openpt, grantpt, unlockpt, ptsname, setsid, ttyname, nativeOpen/Close/Read/Write/Dup, fcntlDupFd, ioctlWithPointer/Int, tcgetattr, tcsetattr
  • Platform-specific constants for macOS and Linux
  • Windows stubs with UnsupportedOperationException

NativeFdIOHandle

  • Bridges native POSIX file descriptors to PerlOnJava's IOHandle interface

IOTty.java Perlmodule

  • pty_allocate, _open_tty, ttyname, pack/unpack_winsize XS replacements
  • Terminal constants in IO::Tty::Constant namespace

Real ioctl implementation

  • Replaces stub with FFM-backed dispatch for TIOCGWINSZ, TIOCSWINSZ, TIOCSCTTY

Perl shims

  • IO::Tty.pm with set_raw, clone_winsize_from, get/set_winsize
  • IO::Pty.pm with new, slave, close_slave, make_slave_controlling_terminal
  • IO::Tty::Constant.pm with Exporter interface

POSIX module additions

  • isatty, setsid, ttyname, dup, close
  • POSIX::Termios class with new, getattr, setattr, get/set for all flag fields
  • Termios constants: ECHO, ICANON, TCSANOW, CS8, CSIZE, PARENB, VMIN, VTIME, etc.

Tests

  • 8 test files (48 tests): constants, ttyname, slave, pty_set_raw, pty_destroy, pty_get_winsize, winsize, clone_winsize
  • All pass (2 marked TODO for native fd close semantics)

Downstream impact

  • Expect module should install via jcpan install Expect (pure Perl, depends on IO::Pty)
  • Modules that check eval { require IO::Pty } will find it available

Test plan

  • make passes (all unit tests, no regressions)
  • All 8 IO-Tty test files pass (48/48 tests, 2 TODO)
  • Smoke test: IO::Pty->new, slave, isatty, set_raw, POSIX::Termios

Generated with Devin

fglock and others added 3 commits April 13, 2026 11:17
Implement IO::Tty and IO::Pty as bundled Java modules using FFM
(Foreign Function & Memory) native bindings for POSIX pseudo-terminal
operations.

Phases 1-7 of the implementation plan (dev/modules/io_pty.md):

FFM PTY Bindings (Phase 1):
- Add posix_openpt, grantpt, unlockpt, ptsname, setsid, ttyname,
  nativeOpen/Close/Read/Write/Dup, fcntlDupFd, ioctlWithPointer/Int,
  tcgetattr, tcsetattr to FFMPosixInterface/FFMPosixLinux
- Platform-specific constants for macOS and Linux
- UnsupportedOperationException stubs in FFMPosixWindows

NativeFdIOHandle (Phase 2):
- Bridge native POSIX file descriptors to PerlOnJava IOHandle interface
- Implements fileno, sysread, syswrite, close, flush, eof

IOTty.java Perlmodule (Phase 3):
- pty_allocate, _open_tty, ttyname, pack/unpack_winsize XS replacements
- Terminal constants in IO::Tty::Constant namespace
- $IO::Tty::CONFIG platform capability string

ioctl Upgrade (Phase 4):
- Replace ioctl stub with real FFM-backed implementation
- Handle TIOCGWINSZ/TIOCSWINSZ (struct), TIOCSCTTY (int)
- Return "0 but true" for Perl convention

Perl Shims (Phase 5):
- IO/Tty.pm with set_raw, clone_winsize_from, get/set_winsize
- IO/Pty.pm with new, slave, close_slave, make_slave_controlling_terminal
- IO/Tty/Constant.pm with Exporter interface

POSIX Module Additions (Phase 6):
- Add isatty, setsid, ttyname, dup, close to POSIX.java
- Implement POSIX::Termios class (new, getattr, setattr, get/set flags)
- Add termios constants (ECHO, ICANON, TCSANOW, CS8, CSIZE, PARENB,
  VMIN, VTIME, and more)
- Add termios_h export group to POSIX.pm

Tests (Phase 7):
- 8 test files (48 tests): constants, ttyname, slave, pty_set_raw,
  pty_destroy, pty_get_winsize, winsize, clone_winsize
- All pass (2 TODO for native fd close semantics)

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- Add IO::Tty, IO::Pty, IO::Tty::Constant to bundled-modules.md
- Update io_pty.md checklist: all phases marked complete
- Update progress tracking with dates, details, known limitations

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock merged commit 1afee08 into master Apr 13, 2026
2 checks passed
@fglock fglock deleted the feature/io-pty branch April 13, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant