1<?php 2 3final class PhutilConsoleList extends PhutilConsoleView { 4 5 private $items = array(); 6 private $wrap = true; 7 private $bullet = '-'; 8 9 public function addItem($item) { 10 $this->items[] = $item; 11 return $this; 12 } 13 14 public function addItems(array $items) { 15 foreach ($items as $item) { 16 $this->addItem($item); 17 } 18 return $this; 19 } 20 21 public function getItems() { 22 return $this->items; 23 } 24 25 public function setBullet($bullet) { 26 $this->bullet = $bullet; 27 return $this; 28 } 29 30 public function getBullet() { 31 return $this->bullet; 32 } 33 34 public function setWrap($wrap) { 35 $this->wrap = $wrap; 36 return $this; 37 } 38 39 protected function drawView() { 40 $indent_depth = 6; 41 $indent_string = str_repeat(' ', $indent_depth); 42 43 if ($this->bullet !== null) { 44 $bullet = $this->bullet.' '; 45 $indent_depth = $indent_depth + phutil_utf8_console_strlen($bullet); 46 } else { 47 $bullet = ''; 48 } 49 50 $output = array(); 51 foreach ($this->getItems() as $item) { 52 if ($this->wrap) { 53 $item = tsprintf('%s', $item) 54 ->applyIndent($indent_depth, false); 55 } 56 57 $output[] = $indent_string.$bullet.$item; 58 } 59 60 return $this->drawLines($output); 61 } 62 63} 64