Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92590395
PhutilConsoleSyntaxHighlighter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Nov 21, 18:48
Size
1 KB
Mime Type
text/x-php
Expires
Sat, Nov 23, 18:48 (2 d)
Engine
blob
Format
Raw Data
Handle
22465613
Attached To
rPHU libphutil
PhutilConsoleSyntaxHighlighter.php
View Options
<?php
/**
* Simple syntax highlighter for console output. We just try to highlight the
* commands so it's easier to follow transcripts.
*
* @group markup
*/
final
class
PhutilConsoleSyntaxHighlighter
{
private
$config
=
array
();
private
$replaceClass
;
public
function
setConfig
(
$key
,
$value
)
{
$this
->
config
[
$key
]
=
$value
;
return
$this
;
}
public
function
getHighlightFuture
(
$source
)
{
$in_command
=
false
;
$lines
=
explode
(
"
\n
"
,
$source
);
foreach
(
$lines
as
$key
=>
$line
)
{
$matches
=
null
;
// Parse commands like this:
//
// some/path/ $ ./bin/example # Do things
//
// ...into path, command, and comment components.
$pattern
=
'@'
.
(
$in_command
?
'()(.*?)'
:
'^(
\S
+[
\\\\
/] )?([$] .*?)'
).
'(#.*|
\\\\
)?$@'
;
if
(
preg_match
(
$pattern
,
$line
,
$matches
))
{
$line
=
''
;
if
(
$matches
[
1
])
{
$line
.=
phutil_escape_html
(
$matches
[
1
]);
}
$line
.=
'<span class="gp">'
.
phutil_escape_html
(
$matches
[
2
]).
'</span>'
;
if
(!
empty
(
$matches
[
3
]))
{
$line
.=
'<span class="k">'
.
phutil_escape_html
(
$matches
[
3
]).
'</span>'
;
}
$lines
[
$key
]
=
$line
;
$in_command
=
(
$matches
[
3
]
==
'
\\
'
);
}
else
{
$lines
[
$key
]
=
'<span class="go">'
.
phutil_escape_html
(
$line
).
'</span>'
;
}
}
$lines
=
implode
(
"
\n
"
,
$lines
);
return
new
ImmediateFuture
(
$lines
);
}
}
Event Timeline
Log In to Comment