Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/view/ShellLogView.php
12256 views
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
),
69
$content_number);
70
71
$td = phutil_tag(
72
'td',
73
array('class' => 'phabricator-source-code'),
74
$content_line);
75
76
$rows[] = phutil_tag(
77
'tr',
78
$row_attributes,
79
array($th, $td));
80
81
if ($hit_limit) {
82
break;
83
}
84
85
$line_number++;
86
}
87
88
$classes = array();
89
$classes[] = 'phabricator-source-code-view';
90
$classes[] = 'remarkup-code';
91
$classes[] = 'PhabricatorMonospaced';
92
93
return phutil_tag(
94
'div',
95
array(
96
'class' => 'phabricator-source-code-container',
97
),
98
phutil_tag(
99
'table',
100
array(
101
'class' => implode(' ', $classes),
102
),
103
phutil_implode_html('', $rows)));
104
}
105
106
}
107
108