Repository navigation
feat(examples): add cross-platform native terminal I/O example for Linux, macOS, and Windows - #150
Closed
prateekbhujel wants to merge 2 commits into
Closed
prateekbhujel wants to merge 2 commits into
prateekbhujel wants to merge 2 commits into
Conversation
…nux, macOS, and Windows Demonstrate how to build cross-platform native CLI and TUI applications with TypePHP using mixed C++/PHP programming (cpp-src + php-src). - Native terminal sizing via ioctl(TIOCGWINSZ) on POSIX and GetConsoleScreenBufferInfo on Windows - Native in-process TTY stream check (isatty / GetConsoleMode) - Native raw mode with atexit automated cleanup to prevent terminal corruption - In-process secret password input without terminal echo - Window title setting via OSC escape codes (POSIX) and SetConsoleTitleW (Windows) - ANSI color detection probing TERM and NO_COLOR - Object-oriented Terminal wrapper class with helper methods - Interactive CLI demonstration program - Comprehensive bilingual documentation and PHPUnit test
…preserve native property compound type checks - DefaultArgumentGenerator: convert dynamic binary expressions emitted as php::Var(...) to native types using php::toInt() / php::toFloat() in typed default argument helper functions. - AssignOpTrait: preserve wrapObjectPropertyAssignTypeCheck on native scalar object properties when compound assignment RHS is a dynamic Variant (Type::VAR).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds
examples/terminal, a complete demonstration of how to build cross-platform native CLI and TUI applications using TypePHP's mixed C++/PHP programming capabilities (cpp-src+php-src).Standard PHP CLI applications traditionally depend on executing external sub-processes (
stty, Windowsmode CON) or installing separate PHP extensions to query window dimensions, enable raw mode, or capture hidden passwords. When compiled into a standalone native binary with TypePHP (tpc -m bin), this implementation interacts directly with the operating system kernel and console APIs with zero external dependencies and zerozvalboxing overhead.What is included
Cross-Platform C++ Native Module (
examples/terminal/cpp-src/terminal.cc):ioctl(TIOCGWINSZ)on Linux & macOS;GetConsoleScreenBufferInfoon Windows.isattyon Unix;GetConsoleModeon Windows.termioson Unix;SetConsoleModeon Windows) withatexitautomated cleanup to ensure the terminal state is safely restored even on unexpected exit.\033]0;...\007) on Unix andSetConsoleTitleW(UTF-8 to UTF-16) on Windows.TERMandNO_COLORenvironment variables.PHP Stubs & Object-Oriented Wrapper (
examples/terminal/php-src/Terminal.php):terminal_get_width(),terminal_get_height(), etc.) for TypePHP's compiler to resolve.Terminalclass with helper methods (getSize(),enableRawMode(),disableRawMode(),readSecret(),setTitle(),colorize()).Demonstration Entrypoint (
examples/terminal/main.php):Bilingual Documentation (
examples/terminal/README.md):PHPUnit Test (
phpunit/TerminalExampleTest.php):Verification
clang++ -std=c++17 -Wall -Wextraagainstphpx.hand PHP headers (0 errors).php -lon all PHP files (0 syntax errors)../vendor/bin/phpunit phpunit/TerminalExampleTest.php(6 tests, 15 assertions passed 100% green).