1<?php
2/**
3 * Copyright 2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (LGPL). If you did
6 * not receive this file, see http://www.horde.org/licenses/lgpl21.
7 *
8 * @author   Jan Schneider <jan@horde.org>
9 * @category Horde
10 * @license  http://www.horde.org/licenses/lgpl21 LGPL
11 * @package  Text_Diff
12 */
13
14/**
15 * "Unified" diff renderer with output coloring.
16 *
17 * @author    Jan Schneider <jan@horde.org>
18 * @category  Horde
19 * @copyright 2017 Horde LLC
20 * @license   http://www.horde.org/licenses/lgpl21 LGPL
21 * @package   Text_Diff
22 */
23class Horde_Text_Diff_Renderer_Unified_Colored
24extends Horde_Text_Diff_Renderer_Unified
25{
26    /**
27     * CLI handler.
28     *
29     * Contrary to the name, it supports color highlighting for HTML too.
30     *
31     * @var Horde_Cli
32     */
33    protected $_cli;
34
35    /**
36     * Constructor.
37     */
38    public function __construct($params = array())
39    {
40        if (!isset($params['cli'])) {
41            throw new BadMethodCallException('CLI handler is missing');
42        }
43        parent::__construct($params);
44        $this->_cli = $params['cli'];
45    }
46
47    protected function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
48    {
49        return $this->_cli->color(
50            'lightmagenta', parent::_blockHeader($xbeg, $xlen, $ybeg, $ylen)
51        );
52    }
53
54    protected function _added($lines)
55    {
56        return $this->_cli->color(
57            'lightgreen', parent::_added($lines)
58        );
59    }
60
61    protected function _deleted($lines)
62    {
63        return $this->_cli->color(
64            'lightred', parent::_deleted($lines)
65        );
66    }
67}
68