예제 #1
0
파일: Window.php 프로젝트: alexpw/Console
 /**
  * Get current size (x and y) of the window.
  *
  * @access  public
  * @return  array
  */
 public static function getSize()
 {
     if (OS_WIN) {
         $modecon = explode("\n", ltrim(Processus::execute('mode con')));
         $_y = trim($modecon[2]);
         preg_match('#[^:]+:\\s*([0-9]+)#', $_y, $matches);
         $y = (int) $matches[1];
         $_x = trim($modecon[3]);
         preg_match('#[^:]+:\\s*([0-9]+)#', $_x, $matches);
         $x = (int) $matches[1];
         return array('x' => $x, 'y' => $y);
     }
     // Fix "tput: No value for $TERM and no -T specified"
     if (isset($_SERVER['TERM'])) {
         $prefix = "TERM={$_SERVER['TERM']}";
     } else {
         $prefix = '';
     }
     $cmd = "{$prefix} tput cols && {$prefix} tput lines";
     $tput = Processus::execute($cmd, false);
     if (!empty($tput)) {
         list($x, $y) = explode("\n", $tput);
         return array('x' => intval($x), 'y' => intval($y));
     }
     // DECSLPP.
     echo "";
     // Read \033[8;y;xt.
     fread(STDIN, 4);
     // skip \033, [, 8 and ;.
     $x = null;
     $y = null;
     $handle =& $y;
     do {
         $char = fread(STDIN, 1);
         switch ($char) {
             case ';':
                 $handle =& $x;
                 break;
             case 't':
                 break 2;
             default:
                 if (false === ctype_digit($char)) {
                     break 2;
                 }
                 $handle .= $char;
         }
     } while (true);
     if (null === $x || null === $y) {
         return array('x' => 0, 'y' => 0);
     }
     return array('x' => (int) $x, 'y' => (int) $y);
 }
예제 #2
0
파일: Console.php 프로젝트: alexpw/Console
 /**
  * Restore previous interaction options.
  *
  * @access  public
  * @return  void
  */
 public static function restoreInteraction()
 {
     if (null === self::$_old) {
         return;
     }
     Processus::execute('stty ' . self::$_old);
     return;
 }