9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/bdrem.htm
17 * Render events on the terminal as ASCII table
21 * @author Christian Weiske <cweiske@cweiske.de>
22 * @copyright 2014 Christian Weiske
23 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
24 * @version Release: @package_version@
25 * @link http://cweiske.de/bdrem.htm
27 class Renderer_Console extends Renderer
33 protected $httpContentType = 'text/plain; charset=utf-8';
36 * Use ANSI color codes for output coloring
43 * @var \Console_Color2
48 * Render events as console table
50 * @param array $arEvents Array of events to render
52 * @return string ASCII table
54 public function render($arEvents)
58 $this->cc = new \Console_Color2();
61 $tbl = new \Console_Table(
62 CONSOLE_TABLE_ALIGN_LEFT,
63 array('intersection' => '', 'horizontal' => '-', 'vertical' => ''),
66 $tbl->setAlign(0, CONSOLE_TABLE_ALIGN_RIGHT);
67 $tbl->setAlign(1, CONSOLE_TABLE_ALIGN_RIGHT);
71 array('Days', 'Age', 'Name', 'Event', 'Date', 'Day'),
75 $tbl->setBorderVisibility(
85 foreach ($arEvents as $event) {
87 if ($event->days == 0) {
95 wordwrap($event->title, 30, "\n", true),
96 wordwrap($event->type, 20, "\n", true),
97 $this->getLocalDate($event->date),
98 strftime('%a', strtotime($event->localDate))
104 return $tbl->getTable();
108 * Wrap each string in an array in an ANSI color code
110 * @param array $data Array of strings
111 * @param string $colorCode ANSI color code or name
113 * @return array Wrapped data
115 protected function ansiWrap($data, $colorCode = null)
117 if (!$this->ansi || $colorCode === null) {
121 foreach ($data as $k => &$value) {
122 $value = $this->cc->convert(
123 $colorCode . $value . '%n'
130 * Load configuration values into the class
134 protected function loadConfig()
136 if (isset($this->config->ansi)) {
137 $this->ansi = $this->config->ansi;