[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/harbormaster/view/ -> ShellLogView.php (source)

   1  <?php
   2  
   3  final class ShellLogView extends AphrontView {
   4  
   5    private $start = 1;
   6    private $lines;
   7    private $limit;
   8    private $highlights = array();
   9  
  10    public function setStart($start) {
  11      $this->start = $start;
  12      return $this;
  13    }
  14  
  15    public function setLimit($limit) {
  16      $this->limit = $limit;
  17      return $this;
  18    }
  19  
  20    public function setLines(array $lines) {
  21      $this->lines = $lines;
  22      return $this;
  23    }
  24  
  25    public function setHighlights(array $highlights) {
  26      $this->highlights = array_fuse($highlights);
  27      return $this;
  28    }
  29  
  30    public function render() {
  31      require_celerity_resource('phabricator-source-code-view-css');
  32      require_celerity_resource('syntax-highlighting-css');
  33  
  34      Javelin::initBehavior('phabricator-oncopy', array());
  35  
  36      $line_number = $this->start;
  37  
  38      $rows = array();
  39      foreach ($this->lines as $line) {
  40        $hit_limit = $this->limit &&
  41                     ($line_number == $this->limit) &&
  42                     (count($this->lines) != $this->limit);
  43  
  44        if ($hit_limit) {
  45          $content_number = '';
  46          $content_line = phutil_tag(
  47            'span',
  48            array(
  49              'class' => 'c',
  50            ),
  51            pht('...'));
  52        } else {
  53          $content_number = $line_number;
  54          $content_line = $line;
  55        }
  56  
  57        $row_attributes = array();
  58        if (isset($this->highlights[$line_number])) {
  59          $row_attributes['class'] = 'phabricator-source-highlight';
  60        }
  61  
  62        // TODO: Provide nice links.
  63  
  64        $th = phutil_tag(
  65          'th',
  66          array(
  67            'class' => 'phabricator-source-line',
  68            'style' => 'background-color: #fff;',
  69          ),
  70          $content_number);
  71  
  72        $td = phutil_tag(
  73          'td',
  74          array('class' => 'phabricator-source-code'),
  75          $content_line);
  76  
  77        $rows[] = phutil_tag(
  78          'tr',
  79          $row_attributes,
  80          array($th, $td));
  81  
  82        if ($hit_limit) {
  83          break;
  84        }
  85  
  86        $line_number++;
  87      }
  88  
  89      $classes = array();
  90      $classes[] = 'phabricator-source-code-view';
  91      $classes[] = 'remarkup-code';
  92      $classes[] = 'PhabricatorMonospaced';
  93  
  94      return phutil_tag(
  95        'div',
  96        array(
  97          'class' => 'phabricator-source-code-container',
  98          'style' => 'background-color: black; color: white;',
  99        ),
 100        phutil_tag(
 101          'table',
 102          array(
 103            'class' => implode(' ', $classes),
 104            'style' => 'background-color: black',
 105          ),
 106          phutil_implode_html('', $rows)));
 107    }
 108  
 109  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1