Source of file Virtual.php
Size: 3,867 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Console/Adapter/Virtual.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Console\Adapter; use Zend\Console\Charset; /** * Virtual buffer adapter */ class Virtual extends AbstractAdapter { /** * Whether or not mbstring is enabled * * @var null|bool */ protected static $hasMBString; /** * Results of mode system command * * @var mixed */ protected $modeResult; /** * Determine and return current console width. * * @return int */ public function getWidth() { static $width; if ($width > 0) { return $width; } // Try to read console size from "mode" command if ($this->modeResult === null) { $this->runProbeCommand(); } if (preg_match('/Columns\:\s+(\d+)/', $this->modeResult, $matches)) { $width = $matches[1]; } else { $width = parent::getWidth(); } return $width; } /** * Determine and return current console height. * * @return false|int */ public function getHeight() { static $height; if ($height > 0) { return $height; } // Try to read console size from "mode" command if ($this->modeResult === null) { $this->runProbeCommand(); } if (preg_match('/Rows\:\s+(\d+)/', $this->modeResult, $matches)) { $height = $matches[1]; } else { $height = parent::getHeight(); } return $height; } /** * Run and store the results of mode command * * @return void */ protected function runProbeCommand() { exec('mode', $output, $return); if ($return || !count($output)) { $this->modeResult = ''; } else { $this->modeResult = trim(implode('', $output)); } } /** * Check if console is UTF-8 compatible * * @return bool */ public function isUtf8() { // Try to read code page info from "mode" command if ($this->modeResult === null) { $this->runProbeCommand(); } if (preg_match('/Code page\:\s+(\d+)/', $this->modeResult, $matches)) { return (int) $matches[1] == 65001; } return false; } /** * Return current console window title. * * @return string */ public function getTitle() { // Try to use powershell to retrieve console window title exec('powershell -command "write $Host.UI.RawUI.WindowTitle"', $output, $result); if ($result || !$output) { return ''; } return trim($output, "\r\n"); } /** * Set Console charset to use. * * @param Charset\CharsetInterface $charset */ public function setCharset(Charset\CharsetInterface $charset) { $this->charset = $charset; } /** * Get charset currently in use by this adapter. * * @return Charset\CharsetInterface $charset */ public function getCharset() { if ($this->charset === null) { $this->charset = $this->getDefaultCharset(); } return $this->charset; } /** * @return Charset\AsciiExtended */ public function getDefaultCharset() { return new Charset\AsciiExtended; } /** * Switch to UTF mode * * @return void */ protected function switchToUtf8() { shell_exec('mode con cp select=65001'); } } |