xp-forge/terminal

此包已被弃用,不再维护。未建议替代包。

终端控制

v1.0.1 2020-10-04 14:09 UTC

This package is auto-updated.

Last update: 2021-11-04 16:19:26 UTC


README

Build Status on TravisCI XP Framework Module BSD Licence Supports PHP 7.0+ Latest Stable Version

终端库为 util.cmd.Console 类添加了对颜色的支持。

Screenshot

样式

有五种预定义样式

use util\cmd\Console;

Console::writeLine('This is <primary>primary</>!');
Console::writeLine('This is <success>success</>!');
Console::writeLine('This is <info>info</>!');
Console::writeLine('This is <warning>warning</>!');
Console::writeLine('This is <danger>danger</>!');

颜色

对于直接颜色控制,可以通过提供颜色名称直接选择颜色。前景色和背景色由 @ 符号分隔

use util\cmd\Console;

Console::writeLine('<red>An error occured</>');
Console::writeLine('<white@green>OK: 100 Tests succeeded</>');

颜色的名称有黑色、深红色、深绿色、深黄色、深蓝色、深洋红色、深青色、灰色、深灰色、红色、绿色、黄色、蓝色、洋红色、青色和白色。

属性

还有三个属性。虽然不是所有终端都支持这些属性!

use util\cmd\Console;

Console::writeLine('<underline>http://localhost</>');
Console::writeLine('<bold>Watch out!</>');
Console::writeLine('<italic>- The XP Framework group</>');

// Can be combined, too
Console::writeLine('<dark-blue,underline>http://localhost</>');

定位

util.cmd.term.Terminal 类允许清除屏幕、定位光标并在此处写入文本。

Screenshot

use util\cmd\term\Terminal;

$message= 'Hello from the middle of the screen';

// Center text in third line
$dim= Terminal::size();
$x= ($dim[0] - strlen($message)) / 2;
$y= 3;

Terminal::clear();
Terminal::write($x, $y, $message);

对于上面截图中的更高级的示例,请参阅 此代码