芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/store.kwesioben.com/vendor/psy/psysh/src/Readline/Hoa/ConsoleTput.php
parse($terminfo); return; } /** * Parse. */ protected function parse(string $terminfo): array { if (!\file_exists($terminfo)) { throw new ConsoleException('Terminfo file %s does not exist.', 0, $terminfo); } $data = \file_get_contents($terminfo); $length = \strlen($data); $out = ['file' => $terminfo]; $headers = [ 'data_size' => $length, 'header_size' => 12, 'magic_number' => (\ord($data[1]) << 8) | \ord($data[0]), 'names_size' => (\ord($data[3]) << 8) | \ord($data[2]), 'bool_count' => (\ord($data[5]) << 8) | \ord($data[4]), 'number_count' => (\ord($data[7]) << 8) | \ord($data[6]), 'string_count' => (\ord($data[9]) << 8) | \ord($data[8]), 'string_table_size' => (\ord($data[11]) << 8) | \ord($data[10]), ]; $out['headers'] = $headers; // Names. $i = $headers['header_size']; $nameAndDescription = \explode('|', \substr($data, $i, $headers['names_size'] - 1)); $out['name'] = $nameAndDescription[0]; $out['description'] = $nameAndDescription[1]; // Booleans. $i += $headers['names_size']; $booleans = []; $booleanNames = &static::$_booleans; for ( $e = 0, $max = $i + $headers['bool_count']; $i < $max; ++$e, ++$i ) { $booleans[$booleanNames[$e]] = 1 === \ord($data[$i]); } $out['booleans'] = $booleans; // Numbers. if (1 === ($i % 2)) { ++$i; } $numbers = []; $numberNames = &static::$_numbers; for ( $e = 0, $max = $i + $headers['number_count'] * 2; $i < $max; ++$e, $i += 2 ) { $name = $numberNames[$e]; $data_i0 = \ord($data[$i]); $data_i1 = \ord($data[$i + 1]); if ($data_i1 === 255 && $data_i0 === 255) { $numbers[$name] = -1; } else { $numbers[$name] = ($data_i1 << 8) | $data_i0; } } $out['numbers'] = $numbers; // Strings. $strings = []; $stringNames = &static::$_strings; $ii = $i + $headers['string_count'] * 2; for ( $e = 0, $max = $ii; $i < $max; ++$e, $i += 2 ) { $name = $stringNames[$e]; $data_i0 = \ord($data[$i]); $data_i1 = \ord($data[$i + 1]); if ($data_i1 === 255 && $data_i0 === 255) { continue; } $a = ($data_i1 << 8) | $data_i0; $strings[$name] = $a; if (65534 === $a) { continue; } $b = $ii + $a; $c = $b; while ($c < $length && \ord($data[$c])) { $c++; } $value = \substr($data, $b, $c - $b); $strings[$name] = false !== $value ? $value : null; } $out['strings'] = $strings; return $this->_informations = $out; } /** * Get all informations. */ public function getInformations(): array { return $this->_informations; } /** * Get a boolean value. */ public function has(string $boolean): bool { if (!isset($this->_informations['booleans'][$boolean])) { return false; } return $this->_informations['booleans'][$boolean]; } /** * Get a number value. */ public function count(string $number): int { if (!isset($this->_informations['numbers'][$number])) { return 0; } return $this->_informations['numbers'][$number]; } /** * Get a string value. */ public function get(string $string) { if (!isset($this->_informations['strings'][$string])) { return null; } return $this->_informations['strings'][$string]; } /** * Get current term profile. */ public static function getTerm(): string { return isset($_SERVER['TERM']) && !empty($_SERVER['TERM']) ? $_SERVER['TERM'] : (\defined('PHP_WINDOWS_VERSION_PLATFORM') ? 'windows-ansi' : 'xterm'); } /** * Get pathname to the current terminfo. */ public static function getTerminfo($term = null): string { $paths = []; if (isset($_SERVER['TERMINFO'])) { $paths[] = $_SERVER['TERMINFO']; } if (isset($_SERVER['HOME'])) { $paths[] = $_SERVER['HOME'].\DIRECTORY_SEPARATOR.'.terminfo'; } if (isset($_SERVER['TERMINFO_DIRS'])) { foreach (\explode(':', $_SERVER['TERMINFO_DIRS']) as $path) { $paths[] = $path; } } $paths[] = '/usr/share/terminfo'; $paths[] = '/usr/share/lib/terminfo'; $paths[] = '/lib/terminfo'; $paths[] = '/usr/lib/terminfo'; $paths[] = '/usr/local/share/terminfo'; $paths[] = '/usr/local/share/lib/terminfo'; $paths[] = '/usr/local/lib/terminfo'; $paths[] = '/usr/local/ncurses/lib/terminfo'; $paths[] = 'hoa://Library/Terminfo'; $term = $term ?: static::getTerm(); $fileHexa = \dechex(\ord($term[0])).\DIRECTORY_SEPARATOR.$term; $fileAlpha = $term[0].\DIRECTORY_SEPARATOR.$term; $pathname = null; foreach ($paths as $path) { if (\file_exists($_ = $path.\DIRECTORY_SEPARATOR.$fileHexa) || \file_exists($_ = $path.\DIRECTORY_SEPARATOR.$fileAlpha)) { $pathname = $_; break; } } if (null === $pathname && 'xterm' !== $term) { return static::getTerminfo('xterm'); } return $pathname ?? ''; } /** * Check whether all required terminfo capabilities are defined. */ public static function isSupported(): bool { if (static::getTerminfo() === '') { return false; } $requiredVars = [ 'clear_screen', 'clr_bol', 'clr_eol', 'clr_eos', 'initialize_color', 'parm_down_cursor', 'parm_index', 'parm_left_cursor', 'parm_right_cursor', 'parm_rindex', 'parm_up_cursor', 'user6', 'user7', ]; $tput = new self(); foreach ($requiredVars as $var) { if ($tput->get($var) === null) { return false; } } return true; } }