Skip to content

Use stream_isatty for CLI stdin detection#240

Merged
dereuromark merged 1 commit into
masterfrom
fix/posix-isatty-guard
Jun 10, 2026
Merged

Use stream_isatty for CLI stdin detection#240
dereuromark merged 1 commit into
masterfrom
fix/posix-isatty-guard

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

Problem

bin/djot uses posix_isatty(STDIN) to detect whether stdin is a terminal (for the interactive hint and the legacy bare-stdin convert path). ext-posix is not a hard dependency of the package, so on PHP builds without it - Windows, or minimal/container PHP installs - the CLI fatals:

Fatal error: Call to undefined function posix_isatty()

instead of converting the input.

Fix

Replace both posix_isatty(STDIN) calls with the built-in stream_isatty(STDIN), which is part of PHP core since 7.2 and requires no extension. Behavior is identical where posix was available, and now works everywhere.

Added two CLI tests that run bin/djot with posix_isatty disabled (-d disable_functions=posix_isatty), covering both the convert - subcommand and the legacy bare-stdin form.

Context

Surfaced while updating the djot-intellij plugin to call this CLI: the plugin needs a fallback specifically because of this crash. With this fix the CLI is safe to invoke on any supported PHP build.

Note

phpstan reports one pre-existing error in Parser/BlockParser.php:589 (offsetAccess.invalidOffset) on master, unrelated to this change - left untouched.

bin/djot called posix_isatty(STDIN) for stdin/tty detection, but ext-posix
is not a hard dependency of the package. On PHP builds without it (Windows,
minimal installs) the CLI fatals with 'undefined function posix_isatty()'
instead of converting.

Replace both calls with the built-in stream_isatty(), available in core
since PHP 7.2 and requiring no extension. Add CLI tests that run with
posix_isatty disabled to cover the convert subcommand and legacy stdin.
@dereuromark dereuromark added the bug Something isn't working label Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.89%. Comparing base (ae55a79) to head (fc25f4a).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #240   +/-   ##
=========================================
  Coverage     91.89%   91.89%           
  Complexity     3527     3527           
=========================================
  Files           106      106           
  Lines          9970     9970           
=========================================
  Hits           9162     9162           
  Misses          808      808           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dereuromark dereuromark merged commit f80b8da into master Jun 10, 2026
6 checks passed
@dereuromark dereuromark deleted the fix/posix-isatty-guard branch June 10, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant