write() public static method

输出内容
public static write ( string $text, mixed $pipe = STDOUT )
$text string
$pipe mixed
Beispiel #1
0
 /**
  * 提问并获取用户输入
  *
  * @param string $question 问题
  * @param bool $isHidden 是否要隐藏输入
  * @param string $default 默认答案
  * @param bool $displayDefault 是否显示默认答案
  *
  * @return string
  */
 public function ask($question, $isHidden = false, $default = '', $displayDefault = true)
 {
     if ($displayDefault && !empty($default)) {
         $defaultText = $default;
         if (strlen($defaultText) > 30) {
             $defaultText = substr($default, 0, 30) . '...';
         }
         $question .= " [{$defaultText}]";
     }
     Output::write("{$question} ");
     return $isHidden ? $this->askHidden() : trim(fgets(STDIN)) ?: $default;
 }
Beispiel #2
0
 /**
  * 进入+ x
  *
  * @param int $value
  *
  * @return $this
  */
 public function increment($value = 1)
 {
     $this->percent += $value;
     $percentage = (double) ($this->percent / 100);
     $progress = floor($percentage * 50);
     $output = "\r[" . str_repeat('>', $progress);
     if ($progress < 50) {
         $output .= ">" . str_repeat(' ', 50 - $progress);
     } else {
         $output .= '>';
     }
     $output .= sprintf('] %s%% ', round($percentage * 100, 0));
     $speed = (time() - $this->startTime) / $this->percent;
     $remaining = number_format(round($speed * (100 - $this->percent), 2), 2);
     $percentage == 100 || ($output .= " {$remaining} seconds remaining");
     Output::write($output);
     return $this;
 }
Beispiel #3
0
 /**
  * 格式化输出
  *
  * @param string $text 要输出的内容
  * @param array $option 格式化选项 @see Format
  *
  * @return $this
  */
 public function write($text, $option = [])
 {
     Output::write($this->format($text, $option));
     return $this;
 }