/** * @param $string * @param bool $default * * @return bool */ public function ask($string, $default = null) { if ($default === true) { $suffix = 'Y/n'; } else { if ($default === false) { $suffix = 'y/N'; } else { $suffix = 'y/n'; } } $this->output->write("<question>{$string}</question> [<yellow>{$suffix}</yellow>]: "); $input = $this->input->readLine(); if (array_contains(['yes', 'y'], $input)) { return true; } if (array_contains(['no', 'n'], $input)) { return false; } if (empty($input)) { if ($default === true) { return true; } if ($default === false) { return false; } } return $this->ask($string, $default); }
/** * Render table. */ public function render() { if ($this->title) { $this->output->writeLine($this->title); } $rows = $this->formatRows($this->rows); $widths = $this->calculateColumnWidths($rows); foreach ($rows as $row) { $type = $row['type']; foreach ($row['cols'] as $colIndex => $col) { if ($type === '@row') { $width = array_get($widths, $colIndex); $colWidth = strlen($this->output->format($col, OutputFormat::PLAIN)); // if not last row if (array_has($row['cols'], $colIndex + 1)) { $col .= str_repeat(' ', $width - $colWidth); } } $this->output->write($col); } $this->output->writeLine(); } }