From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- library/Icinga/Cli/Screen.php | 106 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 library/Icinga/Cli/Screen.php (limited to 'library/Icinga/Cli/Screen.php') diff --git a/library/Icinga/Cli/Screen.php b/library/Icinga/Cli/Screen.php new file mode 100644 index 0000000..4ffad72 --- /dev/null +++ b/library/Icinga/Cli/Screen.php @@ -0,0 +1,106 @@ +strlen($txt); + $width = floor(($this->getColumns() + $len) / 2) - $len; + return str_repeat(' ', $width) . $txt; + } + + public function hasUtf8() + { + if ($this->isUtf8 === null) { + // null should equal 0 here, however seems to equal '' on some systems: + $current = setlocale(LC_ALL, 0); + + $parts = preg_split('/;/', $current); + $lc_parts = array(); + foreach ($parts as $part) { + if (strpos($part, '=') === false) { + continue; + } + list($key, $val) = preg_split('/=/', $part, 2); + $lc_parts[$key] = $val; + } + + $this->isUtf8 = array_key_exists('LC_CTYPE', $lc_parts) + && preg_match('~\.UTF-8$~i', $lc_parts['LC_CTYPE']); + } + return $this->isUtf8; + } + + public function clear() + { + return "\n"; + } + + public function underline($text) + { + return $text; + } + + public function colorize($text, $fgColor = null, $bgColor = null) + { + return $text; + } + + public static function instance($output = STDOUT) + { + if (! isset(self::$instances[(int) $output])) { + if (function_exists('posix_isatty') && posix_isatty($output)) { + self::$instances[(int) $output] = new AnsiScreen(); + } else { + self::$instances[(int) $output] = new Screen(); + } + } + + return self::$instances[(int) $output]; + } +} -- cgit v1.2.3