Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3295394
PhutilConsoleSyntaxHighlighter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
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.
*/
final
class
PhutilConsoleSyntaxHighlighter
extends
Phobject
{
private
$config
=
array
(
)
;
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
)
)
{
$lines
[
$key
]
=
hsprintf
(
'%s<span class="gp">%s</span>%s'
,
$matches
[
1
]
,
$matches
[
2
]
,
(
!
empty
(
$matches
[
3
]
)
?
hsprintf
(
'<span class="k">%s</span>'
,
$matches
[
3
]
)
:
''
)
)
;
$in_command
=
(
idx
(
$matches
,
3
)
==
'\\'
)
;
}
else
{
$lines
[
$key
]
=
hsprintf
(
'<span class="go">%s</span>'
,
$line
)
;
}
}
$lines
=
phutil_implode_html
(
"\n"
,
$lines
)
;
return
new
ImmediateFuture
(
$lines
)
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Mar 27, 01:59 (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1197018
Default Alt Text
PhutilConsoleSyntaxHighlighter.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment