首页 > 作文

PHP Class Command Line Colors (bash,cmd)

更新时间:2023-04-07 06:08:03 阅读: 评论:0

color.class.php

<?php

class colors {
private $foreground_colors = array();
private $background_colors = array();

public function __construct() {
// t up shell colors
$this->foreground_colors[‘black’] = ‘0;30’;
$this->foreground_colors[‘dark_gray’] = ‘1;30’;
$this->foreground_colors[‘blue’] = ‘0;34’;
$this->foreground_colors[‘light_blue’] = ‘1;34’;
$this->foreground_colors[‘green’] = ‘0;32’;
$this->foreground_colors[‘light_green’] = ‘1;32’;
一又二分之一的夏天剧情 $this->foreground_colors[‘cyan’] = ‘0;36’;
$this->foreground_colors[‘light_cyan’] = ‘1;36’;
$this->foreground_colors[‘red’] = ‘0;31’;
$this->foreground_colors[‘light_red’] = ‘1;31’;
$this->foreground_colors[‘purple’] = ‘0;35’;
$this->foreground_colors[‘light_purple’] = ‘1;35’;
$this->foreground_colors[‘brown’] = ‘0;33’;
$this->foreground_colors[‘yellow’] = ‘1;33’;
$this->foreground_colors[‘light_gray’] = ‘0;37’;
$this->foreground_colors[‘white’] = ‘1;37’;

$this->background_colors[‘black’] = ’40’;
$this->background_colors[‘red’] = ’41’;
$this->background_colors[‘green’] = ’42’;
$this->background_colors[‘yellow’] = ’43’;
$this->background_colors[‘blue’] = ’44’;
$this->background_colors[‘magenta’] = ’45’;
$this->background_colors[‘cyan’] = ’46’;
$this->background_colors[‘light_gray’] = ’47’;
}

// returns colored string
public function getcoloredstring($string, $foreground_color = null, $background_color = null) {
$colored_string = “”;

// check if given foreground color found
if (ist($this->foreground_colors[$foreground_color])) {
$colored_string .= “\033[” . $this->foreground_colors[$foreground_color] . “m”;
}
// check if given background color found
if (ist($this->background_colors[$background_color])) {
$colored_string .= “\033[” . $this->background_colors[$background_color] . “m”;
}

// add string and end coloring
$colored_string .= $string . “\033[0m”;

return $colored_string;
}

// returns all foreground color names
public function getforegroundcolors() {
return array_keys($this->foreground_colors);
}

// returns all backgr面貌是什么意思ound color names
public function getbackgroundcolors() {
return array_keys($this->background_colors);
}
}

?>

banner.php

<?php
include(“color.class.php”);

$colors = new colors();

$a=$colors->getcoloredstring(” ## ### “, “light_red”);

$x=$b=$colors->getcoloredstring(” c0d3b3:”, “light_red”,”red”);

$b=$colors->getcoloredstring(“lost”, “light_red”,”red”);

$c=$colors->getcoloredstring(“wolf “, “light_red”,”red”);
echo “\r\n”;

echo ” $x”.”$b”.”$c”;

echo “\n\r\n\r\n\r\n\r\n”;

echo ” ######## #”.”\n”;
echo ” ################# #”.”\n”;
echo ” ###################### #”.”\n”;
echo ” ######################### #”.”\n”;
echo ” ############################”.”\n”;
echo ” ##############################”.”\n”;
echo ” ###############################”.”\n”;
echo ” ###############################”.”\n”;
echo ” ##############################”.”\n”;
echo ” # ######## #”;
echo ” \n $a”;echo”#### ##”.”\n”;
echo ” ### ###”.”\n”;
echo ” #### ###”.”\n”;
echo ” #### ########## ####”.”\n”;
echo ” ####################### ####”.”\n”;
echo ” #################### ####”.”\n”;
echo ” ################## ####”.”\n”;
echo ” ############ ##”.”\n”;
echo ” ######## ###”.”\n”;
echo ” ######### #####”.”\n”;
echo ” ############ ######”.”\n”;
echo ” ######## #########”.”\n”;
echo &#讲座心得8221; ##### ########”.”\n”;
echo ” ### #########̶宜人的近义词1;.”\n”;
echo ” ###### ############”.”\n”;
echo ” #######################”.”\n”中国名牌大学排名;
echo ” # # ### # # ##”.”\n”;
echo ” ########################”.”\n”;
echo ” ## ## ## ##”.”\r\n\r\n”;

?>

colors class basic usage examples

<?php

// create new colors class
$colors = new colors();

// test some basic printing with colors class
echo $colors->getcoloredstring(“testing colors class, this is purple string on yellow background.”, “purple”, “yellow”) . “\n”;
echo $colors->getcoloredstring(“testing colors class, this is blue string on light gray background.”, “blue”, “light_gray”) . “\n”;
echo $colors->getcoloredstring(“testing colors class, this is red string on black background.”, “red”, “black”) . “\n”;
echo $colors->getcoloredstring(“testing colors class, this is cyan string on green background.”, “cyan”, “green”) . “\n”;
echo $colors->getcoloredstring(“testing colors class, this is cyan string on default background.”, “cyan”) . “\n”;
echo $colors->getcoloredstring(“testing colors class, this is default string on cyan background.”, null, “cyan”) . “\n”;

?>

all foreground and background colors printed

<?php

// create new colors class
$colors = new colors();

// get foreground colors
$fgs = $colors->getforegroundcolors();
// get background colors
$bgs = $colors->getbackgroundcolors();

// loop through all foreground and background colors
$count = count($fgs);
for ($i = 0; $i < $count; $i++) {
echo $colors->getcoloredstring(“test foreground colors”, $fgs[$i]) . “\t”;
if (ist($bgs[$i])) {
echo $colors->getcoloredstring(“test background colors”, null, $bgs[$i]);
}
echo “\n”;
}
echo “\n”;

// loop through all foreground and background colors
foreach ($fgs as $fg) {
foreach ($bgs as $bg) {
echo $colors->getcoloredstring(“test colors”, $fg, $bg) . “\t”;
}
echo “\n”;
}

?>

//////////////////////////////////////////////////////////

ansi command line colors under windows

having colored text in the command line is a great help for spotting error or success messages. unfortunately, tho of us developing under windows do not have this feature by default. here’s how to enable it:

download ansicon fromhttp://adoxa.110mb.com/ansicon/index.html extract the proper files (depending on if you have a 32 or 64 bit machine) to c:\ansicon\ (for example). i have a 32 bit machine and hence i extracted the files from inside the x86 folder. open a command line prompt and go to c:\ansicon, and then type “ansicon -i” without the quotes done

you can now enjoy the colored output of phpunit for example.

摘自 lostwolf’s blog

本文发布于:2023-04-07 06:07:52,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/13e10b99d9ae30d798b3051c31268d32.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:PHP Class Command Line Colors (bash,cmd).doc

本文 PDF 下载地址:PHP Class Command Line Colors (bash,cmd).pdf

下一篇:返回列表
标签:宜人   面貌   中国名牌   讲座
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图