-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d31117
commit f518a05
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
/** | ||
* php-mvc, a PHP micro-framework for use as a frontend and/or backend | ||
* Copyright (C) 2017 Carl Bennett | ||
* This file is part of php-mvc. | ||
* | ||
* php-mvc is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* php-mvc is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with php-mvc. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace CarlBennett\MVC\Libraries; | ||
|
||
class Term { | ||
|
||
/** | ||
* <http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html> | ||
*/ | ||
|
||
const RESET = "\033[0m"; | ||
|
||
const BOLD = "\033[1m"; | ||
const ITALIC = "\033[3m"; | ||
const UNDERLINE = "\033[4m"; | ||
const INVERSE = "\033[7m"; | ||
const STRIKE = "\033[9m"; | ||
|
||
const FG_BLACK = "\033[30m"; | ||
const FG_RED = "\033[31m"; | ||
const FG_GREEN = "\033[32m"; | ||
const FG_YELLOW = "\033[33m"; | ||
const FG_BLUE = "\033[34m"; | ||
const FG_MAGENTA = "\033[35m"; | ||
const FG_CYAN = "\033[36m"; | ||
const FG_WHITE = "\033[37m"; | ||
const FG_DEFAULT = "\033[39m"; | ||
|
||
const BG_BLACK = "\033[40m"; | ||
const BG_RED = "\033[41m"; | ||
const BG_GREEN = "\033[42m"; | ||
const BG_YELLOW = "\033[43m"; | ||
const BG_BLUE = "\033[44m"; | ||
const BG_MAGENTA = "\033[45m"; | ||
const BG_CYAN = "\033[46m"; | ||
const BG_WHITE = "\033[47m"; | ||
const BG_DEFAULT = "\033[49m"; | ||
|
||
public static $strip_color = false; | ||
|
||
public static function filter_color($text) { | ||
$text = str_replace(self::RESET , "", $text); | ||
|
||
$text = str_replace(self::BOLD , "", $text); | ||
$text = str_replace(self::ITALIC , "", $text); | ||
$text = str_replace(self::UNDERLINE , "", $text); | ||
$text = str_replace(self::INVERSE , "", $text); | ||
$text = str_replace(self::STRIKE , "", $text); | ||
|
||
$text = str_replace(self::FG_BLACK , "", $text); | ||
$text = str_replace(self::FG_RED , "", $text); | ||
$text = str_replace(self::FG_GREEN , "", $text); | ||
$text = str_replace(self::FG_YELLOW , "", $text); | ||
$text = str_replace(self::FG_BLUE , "", $text); | ||
$text = str_replace(self::FG_MAGENTA, "", $text); | ||
$text = str_replace(self::FG_CYAN , "", $text); | ||
$text = str_replace(self::FG_WHITE , "", $text); | ||
$text = str_replace(self::FG_DEFAULT, "", $text); | ||
|
||
$text = str_replace(self::BG_BLACK , "", $text); | ||
$text = str_replace(self::BG_RED , "", $text); | ||
$text = str_replace(self::BG_GREEN , "", $text); | ||
$text = str_replace(self::BG_YELLOW , "", $text); | ||
$text = str_replace(self::BG_BLUE , "", $text); | ||
$text = str_replace(self::BG_MAGENTA, "", $text); | ||
$text = str_replace(self::BG_CYAN , "", $text); | ||
$text = str_replace(self::BG_WHITE , "", $text); | ||
$text = str_replace(self::BG_DEFAULT, "", $text); | ||
|
||
return $text; | ||
} | ||
|
||
public static function stderr($text) { | ||
if (self::$strip_color) { | ||
$text = self::filter_color($text); | ||
} | ||
return fwrite(STDERR, $text); | ||
} | ||
|
||
public static function stdout($text) { | ||
if (self::$strip_color) { | ||
$text = self::filter_color($text); | ||
} | ||
return fwrite(STDOUT, $text); | ||
} | ||
|
||
} |