/**
  * Determines and set the size of the frame, if the attributes were not set
  * before.
  *
  * TODO: Create dummy parent frame with size of console and fire the resize
  * event.
  */
 protected function determineOwnSize()
 {
     // True for the outermost frame only
     if ($this->width == null || $this->height === null) {
         // TODO: allow to define fixed size in which the frame is beeing rendered within.
         $screenSize = Console::getScreenSize();
         if ($screenSize === false) {
             throw new UserException('Couldnt determine console window size!');
         }
         list($screenWidth, $screenHeight) = $screenSize;
         if ($this->width === null && $this->layout === self::LAYOUT_HORIZONTAL) {
             if (is_float($this->size)) {
                 $this->width = intval(round($screenWidth * $this->size));
             } elseif (is_integer($this->size)) {
                 $this->width = $this->size;
             } else {
                 $this->width = $screenWidth;
             }
         }
         if ($this->height === null && $this->layout === self::LAYOUT_VERTICAL) {
             if (is_float($this->size)) {
                 $this->height = intval(round($screenHeight * $this->size));
             } elseif (is_integer($this->size)) {
                 $this->height = $this->size;
             } else {
                 $this->height = $screenHeight;
             }
         }
         if ($this->width === null) {
             $this->width = $screenWidth;
         }
         if ($this->height === null) {
             $this->height = $screenHeight;
         }
         if ($this->width > $screenWidth || $this->height > $screenHeight) {
             throw new UserException('GUI dimensions are too large!');
         }
         $this->trigger(self::EVENT_FRAME_RESIZE, $this->createResizeEvent());
     }
 }
示例#2
0
文件: Yiiic.php 项目: ltd-beget/yiiic
 protected function getScreenWidth() : int
 {
     return Console::getScreenSize(true)[0];
 }
示例#3
0
 public static function clearScreen()
 {
     $size = \yii\helpers\Console::getScreenSize();
     echo str_repeat("\n", $size[0]);
 }