public function __construct($terminal, $title, $data, Borderset $borderset) { parent::__construct($terminal, $borderset); $this->selectedKey = null; $this->title = $title; $this->data = $data; }
public function __construct($terminal, $title, $data, $headers, Borderset $borderset) { parent::__construct($terminal, $borderset); $this->title = $title; $this->data = $data; $this->headers = $headers; $this->index = 0; $templates = []; foreach ($headers as $key => $header) { $this->rowLengths[$key] = max(strlen($header), call_user_func_array('max', array_map(function ($row) use($key) { return strlen($row[$key]); }, $data))); $templates[] = "%-" . $this->rowLengths[$key] . "s"; } $this->rowTemplate = " " . implode(" │ ", $templates) . " "; }
public function show() { parent::show(); $option = 0; $this->drawButtons($option); $this->terminal->readInput(function ($char, $isControl) use(&$option) { if ($char == '[C') { $option = min($option + 1, count($this->options) - 1); $this->drawButtons($option); } else { if ($char == '[D') { $option = max(0, $option - 1); $this->drawButtons($option); } else { if ($char == "\n") { return true; } } } }); $this->terminal->resetFormatting(); return $this->options[$option][0]; }