This file contains 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
<?php | |
function console_styles() { | |
return array( | |
'heading1' => "\033[1;30;46m", | |
'heading2' => "\033[1;35m", | |
'heading3' => "\033[1;34m", | |
'option' => "\033[40;37m", | |
'command' => "\033[1;40;37m", | |
'error' => "\033[0;31m", | |
'success' => "\033[0;32m", | |
'black' => "\033[0;30m", | |
'red' => "\033[0;31m", | |
'green' => "\033[0;32m", | |
'yellow' => "\033[0;33m", | |
'blue' => "\033[0;34m", | |
'purple' => "\033[0;35m", | |
'cyan' => "\033[0;36m", | |
'white' => "\033[0;37m", | |
'end' => "\033[0m", | |
); | |
} | |
function console_out($data) { | |
$styles = console_styles(); | |
foreach ((array) $data as $key=>$token) { | |
if (is_string($key)) { | |
echo $styles[$key], $token, $styles['end']; | |
} else { | |
echo $token; | |
} | |
} | |
} |
Lithiumの表示が綺麗だったので、その部分だけ簡単に使えるように抜き出してみました。PHPの変態的ともいえる配列の動作(辞書的+数字のミックス)を取り入れたんで、比較的使いやすくできました。以下のような感じで、緑色の"world"が表示されます。
console_out(array('Hello', 'green' => '"world"', '!')); echo "\n";
array() が余計かなぁ。ここがもっと簡単にかけるとうれしいんだけど。こんな風にかけたらうれしいな。
console_out(['Hello', 'green'=>'"world"', '!']); echo "\n";
0 件のコメント:
コメントを投稿