Exemple #1
0
 /**
  * Same as \cli\prompt except that it allows empty input
  * @param string $question
  * @param bool $default
  * @param string $marker
  * @return string
  */
 public static function promptAllowingEmpty($question, $default = false, $marker = ': ')
 {
     if ($default && strpos($question, '[') === false) {
         $question .= ' [' . $default . ']';
     }
     while (true) {
         \cli\Streams::out($question . $marker);
         $line = \cli\Streams::input();
         return $line;
     }
 }
 /**
  * Prints the progress bar to the screen with percent complete, elapsed time
  * and estimated total time.
  *
  * @param boolean  $finish  `true` if this was called from
  *                          `cli\Notify::finish()`, `false` otherwise.
  * @see cli\out()
  * @see cli\Notify::formatTime()
  * @see cli\Notify::elapsed()
  * @see cli\Progress::estimated();
  * @see cli\Progress::percent()
  * @see cli\Shell::columns()
  */
 public function display($finish = false)
 {
     $_percent = $this->percent();
     $percent = str_pad(floor($_percent * 100), 3);
     $msg = $this->_message;
     $msg = Streams::render($this->_formatMessage, compact('msg', 'percent'));
     $estimated = $this->formatTime($this->estimated());
     $elapsed = str_pad($this->formatTime($this->elapsed()), strlen($estimated));
     $timing = Streams::render($this->_formatTiming, compact('elapsed', 'estimated'));
     $size = Shell::columns();
     $size -= strlen($msg . $timing);
     if ($size < 0) {
         $size = 0;
     }
     $bar = str_repeat($this->_bars[0], floor($_percent * $size)) . $this->_bars[1];
     // substr is needed to trim off the bar cap at 100%
     $bar = substr(str_pad($bar, $size, ' '), 0, $size);
     Streams::out($this->_format, compact('msg', 'bar', 'timing'));
 }
Exemple #3
0
 /**
  * This method is the meat of all Notifiers. First we increment the ticker
  * and then update the display if enough time has passed since our last tick.
  *
  * @param int  $increment  The amount to increment by.
  * @see cli\Notify::increment()
  * @see cli\Notify::shouldUpdate()
  * @see cli\Notify::display()
  */
 public function tick($increment = 1)
 {
     $this->increment($increment);
     if ($this->shouldUpdate()) {
         Streams::out("\r");
         $this->display();
     }
 }