php/tty/demo_tty.php · 1561 字节 · 下载原文
<?php
// demo_tty.php —— PHP 第二层:**彩色命令行**(tty)
// demo_tty.php -- PHP layer 2: **colour command line** (tty)
//
// 这一层做「在字符界面上排版」:清屏、彩色文字、按行输出。
// This layer lays out a character screen: clear it, colour the text, print lines.
//
// 跑法(桌面 vmlcli):
// How to run (desktop vmlcli):
// dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/php/tty/demo_tty.php
//
// 实现说明:`Lib/php/` 下没有 tty 声明文件,`Lib/php/builtin.vml` 也没有链 tty.vml,
// Implementation note: there is no tty declaration file under Lib/php/ and Lib/php/builtin.vml does not link tty.vml,
// 所以这里用 ANSI 转义串表达同一件事(清屏 ESC[2J、颜色 ESC[<n>m、复位 ESC[0m)。
// so this file expresses the same thing with ANSI escapes (clear ESC[2J, colour ESC[<n>m, reset ESC[0m).
// `chr(27)` 是 ESC,`chr(10)` 是换行(本子集不解释 \n 转义)。
// chr(27) is ESC and chr(10) is the newline (this subset does not interpret \n escapes).
$esc = chr(27);
$nl = chr(10);
echo $esc, "[2J", $esc, "[H", $esc, "[1;36m", "=== PHP TTY demo ===", $esc, "[0m", $nl;
echo $esc, "[33m", " yellow: tty layer / color console", $esc, "[0m", $nl;
echo $esc, "[32m", " green : clear screen + SGR colors", $esc, "[0m", $nl;
echo $esc, "[35m", " magenta: loop follows", $esc, "[0m", $nl;
for ($i = 1; $i <= 3; $i++) {
echo $esc, "[34m", " loop line ", $i, $esc, "[0m", $nl;
}
echo $esc, "[0m", $nl;
echo "PHP TTY demo: done", $nl;