Last active
June 18, 2025 12:47
-
-
Save JamshidbekAkhlidinov/3db57c3b2fa7042c92fd98a62c0042e4 to your computer and use it in GitHub Desktop.
Console da ishlayotganda text larni turli xil rangda chiqarish uchun
This file contains hidden or 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 | |
| class TerminalColors | |
| { | |
| // Matn ranglari | |
| public const TEXT_BLACK = "\033[30m"; | |
| public const TEXT_RED = "\033[31m"; | |
| public const TEXT_GREEN = "\033[32m"; | |
| public const TEXT_YELLOW = "\033[33m"; | |
| public const TEXT_BLUE = "\033[34m"; | |
| public const TEXT_PURPLE = "\033[35m"; | |
| public const TEXT_CYAN = "\033[36m"; | |
| public const TEXT_WHITE = "\033[37m"; | |
| // Fon ranglari | |
| public const BG_BLACK = "\033[40m"; | |
| public const BG_RED = "\033[41m"; | |
| public const BG_GREEN = "\033[42m"; | |
| public const BG_YELLOW = "\033[43m"; | |
| public const BG_BLUE = "\033[44m"; | |
| public const BG_PURPLE = "\033[45m"; | |
| public const BG_CYAN = "\033[46m"; | |
| public const BG_WHITE = "\033[47m"; | |
| // Formatlar | |
| public const BOLD = "\033[1m"; | |
| public const UNDERLINE = "\033[4m"; | |
| public const RESET = "\033[0m"; | |
| // Matn va fon rangini birlashtirish funksiyasi | |
| public static function colorText($text, $textColor = self::TEXT_WHITE, $backgroundColor = self::BG_BLACK, $format = null) | |
| { | |
| $coloredText = ""; | |
| // Agar format kiritilgan bo'lsa, uni qo'shamiz | |
| if ($format) { | |
| $coloredText .= $format; | |
| } | |
| // Matn rangini qo'shamiz | |
| $coloredText .= $textColor; | |
| // Fon rangini qo'shamiz | |
| $coloredText .= $backgroundColor; | |
| // Matn va oxirida rangni tozalash kodi | |
| $coloredText .= $text . self::RESET; | |
| return $coloredText; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment