fgof-pty Public
Code
Use Git or checkout with SVN using the web URL.
No matching headings.
fgof-pty
POSIX-first PTY and terminal session helpers for modern Fortran applications.
fgof-pty is intended to be a small, standalone library that gives Fortran tools an ergonomic PTY surface for interactive subprocesses, terminal resizing, and terminal-aware automation.
It is built for the kind of Fortran programs that need to drive interactive children: shells, terminal emulators, test harnesses, TUI tools, editors, and automation helpers.
It is part of the FortranGoingOnForty lib-modules catalog, but it is intended to stand on its own as a normal fpm package.
Current v1 target:
- POSIX-first PTY sessions on macOS and Linux
- child attach and close
- PTY read and write helpers
- terminal resize propagation
- explicit session state and terminal-size types
- clean integration points for
fgof-processand future expect-style tooling
Future scope:
- richer termios guards in a companion package
- expect-style testing helpers
- higher-level line-editing and key-decoding layers
Status
First real PTY session slice is in place.
Implemented today:
- public
fgof_ptyandfgof_pty_typesmodules - PTY session and terminal-size types
spawn_pty()for argv-based child launch on macOS and Linuxread_some(),write_all(),resize_pty(),refresh_pty(),wait_pty(), andclose_pty()- session-level error codes and messages
- blank-trimmed
programandargvinputs so normal Fortran fixed-length strings work naturally - interactive smoke-test coverage and CI wiring
Still to implement:
- deeper failure semantics and edge-case hardening
- richer session lifecycle helpers
- expect-style helpers in a future companion package
Why Use It
- PTY support is a real ecosystem gap for interactive Fortran tools
- shells, TUIs, and terminal automation all need the same primitives repeatedly
- the package is meant to stay small, direct, and composable
- it complements
fgof-processrather than overlapping it
Public API Shape
Primary modules:
fgof_ptyfgof_pty_types
Public types:
pty_sessionterminal_size
Current public procedures:
pty_backend_namedefault_terminal_sizespawn_ptyread_somerefresh_ptywait_ptywrite_allresize_ptyclose_pty
Quick Start
program demo_pty
use fgof_pty, only : close_pty, pty_session, read_some, spawn_pty, wait_pty, write_all
implicit none
type(pty_session) :: session
character(len=40) :: argv(2)
argv = ""
argv(1) = "-c"
argv(2) = 'read line; printf ''%s\n'' "$line"'
session = spawn_pty("sh", argv)
if (.not. session%is_open) error stop trim(session%error_message)
if (.not. write_all(session, "hello" // new_line("a"))) error stop trim(session%error_message)
print "(A)", read_some(session, 256)
if (.not. wait_pty(session, 1000)) error stop trim(session%error_message)
if (.not. close_pty(session)) error stop trim(session%error_message)
end program demo_pty
Build And Test
fpm test
That is the baseline verification command locally and in CI.
Supported Platforms
- macOS
- Linux
Boundaries
- POSIX-first for macOS and Linux
- intended to stay independently versioned and releasable
- focused on PTY transport and session control, not full terminal UI layers
spawn_pty()trims trailing blanks fromprogramand eachargventry to fit common Fortran string ergonomics
License
MIT