Skip to content

refactor(define): minimize custom terminal FFI - #33

Merged
GG-O-BP merged 1 commit into
mainfrom
refactor/term-size-terminal-ffi-issue-18
Sep 7, 2026
Merged

refactor(define): minimize custom terminal FFI#33
GG-O-BP merged 1 commit into
mainfrom
refactor/term-size-terminal-ffi-issue-18

Conversation

@GG-O-BP

@GG-O-BP GG-O-BP commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Resolves the issue #18 spike by minimizing the widget-definition TUI's custom
terminal FFI. Terminal-capability and raw-input FFI previously lived in a single
src/glendix/define_ffi.mjs adapter; this change delegates everything with a
reliable ecosystem equivalent to a package and keeps only the irreducible
custom residue, moved to an internal boundary module.

Closes #18

Changes

  • Terminal size now delegates to the term_size package (term_size.get()),
    converting the package's #(rows, columns) result into the TUI's existing
    #(columns, rows) contract. The conventional 80x24 fallback is preserved,
    including independent fallback for non-positive dimensions.
  • Process exit now delegates to the existing plinth/node/process.exit
    dependency instead of a custom zero-argument FFI export.
  • The terminal boundary moved from src/glendix/define_ffi.mjs into the internal
    module glendix/internal/define/terminal_control (+ terminal_control_ffi.mjs),
    so no new public package API is introduced.
  • terminal-ffi-spike.md records the full evaluation and rationale.

Intentionally retained custom FFI

No evaluated package safely provides these, so they remain custom and are
documented as intentional residue:

  • TTY probe (is_tty)
  • raw-mode toggling with exact failure messages (incl. "stdin does not support
    raw mode")
  • stdin lifecycle
  • non-blocking one-shot key polling with timeout
  • UTF-8 aware key decoding (arrow/nav keys, Enter, Backspace, Ctrl+C, Tab)

Tests

Added contract coverage in
test/glendix/internal/define/terminal_control_test.gleam:

  • size-tuple ordering and the 80x24 fallback (including non-positive dims)
  • key decoding: Arrow/Home/End/PageUp/PageDown/Enter/Escape/Backspace/Ctrl+C/Tab
  • ASCII and 2/3/4-byte UTF-8 decoding
  • raw-mode unsupported message and preserved exception cause
  • enable/disable lifecycle
  • pending / queued / timeout polling

Verification

  • ./scripts/verify.sh inner glendix — pass (Glendix: 106 passed, no failures)
  • ./scripts/verify.sh shared glendix — pass (family gates, all standalone
    consumers, widget .mpk build)
  • ./scripts/verify.sh final — run via the mandatory child pre-push hook
    (family gates + Lustre and Mendix end-to-end)

Dependency contract

  • glendix -> mendraw keeps its currently declared Hex dependency source form.
  • Managed harness locals remain local.

Move the widget definition TUI terminal boundary into the internal
glendix/internal/define/terminal_control module. Delegate size queries to the
term_size package and successful process termination to plinth, while retaining
only the TTY probe, raw-mode control, stdin lifecycle, and non-blocking key
polling as documented custom FFI.

Preserve the 80x24 fallback, raw-mode error messages, key decoding, queued input,
and one-shot timeout behavior. Add contract coverage for every retained key
sequence, raw-mode success and error paths, polling, and terminal-size tuple
conversion without exposing a new public package API.

Refs #18
@GG-O-BP
GG-O-BP force-pushed the refactor/term-size-terminal-ffi-issue-18 branch from a62f126 to 3e76e20 Compare September 7, 2026 12:29
@GG-O-BP
GG-O-BP merged commit 3b068cc into main Sep 7, 2026
1 check passed
@GG-O-BP
GG-O-BP deleted the refactor/term-size-terminal-ffi-issue-18 branch September 7, 2026 12:31
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.

[ffi] Evaluate terminal packages and minimize raw terminal FFI

1 participant